diff options
| author | Rémi Rahir <rar@odoo.com> | 2018-09-16 20:37:25 +0200 |
|---|---|---|
| committer | Rémi Rahir <rar@odoo.com> | 2018-09-19 17:58:35 +0200 |
| commit | 46dc8ceef90ec5472b1aa4b45509f23d6c3e2624 (patch) | |
| tree | 990b336d942be432672857a6c7ffedabb5cdad34 /addons/snailmail | |
| parent | 2f3c69d7c44737a9ebb448f7f7a9cc4a9af816d4 (diff) | |
[IMP] snailmail: adapt reports for snailmail
In order to ease the integration with the snailmail posting service provider,
We will generate specific reports with a layout that fits their
criteria.
In short,
* we specify the postition of the recipient's address on the
document
* we force the A4 format
This also support the din5008 type B report.
Diffstat (limited to 'addons/snailmail')
| -rw-r--r-- | addons/snailmail/__manifest__.py | 1 | ||||
| -rw-r--r-- | addons/snailmail/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/snailmail/models/ir_actions_report.py | 25 | ||||
| -rw-r--r-- | addons/snailmail/models/snailmail_letter.py | 11 | ||||
| -rw-r--r-- | addons/snailmail/static/src/scss/snailmail_external_layout_asset.scss | 32 | ||||
| -rw-r--r-- | addons/snailmail/views/report_assets.xml | 17 |
6 files changed, 86 insertions, 1 deletions
diff --git a/addons/snailmail/__manifest__.py b/addons/snailmail/__manifest__.py index 5435f816013..463832ce6b9 100644 --- a/addons/snailmail/__manifest__.py +++ b/addons/snailmail/__manifest__.py @@ -10,6 +10,7 @@ Allows users to send documents by post 'depends': ['iap', 'mail'], 'data': [ 'data/snailmail_data.xml', + 'views/report_assets.xml', 'views/res_config_settings_views.xml', 'views/snailmail_views.xml', 'security/ir.model.access.csv', diff --git a/addons/snailmail/models/__init__.py b/addons/snailmail/models/__init__.py index ee0d4f4704c..cbf1ce99ac5 100644 --- a/addons/snailmail/models/__init__.py +++ b/addons/snailmail/models/__init__.py @@ -3,3 +3,4 @@ from . import res_company from . import res_config_settings from . import snailmail_letter +from . import ir_actions_report
\ No newline at end of file diff --git a/addons/snailmail/models/ir_actions_report.py b/addons/snailmail/models/ir_actions_report.py new file mode 100644 index 00000000000..59c7487d804 --- /dev/null +++ b/addons/snailmail/models/ir_actions_report.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +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 + res = super(IrActionsReport, self).get_paperformat() + if self.env.context.get('snailmail_layout') and res != self.env.ref('l10n_de.paperformat_euro_din', False): + paperformat_id = self.env.ref('base.paperformat_euro') + return paperformat_id + else: + return res diff --git a/addons/snailmail/models/snailmail_letter.py b/addons/snailmail/models/snailmail_letter.py index 4ff996000b6..adbdb1268f5 100644 --- a/addons/snailmail/models/snailmail_letter.py +++ b/addons/snailmail/models/snailmail_letter.py @@ -65,7 +65,7 @@ class SnailmailLetter(models.Model): else: report_name = 'Document' filename = "%s.%s" % (report_name, "pdf") - pdf_bin, _ = report.render_qweb_pdf(self.res_id) + pdf_bin, _ = report.with_context(snailmail_layout=True).render_qweb_pdf(self.res_id) attachment = self.env['ir.attachment'].create({ 'name': filename, 'datas': base64.b64encode(pdf_bin), @@ -160,6 +160,11 @@ class SnailmailLetter(models.Model): if route == 'estimate' and batch: document.update(pages=1) else: + # adding the web logo from the company for future possible customization + if route == 'print': + document.update({ + 'company_logo': letter.company_id.logo_web, + }) attachment = letter._fetch_attachment() if attachment: document.update({ @@ -172,6 +177,10 @@ class SnailmailLetter(models.Model): 'state': 'error', }) continue + if letter.report_template == self.env.ref('l10n_de.external_layout_din5008', False): + document.update({ + 'rightaddress': 0, + }) documents.append(document) return { diff --git a/addons/snailmail/static/src/scss/snailmail_external_layout_asset.scss b/addons/snailmail/static/src/scss/snailmail_external_layout_asset.scss new file mode 100644 index 00000000000..be7331a9b61 --- /dev/null +++ b/addons/snailmail/static/src/scss/snailmail_external_layout_asset.scss @@ -0,0 +1,32 @@ +/* Generic report layouts*/ +.header { + height: 200px; +} +.article>.page { + > h1, > h2, > h3 { + width: 50%; + } +} +.article { + > .address.row { + padding-top: 95px; + } + > .page { + margin-top:-20px; + } +} + +/*l10n_de_din layout*/ +.din { + .invoice_address { + top: 27.7mm !important; + } + &.article { + .page { + top: 18.46mm !important; + } + } + &.o_background_footer { + top: -8mm !important; + } +} diff --git a/addons/snailmail/views/report_assets.xml b/addons/snailmail/views/report_assets.xml new file mode 100644 index 00000000000..e73de6ed3d4 --- /dev/null +++ b/addons/snailmail/views/report_assets.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <template id="report_assets_snailmail"> + <t t-call="web._assets_helpers"/> + <link rel="stylesheet" type="text/scss" href="/snailmail/static/src/scss/snailmail_external_layout_asset.scss"/> + </template> + <template id="report_layout" inherit_id="web.report_layout"> + <xpath expr="//head" position="inside"> + <t t-if="env.context.get('snailmail_layout')" t-call-assets="snailmail.report_assets_snailmail"/> + </xpath> + </template> + <template id="minimal_layout" inherit_id="web.minimal_layout"> + <xpath expr="//head" position="inside"> + <t t-if="env.context.get('snailmail_layout')" t-call-assets="snailmail.report_assets_snailmail"/> + </xpath> + </template> +</odoo> |
