Skip to content

Commit 6f29dda

Browse files
committed
[FIX] base_import_pdf_by_template_account: Avoid error when adding a pdf attachment to an invoice if no template applies
TT54717
1 parent fed49e6 commit 6f29dda

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def action_process(self):
6060
self.line_ids = lines
6161
# Error si corresponde
6262
lines_without_template = self.line_ids.filtered(lambda x: not x.template_id)
63-
if lines_without_template:
63+
if lines_without_template and not self.env.context.get(
64+
"skip_template_not_found_error"
65+
):
6466
raise UserError(
6567
_(
6668
"No template has been auto-detected from %s, it may be "
@@ -70,7 +72,7 @@ def action_process(self):
7072
)
7173
# Process + return records
7274
records = self.env[self.model]
73-
for line in self.line_ids:
75+
for line in self.line_ids.filtered("template_id"):
7476
records += line.action_process()
7577
action = {
7678
"type": "ir.actions.act_window",

base_import_pdf_by_template_account/models/account_move.py

+2-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
from base64 import b64encode
44

@@ -25,15 +25,14 @@ def _import_base_import_pdf_by_template(self, file_data, new=False):
2525
self.move_type = (
2626
"in_invoice" if self.journal_id.type == "purchase" else "out_invoice"
2727
)
28-
# return self._import_record_base_import_pdf_by_template(invoice, attachment)
2928
wizard = self.env["wizard.base.import.pdf.upload"].create(
3029
{
3130
"model": self._name,
3231
"record_ref": f"{self._name},{self.id}",
3332
"attachment_ids": [(6, 0, attachment.ids)],
3433
}
3534
)
36-
wizard.action_process()
35+
wizard.with_context(skip_template_not_found_error=True).action_process()
3736
return True
3837

3938
def _get_edi_decoder(self, file_data, new=False):

0 commit comments

Comments
 (0)