summaryrefslogtreecommitdiff
path: root/addons/account/models/ir_actions_report.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account/models/ir_actions_report.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account/models/ir_actions_report.py')
-rw-r--r--addons/account/models/ir_actions_report.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/addons/account/models/ir_actions_report.py b/addons/account/models/ir_actions_report.py
new file mode 100644
index 00000000..27deaa9f
--- /dev/null
+++ b/addons/account/models/ir_actions_report.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+
+from odoo import models, api, _
+from odoo.exceptions import UserError
+
+class IrActionsReport(models.Model):
+ _inherit = 'ir.actions.report'
+
+ 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)
+
+ 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)
+
+ 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
+ res = super(IrActionsReport, self)._postprocess_pdf_report(record, buffer)
+ if self.model == 'account.move' and record.state == 'posted' and record.is_sale_document(include_receipts=True):
+ attachment = self.retrieve_attachment(record)
+ if attachment:
+ attachment.register_as_main_attachment(force=False)
+ return res