Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][FIX] base_import_pdf_by_template_account: Preventing 2 attachments linked to the same invoice #1115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions base_import_pdf_by_template_account/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Copyright 2024-2025 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from base64 import b64encode

from odoo import models


Expand All @@ -17,19 +15,14 @@ def _import_base_import_pdf_by_template(self, file_data, new=False):
total_templates = template_model.search_count([("model", "=", self._name)])
if total_templates == 0:
return False
# We need to create the attachment that we will use in the wizard because it
# has not been created yet.
attachment = self.env["ir.attachment"].create(
{"name": file_data["filename"], "datas": b64encode(file_data["content"])}
)
self.move_type = (
"in_invoice" if self.journal_id.type == "purchase" else "out_invoice"
)
wizard = self.env["wizard.base.import.pdf.upload"].create(
{
"model": self._name,
"record_ref": f"{self._name},{self.id}",
"attachment_ids": [(6, 0, attachment.ids)],
"attachment_ids": [(6, 0, file_data["attachment"].ids)],
}
)
wizard.with_context(skip_template_not_found_error=True).action_process()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# Copyright 2024-2025 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from base64 import b64encode
Expand Down Expand Up @@ -220,13 +220,15 @@ def test_account_invoice_tecnativa(self):
res = wizard.action_process()
self.assertEqual(res["res_model"], "account.move")
record = self.env[res["res_model"]].browse(res["res_id"])
self.assertIn(attachment, record.attachment_ids)
self.assertEqual(len(record.attachment_ids), 1)
self.assertEqual(attachment, record.attachment_ids)
self._test_account_invoice_tecnativa_data(record)

def test_account_move_edi_decoder(self):
attachment = self._create_ir_attachment("account_invoice_tecnativa.pdf")
invoice = self.journal.with_context(
default_journal_id=self.journal.id
)._create_document_from_attachment(attachment.id)
self.assertIn(attachment, invoice.attachment_ids)
self.assertEqual(len(invoice.attachment_ids), 1)
self.assertEqual(attachment, invoice.attachment_ids)
self._test_account_invoice_tecnativa_data(invoice)
Loading