[IMP] snailmail: Change formatting of address in snailmail

The previous format displayed the fields 'street' and 'street2' on two different line, making the address too big for the address area allowed by Pingen.

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

closes odoo/odoo#27841
This commit is contained in:
Robot Odoo
2018-10-23 00:28:03 +02:00
committed by GitHub
4 changed files with 24 additions and 15 deletions
@@ -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
+8 -2
View File
@@ -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)
+9 -1
View File
@@ -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()
+7 -4
View File
@@ -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 '',