diff --git a/addons/snailmail/models/ir_actions_report.py b/addons/snailmail/models/ir_actions_report.py index 59c7487d804..2a1ad2f9496 100644 --- a/addons/snailmail/models/ir_actions_report.py +++ b/addons/snailmail/models/ir_actions_report.py @@ -6,14 +6,6 @@ from odoo import models, fields, api, _ class IrActionsReport(models.Model): _inherit = 'ir.actions.report' - @api.model - def _get_rendering_context(self, docids, data): - res = super(IrActionsReport, self)._get_rendering_context(docids, data) - # Add snailmail_layout if specified in the context - if self.env.context.get('snailmail_layout'): - res.update({'snailmail_layout': True}) - return res - @api.model def get_paperformat(self): # force the right format (euro/A4) when sending letters, only if we are not using the l10n_DE layout diff --git a/addons/snailmail/models/ir_qweb_fields.py b/addons/snailmail/models/ir_qweb_fields.py index 82a538170e0..b005fdd342f 100644 --- a/addons/snailmail/models/ir_qweb_fields.py +++ b/addons/snailmail/models/ir_qweb_fields.py @@ -8,6 +8,12 @@ class Contact(models.AbstractModel): @api.model def value_to_html(self, value, options): - snailmail_layout = options['template_options'].get('snailmail_layout') - value = value.with_context(snailmail_layout=snailmail_layout) + if self.env.context.get('snailmail_layout'): + value = value.with_context(snailmail_layout=self.env.context['snailmail_layout']) return super(Contact, self).value_to_html(value, options) + + @api.model + def record_to_html(self, record, field_name, options): + if self.env.context.get('snailmail_layout'): + record = record.with_context(snailmail_layout=self.env.context['snailmail_layout']) + return super(Contact, self).record_to_html(record, field_name, options) diff --git a/addons/snailmail/models/res_partner.py b/addons/snailmail/models/res_partner.py index 5cc07efaf8b..449559d2e9d 100644 --- a/addons/snailmail/models/res_partner.py +++ b/addons/snailmail/models/res_partner.py @@ -12,10 +12,18 @@ class ResPartner(models.Model): @api.multi def _get_country_name(self): # when sending a letter, thus rendering the report with the snailmail_layout, - # we need to override the country name to its english version following the + # we need to override the country name to its english version following the # dictionary imported in country_utils.py country_code = self.country_id.code if self.env.context.get('snailmail_layout') and country_code in SNAILMAIL_COUNTRIES: return SNAILMAIL_COUNTRIES.get(country_code) return super(ResPartner, self)._get_country_name() + + @api.model + def _get_address_format(self): + # When sending a letter, the fields 'street' and 'street2' should be on a single line to fit in the address area + if self.env.context.get('snailmail_layout'): + return "%(street)s, %(street2)s\n%(city)s %(state_code)s %(zip)s\n%(country_name)s" + + return super(ResPartner, self)._get_address_format() \ No newline at end of file diff --git a/odoo/addons/base/models/res_partner.py b/odoo/addons/base/models/res_partner.py index 85be4b7ffc3..f5d0284af3f 100644 --- a/odoo/addons/base/models/res_partner.py +++ b/odoo/addons/base/models/res_partner.py @@ -21,7 +21,7 @@ from odoo.exceptions import UserError, ValidationError from odoo.tools import pycompat # Global variables used for the warning fields declared on the res.partner -# in the following modules : sale, purchase, account, stock +# in the following modules : sale, purchase, account, stock WARNING_MESSAGE = [ ('no-message','No Message'), ('warning','Warning'), @@ -460,7 +460,7 @@ class Partner(models.Model): # 1a. Commercial fields: sync if parent changed if values.get('parent_id'): self._commercial_sync_from_company() - # 1b. Address fields: sync if parent or use_parent changed *and* both are now set + # 1b. Address fields: sync if parent or use_parent changed *and* both are now set if self.parent_id and self.type == 'contact': onchange_vals = self.onchange_parent_id().get('value', {}) self.update_address(onchange_vals) @@ -811,6 +811,10 @@ class Partner(models.Model): def _get_default_address_format(self): return "%(street)s\n%(street2)s\n%(city)s %(state_code)s %(zip)s\n%(country_name)s" + @api.model + def _get_address_format(self): + return self.country_id.address_format or self._get_default_address_format() + @api.multi def _display_address(self, without_company=False): @@ -825,8 +829,7 @@ class Partner(models.Model): ''' # get the information that will be injected into the display format # get the address format - address_format = self.country_id.address_format or \ - self._get_default_address_format() + address_format = self._get_address_format() args = { 'state_code': self.state_id.code or '', 'state_name': self.state_id.name or '',