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 | |
| 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.
| -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 | ||||
| -rw-r--r-- | addons/web/views/report_templates.xml | 14 | ||||
| -rw-r--r-- | odoo/addons/base/models/ir_actions_report.py | 8 |
8 files changed, 102 insertions, 7 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> diff --git a/addons/web/views/report_templates.xml b/addons/web/views/report_templates.xml index ad3c2498d3e..4e26bd1e9a7 100644 --- a/addons/web/views/report_templates.xml +++ b/addons/web/views/report_templates.xml @@ -164,7 +164,7 @@ <template id="address_layout"> <t t-set="colclass" t-value="('col-md-5' if report_type == 'html' else 'col-5') + ' ml-auto'"/> <t t-if="address"> - <div class="row"> + <div class="address row"> <t t-if="information_block"> <t t-set="colclass" t-value="'col-5 offset-1'"/> <div name="information_block" class="col-6"> @@ -179,7 +179,8 @@ </template> <template id="external_layout_background"> - <div class="header o_background_header"> + <div class="header"> + <div class="o_background_header"> <div class="float-right"> <h3 class="mt0 text-right" t-field="company.report_header"/> </div> @@ -192,6 +193,7 @@ t-options='{"widget": "contact", "fields": ["address"], "no_marker": true}'/> </div> <div class="clearfix mb8"/> + </div> </div> <div class="article o_report_layout_background" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id"> @@ -219,7 +221,8 @@ </template> <template id="external_layout_boxed"> - <div class="header o_boxed_header"> + <div class="header"> + <div class="o_boxed_header"> <div class="row mb8"> <div class="col-6"> <img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % to_text(company.logo)" alt="Logo"/> @@ -232,6 +235,7 @@ </div> </div> </div> + </div> </div> <div class="article o_report_layout_boxed" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id"> @@ -256,7 +260,8 @@ </template> <template id="external_layout_clean"> - <div class="header o_clean_header"> + <div class="header"> + <div class="o_clean_header"> <div class="row"> <div class="col-6"> <img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % to_text(company.logo)" alt="Logo"/> @@ -271,6 +276,7 @@ </ul> </div> </div> + </div> </div> <div class="article o_report_layout_clean" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id"> diff --git a/odoo/addons/base/models/ir_actions_report.py b/odoo/addons/base/models/ir_actions_report.py index dfed8cedd0a..16257c836ac 100644 --- a/odoo/addons/base/models/ir_actions_report.py +++ b/odoo/addons/base/models/ir_actions_report.py @@ -196,6 +196,10 @@ class IrActionsReport(models.Model): return wkhtmltopdf_state @api.model + def get_paperformat(self): + return self.paperformat_id or self.env.user.company_id.paperformat_id + + @api.model def _build_wkhtmltopdf_args( self, paperformat_id, @@ -358,7 +362,7 @@ class IrActionsReport(models.Model): :param set_viewport_size: Enable a viewport sized '1024x1280' or '1280x1024' depending of landscape arg. :return: Content of the pdf as a string ''' - paperformat_id = self.paperformat_id or self.env.user.company_id.paperformat_id + paperformat_id = self.get_paperformat() # Build the base command args for wkhtmltopdf bin command_args = self._build_wkhtmltopdf_args( @@ -666,7 +670,7 @@ class IrActionsReport(models.Model): if self.attachment and set(res_ids) != set(html_ids): raise UserError(_("The report's template '%s' is wrong, please contact your administrator. \n\n" - "Can not separate file to save as attachment because the report's template does not contains the attributes 'data-model' and 'data-id' on the div with 'page' classname.") % self.name) + "Can not separate file to save as attachment because the report's template does not contains the attributes 'data-oe-model' and 'data-oe-id' on the div with 'article' classname.") % self.name) pdf_content = self._run_wkhtmltopdf( bodies, |
