Skip to content

Commit 8ecd7a1

Browse files
committed
[FIX] base_import_pdf_by_template_account: Preventing 2 attachments linked to the same invoice
Required since odoo/odoo@51d327b TT54750
1 parent abbd9f7 commit 8ecd7a1

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

base_import_pdf_by_template_account/models/account_move.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Copyright 2024-2025 Tecnativa - Víctor Martínez
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3-
from base64 import b64encode
4-
53
from odoo import models
64

75

@@ -17,19 +15,14 @@ def _import_base_import_pdf_by_template(self, file_data, new=False):
1715
total_templates = template_model.search_count([("model", "=", self._name)])
1816
if total_templates == 0:
1917
return False
20-
# We need to create the attachment that we will use in the wizard because it
21-
# has not been created yet.
22-
attachment = self.env["ir.attachment"].create(
23-
{"name": file_data["filename"], "datas": b64encode(file_data["content"])}
24-
)
2518
self.move_type = (
2619
"in_invoice" if self.journal_id.type == "purchase" else "out_invoice"
2720
)
2821
wizard = self.env["wizard.base.import.pdf.upload"].create(
2922
{
3023
"model": self._name,
3124
"record_ref": f"{self._name},{self.id}",
32-
"attachment_ids": [(6, 0, attachment.ids)],
25+
"attachment_ids": [(6, 0, file_data["attachment"].ids)],
3326
}
3427
)
3528
wizard.with_context(skip_template_not_found_error=True).action_process()

base_import_pdf_by_template_account/tests/test_base_import_pdf_by_template_account.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Tecnativa - Víctor Martínez
1+
# Copyright 2024-2025 Tecnativa - Víctor Martínez
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

44
from base64 import b64encode
@@ -220,13 +220,15 @@ def test_account_invoice_tecnativa(self):
220220
res = wizard.action_process()
221221
self.assertEqual(res["res_model"], "account.move")
222222
record = self.env[res["res_model"]].browse(res["res_id"])
223-
self.assertIn(attachment, record.attachment_ids)
223+
self.assertEqual(len(record.attachment_ids), 1)
224+
self.assertEqual(attachment, record.attachment_ids)
224225
self._test_account_invoice_tecnativa_data(record)
225226

226227
def test_account_move_edi_decoder(self):
227228
attachment = self._create_ir_attachment("account_invoice_tecnativa.pdf")
228229
invoice = self.journal.with_context(
229230
default_journal_id=self.journal.id
230231
)._create_document_from_attachment(attachment.id)
231-
self.assertIn(attachment, invoice.attachment_ids)
232+
self.assertEqual(len(invoice.attachment_ids), 1)
233+
self.assertEqual(attachment, invoice.attachment_ids)
232234
self._test_account_invoice_tecnativa_data(invoice)

0 commit comments

Comments
 (0)