From 218fbaf90b55125db7d4220d8afaa4516bf57ae5 Mon Sep 17 00:00:00 2001 From: "Antoine Prieels (ANP)" Date: Tue, 16 Oct 2018 11:20:05 +0000 Subject: [PATCH 1/2] [IMP] snailmail: Change formatting of address in snailmail The previos format displayed the fields 'street' and 'street2' on two different line, making the address too big for the address area allowed by Pingen. --- addons/snailmail/models/res_partner.py | 10 +++++++++- odoo/addons/base/models/res_partner.py | 11 +++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) 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 '', From 5032828d5a0f9b89de3ce8883193cbc40e423ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir?= Date: Wed, 17 Oct 2018 12:59:57 +0000 Subject: [PATCH 2/2] [FIX] snailmail: instable behaviour on print Since commit b6a981405e1c211b3d5377ff53a2bb7847225d6f we require a certain key in the context to apply the custom snailmail report layout. This was badly managed and would eventually confilt inside the modal that links snailmail and the mail composer. This fix stabilises the biehaviour by properly propagating the context key. --- addons/snailmail/models/ir_actions_report.py | 8 -------- addons/snailmail/models/ir_qweb_fields.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 10 deletions(-) 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)