[IMP] pre-commit: first run on whole repo
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models
|
||||
from odoo.addons.base.models.ir_mail_server import extract_rfc2822_addresses
|
||||
import logging
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
from odoo.addons.base.models.ir_mail_server import extract_rfc2822_addresses
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -14,23 +16,42 @@ class IrMailServer(models.Model):
|
||||
|
||||
@api.model
|
||||
def send_email(
|
||||
self, message, mail_server_id=None, smtp_server=None,
|
||||
smtp_port=None, smtp_user=None, smtp_password=None,
|
||||
smtp_encryption=None, smtp_debug=False, smtp_session=None):
|
||||
self,
|
||||
message,
|
||||
mail_server_id=None,
|
||||
smtp_server=None,
|
||||
smtp_port=None,
|
||||
smtp_user=None,
|
||||
smtp_password=None,
|
||||
smtp_encryption=None,
|
||||
smtp_debug=False,
|
||||
smtp_session=None,
|
||||
):
|
||||
# Start copy from native method
|
||||
smtp_from = message['Return-Path'] or\
|
||||
self._get_default_bounce_address() or message['From']
|
||||
smtp_from = (
|
||||
message["Return-Path"]
|
||||
or self._get_default_bounce_address()
|
||||
or message["From"]
|
||||
)
|
||||
from_rfc2822 = extract_rfc2822_addresses(smtp_from)
|
||||
smtp_from = from_rfc2822[-1]
|
||||
# End copy from native method
|
||||
logger.info(
|
||||
"Sending email from '%s' to '%s' Cc '%s' Bcc '%s' "
|
||||
"with subject '%s'",
|
||||
smtp_from, message.get('To'), message.get('Cc'),
|
||||
message.get('Bcc'), message.get('Subject'))
|
||||
"Sending email from '%s' to '%s' Cc '%s' Bcc '%s' " "with subject '%s'",
|
||||
smtp_from,
|
||||
message.get("To"),
|
||||
message.get("Cc"),
|
||||
message.get("Bcc"),
|
||||
message.get("Subject"),
|
||||
)
|
||||
return super().send_email(
|
||||
message, mail_server_id=mail_server_id,
|
||||
smtp_server=smtp_server, smtp_port=smtp_port,
|
||||
smtp_user=smtp_user, smtp_password=smtp_password,
|
||||
smtp_encryption=smtp_encryption, smtp_debug=smtp_debug,
|
||||
smtp_session=smtp_session)
|
||||
message,
|
||||
mail_server_id=mail_server_id,
|
||||
smtp_server=smtp_server,
|
||||
smtp_port=smtp_port,
|
||||
smtp_user=smtp_user,
|
||||
smtp_password=smtp_password,
|
||||
smtp_encryption=smtp_encryption,
|
||||
smtp_debug=smtp_debug,
|
||||
smtp_session=smtp_session,
|
||||
)
|
||||
|
||||
@@ -6,11 +6,11 @@ from odoo import api, models
|
||||
|
||||
|
||||
class IrModel(models.Model):
|
||||
_inherit = 'ir.model'
|
||||
_inherit = "ir.model"
|
||||
|
||||
@api.depends('name', 'model')
|
||||
@api.depends("name", "model")
|
||||
def name_get(self):
|
||||
res = []
|
||||
for rec in self:
|
||||
res.append((rec.id, '%s (%s)' % (rec.name, rec.model)))
|
||||
res.append((rec.id, "%s (%s)" % (rec.name, rec.model)))
|
||||
return res
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models, _
|
||||
from odoo import _, api, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = 'res.company'
|
||||
_inherit = "res.company"
|
||||
|
||||
@api.model
|
||||
def generate_line(self, fields, options, icon=True, separator=' - '):
|
||||
def generate_line(self, fields, options, icon=True, separator=" - "):
|
||||
assert fields
|
||||
assert options
|
||||
content = []
|
||||
@@ -20,13 +20,13 @@ class ResCompany(models.Model):
|
||||
label = field[1]
|
||||
uicon = False
|
||||
elif isinstance(field, str) and field in options:
|
||||
value = options[field]['value']
|
||||
label = options[field].get('label')
|
||||
uicon = options[field].get('icon')
|
||||
value = options[field]["value"]
|
||||
label = options[field].get("label")
|
||||
uicon = options[field].get("icon")
|
||||
if value:
|
||||
prefix = icon and uicon or label
|
||||
if prefix:
|
||||
content.append('%s %s' % (prefix, value))
|
||||
content.append("%s %s" % (prefix, value))
|
||||
else:
|
||||
content.append(value)
|
||||
line = separator.join(content)
|
||||
@@ -35,46 +35,51 @@ class ResCompany(models.Model):
|
||||
def _prepare_header_options(self):
|
||||
self.ensure_one()
|
||||
options = {
|
||||
'phone': {
|
||||
'value': self.phone,
|
||||
"phone": {
|
||||
"value": self.phone,
|
||||
# http://www.fileformat.info/info/unicode/char/1f4de/index.htm
|
||||
'icon': '\U0001F4DE',
|
||||
'label': _('Tel:')},
|
||||
'email': {
|
||||
'value': self.email,
|
||||
"icon": "\U0001F4DE",
|
||||
"label": _("Tel:"),
|
||||
},
|
||||
"email": {
|
||||
"value": self.email,
|
||||
# http://www.fileformat.info/info/unicode/char/2709/index.htm
|
||||
'icon': '\u2709',
|
||||
'label': _('E-mail:')},
|
||||
'website': {
|
||||
'value': self.website,
|
||||
'icon': '\U0001f310',
|
||||
'label': _('Website:')},
|
||||
'vat': {
|
||||
'value': self.vat,
|
||||
'label': _('VAT:')},
|
||||
}
|
||||
"icon": "\u2709",
|
||||
"label": _("E-mail:"),
|
||||
},
|
||||
"website": {
|
||||
"value": self.website,
|
||||
"icon": "\U0001f310",
|
||||
"label": _("Website:"),
|
||||
},
|
||||
"vat": {"value": self.vat, "label": _("VAT:")},
|
||||
}
|
||||
return options
|
||||
|
||||
def _report_company_legal_name(self):
|
||||
'''Method inherited in the module base_company_extension'''
|
||||
"""Method inherited in the module base_company_extension"""
|
||||
self.ensure_one()
|
||||
return self.name
|
||||
|
||||
# for reports
|
||||
def _display_report_header(
|
||||
self, line_details=[['phone', 'website'], ['vat']],
|
||||
icon=True, line_separator=' - '):
|
||||
self,
|
||||
line_details=[["phone", "website"], ["vat"]],
|
||||
icon=True,
|
||||
line_separator=" - ",
|
||||
):
|
||||
self.ensure_one()
|
||||
res = ''
|
||||
res = ""
|
||||
address = self.partner_id._display_address(without_company=True)
|
||||
address = address.replace('\n', ' - ')
|
||||
address = address.replace("\n", " - ")
|
||||
|
||||
line1 = '%s - %s' % (self._report_company_legal_name(), address)
|
||||
line1 = "%s - %s" % (self._report_company_legal_name(), address)
|
||||
lines = [line1]
|
||||
options = self._prepare_header_options()
|
||||
for details in line_details:
|
||||
line = self.generate_line(
|
||||
details, options, icon=icon, separator=line_separator)
|
||||
details, options, icon=icon, separator=line_separator
|
||||
)
|
||||
lines.append(line)
|
||||
res = '\n'.join(lines)
|
||||
res = "\n".join(lines)
|
||||
return res
|
||||
|
||||
@@ -2,21 +2,20 @@
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
_inherit = "res.partner"
|
||||
|
||||
# tracking=True is handled in the 'mail' module, and base_usability
|
||||
# doesn't depend on 'mail', so adding tracking on res.partner fields
|
||||
# has been moved to mail_usability
|
||||
ref = fields.Char(copy=False)
|
||||
# For reports
|
||||
name_title = fields.Char(
|
||||
compute='_compute_name_title', string='Name with Title')
|
||||
name_title = fields.Char(compute="_compute_name_title", string="Name with Title")
|
||||
|
||||
@api.depends('name', 'title')
|
||||
@api.depends("name", "title")
|
||||
def _compute_name_title(self):
|
||||
for partner in self:
|
||||
name_title = partner.name
|
||||
@@ -28,21 +27,22 @@ class ResPartner(models.Model):
|
||||
if partner.lang:
|
||||
partner_lg = partner.with_context(lang=partner.lang)
|
||||
title = partner_lg.title.shortcut or partner_lg.title.name
|
||||
name_title = ' '.join([title, name_title])
|
||||
name_title = " ".join([title, name_title])
|
||||
partner.name_title = name_title
|
||||
|
||||
def _display_address(self, without_company=False):
|
||||
'''Remove empty lines'''
|
||||
"""Remove empty lines"""
|
||||
res = super()._display_address(without_company=without_company)
|
||||
while "\n\n" in res:
|
||||
res = res.replace('\n\n', '\n')
|
||||
res = res.replace("\n\n", "\n")
|
||||
return res
|
||||
|
||||
# for reports
|
||||
def _display_full_address(
|
||||
self,
|
||||
details=['company', 'name', 'address', 'phone', 'mobile', 'email'],
|
||||
icon=True):
|
||||
self,
|
||||
details=["company", "name", "address", "phone", "mobile", "email"],
|
||||
icon=True,
|
||||
):
|
||||
self.ensure_one()
|
||||
# To make the icons work with py3o with PDF export, on the py3o server:
|
||||
# 1) sudo apt-get install fonts-symbola
|
||||
@@ -54,85 +54,89 @@ class ResPartner(models.Model):
|
||||
title = False
|
||||
title_short = False
|
||||
else:
|
||||
company = self.parent_id and self.parent_id.is_company and\
|
||||
self.parent_id.name or False
|
||||
company = (
|
||||
self.parent_id
|
||||
and self.parent_id.is_company
|
||||
and self.parent_id.name
|
||||
or False
|
||||
)
|
||||
name = self.name_title
|
||||
name_no_title = self.name
|
||||
title = self.title.name
|
||||
title_short = self.title.shortcut
|
||||
options = {
|
||||
'name': {
|
||||
'value': name,
|
||||
},
|
||||
'company': {
|
||||
'value': company,
|
||||
},
|
||||
'title': {
|
||||
'value': title,
|
||||
},
|
||||
'title_short': {
|
||||
'value': title_short,
|
||||
},
|
||||
'name_no_title': {
|
||||
'value': name_no_title,
|
||||
},
|
||||
'phone': {
|
||||
'value': self.phone,
|
||||
"name": {
|
||||
"value": name,
|
||||
},
|
||||
"company": {
|
||||
"value": company,
|
||||
},
|
||||
"title": {
|
||||
"value": title,
|
||||
},
|
||||
"title_short": {
|
||||
"value": title_short,
|
||||
},
|
||||
"name_no_title": {
|
||||
"value": name_no_title,
|
||||
},
|
||||
"phone": {
|
||||
"value": self.phone,
|
||||
# http://www.fileformat.info/info/unicode/char/1f4de/index.htm
|
||||
'icon': '\U0001F4DE',
|
||||
'label': _('Tel:'),
|
||||
},
|
||||
'mobile': {
|
||||
'value': self.mobile,
|
||||
"icon": "\U0001F4DE",
|
||||
"label": _("Tel:"),
|
||||
},
|
||||
"mobile": {
|
||||
"value": self.mobile,
|
||||
# http://www.fileformat.info/info/unicode/char/1f4f1/index.htm
|
||||
'icon': '\U0001F4F1',
|
||||
'label': _('Mobile:'),
|
||||
},
|
||||
'email': {
|
||||
'value': self.email,
|
||||
"icon": "\U0001F4F1",
|
||||
"label": _("Mobile:"),
|
||||
},
|
||||
"email": {
|
||||
"value": self.email,
|
||||
# http://www.fileformat.info/info/unicode/char/2709/index.htm
|
||||
'icon': '\u2709',
|
||||
'label': _('E-mail:'),
|
||||
},
|
||||
'website': {
|
||||
'value': self.website,
|
||||
"icon": "\u2709",
|
||||
"label": _("E-mail:"),
|
||||
},
|
||||
"website": {
|
||||
"value": self.website,
|
||||
# http://www.fileformat.info/info/unicode/char/1f310/index.htm
|
||||
'icon': '\U0001f310',
|
||||
'label': _('Website:'),
|
||||
},
|
||||
'address': {
|
||||
'value': self._display_address(without_company=True),
|
||||
},
|
||||
'vat': {
|
||||
'value': self.commercial_partner_id.vat,
|
||||
'label': _('VAT Number:'),
|
||||
},
|
||||
'commercial_ref': {
|
||||
'value': self.commercial_partner_id.ref,
|
||||
'label': _('Customer Number:'),
|
||||
},
|
||||
'ref': {
|
||||
'value': self.ref,
|
||||
'label': _('Customer Number:'),
|
||||
},
|
||||
"icon": "\U0001f310",
|
||||
"label": _("Website:"),
|
||||
},
|
||||
"address": {
|
||||
"value": self._display_address(without_company=True),
|
||||
},
|
||||
"vat": {
|
||||
"value": self.commercial_partner_id.vat,
|
||||
"label": _("VAT Number:"),
|
||||
},
|
||||
"commercial_ref": {
|
||||
"value": self.commercial_partner_id.ref,
|
||||
"label": _("Customer Number:"),
|
||||
},
|
||||
"ref": {
|
||||
"value": self.ref,
|
||||
"label": _("Customer Number:"),
|
||||
},
|
||||
# Same with 'supplier_' prefix, to change the label
|
||||
'supplier_commercial_ref': {
|
||||
'value': self.commercial_partner_id.ref,
|
||||
'label': _('Supplier Number:'),
|
||||
},
|
||||
'supplier_ref': {
|
||||
'value': self.ref,
|
||||
'label': _('Supplier Number:'),
|
||||
},
|
||||
}
|
||||
"supplier_commercial_ref": {
|
||||
"value": self.commercial_partner_id.ref,
|
||||
"label": _("Supplier Number:"),
|
||||
},
|
||||
"supplier_ref": {
|
||||
"value": self.ref,
|
||||
"label": _("Supplier Number:"),
|
||||
},
|
||||
}
|
||||
res = []
|
||||
for detail in details:
|
||||
if options.get(detail) and options[detail]['value']:
|
||||
if options.get(detail) and options[detail]["value"]:
|
||||
entry = options[detail]
|
||||
prefix = icon and entry.get('icon') or entry.get('label')
|
||||
prefix = icon and entry.get("icon") or entry.get("label")
|
||||
if prefix:
|
||||
res.append('%s %s' % (prefix, entry['value']))
|
||||
res.append("%s %s" % (prefix, entry["value"]))
|
||||
else:
|
||||
res.append('%s' % entry['value'])
|
||||
res = '\n'.join(res)
|
||||
res.append("%s" % entry["value"])
|
||||
res = "\n".join(res)
|
||||
return res
|
||||
|
||||
@@ -6,9 +6,9 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class ResPartnerBank(models.Model):
|
||||
_inherit = 'res.partner.bank'
|
||||
_inherit = "res.partner.bank"
|
||||
|
||||
# In the 'base' module, they didn't put any string, so the bank name is
|
||||
# displayed as 'Name', which the string of the related field it
|
||||
# points to
|
||||
bank_name = fields.Char(string='Bank Name')
|
||||
bank_name = fields.Char(string="Bank Name")
|
||||
|
||||
@@ -6,6 +6,6 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class ResPartnerCategory(models.Model):
|
||||
_inherit = 'res.partner.category'
|
||||
_inherit = "res.partner.category"
|
||||
|
||||
name = fields.Char(translate=False)
|
||||
|
||||
@@ -2,26 +2,26 @@
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models, SUPERUSER_ID
|
||||
import logging
|
||||
|
||||
from odoo import SUPERUSER_ID, api, models
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
_inherit = 'res.users'
|
||||
_inherit = "res.users"
|
||||
|
||||
@api.model
|
||||
def _script_partners_linked_to_users_no_company(self):
|
||||
if self.env.user.id != SUPERUSER_ID:
|
||||
self = self.sudo()
|
||||
logger.info(
|
||||
'START to set company_id=False on partners related to users')
|
||||
logger.info("START to set company_id=False on partners related to users")
|
||||
users = self.with_context(active_test=False).search([])
|
||||
for user in users:
|
||||
if user.partner_id.company_id:
|
||||
user.partner_id.write({'company_id': False})
|
||||
user.partner_id.write({"company_id": False})
|
||||
logger.info(
|
||||
'Wrote company_id=False on user %s ID %d',
|
||||
user.login, user.id)
|
||||
logger.info(
|
||||
'END setting company_id=False on partners related to users')
|
||||
"Wrote company_id=False on user %s ID %d", user.login, user.id
|
||||
)
|
||||
logger.info("END setting company_id=False on partners related to users")
|
||||
|
||||
Reference in New Issue
Block a user