[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) <qdp@openerp.com>
This commit is contained in:
@@ -21,3 +21,4 @@ from . import reconciliation_widget
|
||||
from . import account_incoterms
|
||||
from . import digest
|
||||
from . import res_users
|
||||
from . import ir_actions_report
|
||||
|
||||
@@ -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)
|
||||
@@ -14,6 +14,17 @@
|
||||
groups="account.group_account_invoice"
|
||||
/>
|
||||
|
||||
<report
|
||||
id="action_account_original_vendor_bill"
|
||||
model="account.move"
|
||||
string="Original vendor bills"
|
||||
report_type="qweb-pdf"
|
||||
name="account.report_original_vendor_bill"
|
||||
file="account.report_original_vendor_bill"
|
||||
attachment="'original_vendor_bill.pdf'"
|
||||
attachment_use="True"
|
||||
/>
|
||||
|
||||
<report
|
||||
id="account_invoices_without_payment"
|
||||
model="account.move"
|
||||
|
||||
@@ -230,5 +230,16 @@
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<!--We need to create the following empty report template for the action report
|
||||
"action_account_original_vendor_bill" to work. The action is merging the
|
||||
original vendor bill(s) that were used to create the vendor bill(s) into one PDF. -->
|
||||
<template id="report_original_vendor_bill">
|
||||
<t t-call="web.html_container">
|
||||
<t t-foreach="docs" t-as="o">
|
||||
<div class="article" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id" t-att-data-oe-lang="o and o.env.context.get('lang')"></div>
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user