From 04114043bb970488f9fb17c2e406f37709a0589b Mon Sep 17 00:00:00 2001 From: Goaman Date: Wed, 26 Jun 2019 15:37:38 +0000 Subject: [PATCH] [IMP] account: Allow to merge and print original vendor bills This commit add an action to merge and print the original vendor bills through the field 'message_main_attachment_id'. Was task 2006908 closes odoo/odoo#34023 Signed-off-by: Quentin De Paoli (qdp) --- addons/account/models/__init__.py | 1 + addons/account/models/ir_actions_report.py | 33 ++++++++++++++++++++++ addons/account/views/account_report.xml | 11 ++++++++ addons/account/views/report_invoice.xml | 11 ++++++++ 4 files changed, 56 insertions(+) create mode 100644 addons/account/models/ir_actions_report.py diff --git a/addons/account/models/__init__.py b/addons/account/models/__init__.py index f52625112da..ea94120355d 100644 --- a/addons/account/models/__init__.py +++ b/addons/account/models/__init__.py @@ -21,3 +21,4 @@ from . import reconciliation_widget from . import account_incoterms from . import digest from . import res_users +from . import ir_actions_report diff --git a/addons/account/models/ir_actions_report.py b/addons/account/models/ir_actions_report.py new file mode 100644 index 00000000000..a9df7eebb41 --- /dev/null +++ b/addons/account/models/ir_actions_report.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +from odoo import models, api, _ +from odoo.exceptions import UserError + +class IrActionsReport(models.Model): + _inherit = 'ir.actions.report' + + @api.multi + def retrieve_attachment(self, record): + # get the original bills through the message_main_attachment_id field of the record + if self.report_name == 'account.report_original_vendor_bill' and record.message_main_attachment_id: + if record.message_main_attachment_id.mimetype == 'application/pdf' or \ + record.message_main_attachment_id.mimetype.startswith('image'): + return record.message_main_attachment_id + return super(IrActionsReport, self).retrieve_attachment(record) + + @api.multi + def _post_pdf(self, save_in_attachment, pdf_content=None, res_ids=None): + # don't include the generated dummy report + if self.report_name == 'account.report_original_vendor_bill': + pdf_content = None + res_ids = None + if not save_in_attachment: + raise UserError(_("No original vendor bills could be found for any of the selected vendor bills.")) + return super(IrActionsReport, self)._post_pdf(save_in_attachment, pdf_content=pdf_content, res_ids=res_ids) + + @api.multi + def postprocess_pdf_report(self, record, buffer): + # don't save the 'account.report_original_vendor_bill' report as it's just a mean to print existing attachments + if self.report_name == 'account.report_original_vendor_bill': + return None + return super(IrActionsReport, self).postprocess_pdf_report(record, buffer) diff --git a/addons/account/views/account_report.xml b/addons/account/views/account_report.xml index 9a8dc5c5c2a..6e5651dc8c7 100644 --- a/addons/account/views/account_report.xml +++ b/addons/account/views/account_report.xml @@ -14,6 +14,17 @@ groups="account.group_account_invoice" /> + + + + +