[FIX] account: fix invoice_report_file_id if proforma pdf
When triggering the Send & Print with the allow_fallback_pdf=True, if an error occurs (e.g.: no UNSCPC code on the product with CFDI), the proforma PDF is generated instead and is assigned to `invoice_report_file_id`. However, only a successful PDF should be bound to this field. task-3542881 closes odoo/odoo#138206 Related: odoo/enterprise#49137 Signed-off-by: Laurent Smet (las) <las@odoo.com>
This commit is contained in:
@@ -884,8 +884,9 @@ class TestAccountMoveSend(TestAccountMoveSendCommon):
|
||||
self.assertEqual(results['type'], 'ir.actions.act_url')
|
||||
self.assertRecordValues(wizard, [{'mode': 'done'}])
|
||||
|
||||
# The PDF is generated even in case of error.
|
||||
self.assertTrue(invoice.invoice_pdf_report_id)
|
||||
# The PDF is generated even in case of error, but invoice_pdf_report_id is not set
|
||||
self.assertFalse(invoice.invoice_pdf_report_id)
|
||||
self.assertTrue(invoice.message_main_attachment_id)
|
||||
|
||||
def test_with_unlink_invoices(self):
|
||||
invoice = self.init_invoice("out_invoice", amounts=[1000], post=True)
|
||||
|
||||
@@ -535,7 +535,7 @@ class AccountMoveSend(models.Model):
|
||||
}
|
||||
for invoice, invoice_data in invoices_data_pdf.items():
|
||||
form = invoice_data['_form']
|
||||
if form._need_invoice_document(invoice):
|
||||
if form._need_invoice_document(invoice) and not invoice_data.get('error'):
|
||||
form._prepare_invoice_pdf_report(invoice, invoice_data)
|
||||
form._hook_invoice_document_after_pdf_report_render(invoice, invoice_data)
|
||||
|
||||
@@ -548,8 +548,6 @@ class AccountMoveSend(models.Model):
|
||||
}
|
||||
if invoices_data_pdf_error:
|
||||
self._hook_if_errors(invoices_data_pdf_error, allow_fallback_pdf=allow_fallback_pdf)
|
||||
for invoice_data in invoices_data_pdf_error.values():
|
||||
invoice_data.pop('error')
|
||||
|
||||
# Web-service after the PDF generation.
|
||||
invoices_data_web_service = {
|
||||
|
||||
@@ -144,7 +144,8 @@ class AccountMoveSend(models.Model):
|
||||
return
|
||||
|
||||
# Read pdf content.
|
||||
reader_buffer = io.BytesIO(invoice_data['pdf_attachment_values']['raw'])
|
||||
pdf_values = invoice_data.get('pdf_attachment_values') or invoice_data['proforma_pdf_attachment_values']
|
||||
reader_buffer = io.BytesIO(pdf_values['raw'])
|
||||
reader = OdooPdfFileReader(reader_buffer, strict=False)
|
||||
|
||||
# Post-process.
|
||||
@@ -174,7 +175,7 @@ class AccountMoveSend(models.Model):
|
||||
# Replace the current content.
|
||||
writer_buffer = io.BytesIO()
|
||||
writer.write(writer_buffer)
|
||||
invoice_data['pdf_attachment_values']['raw'] = writer_buffer.getvalue()
|
||||
pdf_values['raw'] = writer_buffer.getvalue()
|
||||
reader_buffer.close()
|
||||
writer_buffer.close()
|
||||
|
||||
@@ -185,8 +186,9 @@ class AccountMoveSend(models.Model):
|
||||
if not anchor_elements:
|
||||
return
|
||||
|
||||
filename = invoice_data['pdf_attachment_values']['name']
|
||||
content = invoice_data['pdf_attachment_values']['raw']
|
||||
pdf_values = invoice_data.get('pdf_attachment_values') or invoice_data['proforma_pdf_attachment_values']
|
||||
filename = pdf_values['name']
|
||||
content = pdf_values['raw']
|
||||
|
||||
edi_model = invoice_data["ubl_cii_xml_options"]["builder"]
|
||||
doc_type_code_vals = edi_model._get_document_type_code_vals(invoice, invoice_data)
|
||||
|
||||
Reference in New Issue
Block a user