Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def action_process(self):
for line in self.line_ids.filtered("template_id"):
try:
records += line.action_process()
except Exception:
except Exception as e:
logger.info(e)
if not self.env.context.get("skip_template_not_found_error"):
raise
action = {
Expand Down Expand Up @@ -190,7 +191,8 @@ def _process_set_value_form(self, _form, field_name, value):
else:
try:
setattr(_form, field_name, value)
except Exception:
except Exception as e:
logger.info(e)
self._add_log_error_text(field_name, value)

def _process_form(self):
Expand All @@ -207,14 +209,18 @@ def _process_form(self):
# appropriate (fiscal position).
extra_vals = {}
for key in list(ctx.keys()):
if key.startswith("default_"):
# It is important to skip this field, when using fetchmail it
# is defined as default_ but it does not exist and there
# would be an error preventing the record from being created.
if key.startswith("default_") and key != "default_fetchmail_server_id":
field_name = key.replace("default_", "")
field_value = ctx[key]
if model._fields[field_name].type == "many2one":
field_value = model[field_name].browse(field_value)
try:
setattr(model_form, field_name, field_value)
except Exception:
except Exception as e:
logger.info(e)
extra_vals[field_name] = ctx[key]
# Set the values of the header in Form
header_values = template._get_field_header_values(text)
Expand All @@ -237,7 +243,8 @@ def _process_form(self):
child_field_value = child_fixed_values[field_name]
try:
setattr(line_form, field_name, child_field_value)
except Exception:
except Exception as e:
logger.info(e)
self._add_log_error_text(field_name, child_field_value)
# set the values of any line
for field_name in list(line.keys()):
Expand Down
1 change: 1 addition & 0 deletions base_import_pdf_by_template_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import account_move
from . import ir_attachment
30 changes: 30 additions & 0 deletions base_import_pdf_by_template_account/models/ir_attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2025 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models


class IrAttachment(models.Model):
_inherit = "ir.attachment"

# TODO: Remove in v19 because _extend_with_attachments() method is properly done
# in account.document.import.mixin
def _unwrap_edi_attachments(self):
to_process = super()._unwrap_edi_attachments()
if len(to_process) > 1 and any(a["type"] == "pdf" for a in to_process):
attachment = to_process[0]["attachment"]
if attachment.res_model and attachment.res_id:
record = self.env[attachment.res_model].browse(attachment.res_id)
template_model = self.env["base.import.pdf.template"]
if "company_id" in record._fields:
template_model = template_model.with_company(record.company_id.id)
total_templates = template_model.search_count(
[("model", "=", record._name)]
)
if total_templates > 0:
# Define a sort_weight=1 to have a higher priority in the
# _extend_with_attachments() method when doing the decoder
for to_process_item in to_process:
if to_process_item["type"] == "pdf":
to_process_item["sort_weight"] = 1
to_process.sort(key=lambda x: x["sort_weight"])
return to_process