-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccount_move.py
39 lines (35 loc) · 1.65 KB
/
account_move.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright 2024-2025 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class AccountMove(models.Model):
_inherit = "account.move"
def _import_base_import_pdf_by_template(self, file_data, new=False):
"""Method to process the PDF with base_import_pdf_by_template_account
if any template is available (similar to account_edi_ubl_cii)."""
template_model = self.env["base.import.pdf.template"].with_company(
self.company_id.id
)
total_templates = template_model.search_count([("model", "=", self._name)])
if total_templates == 0:
return False
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, file_data["attachment"].ids)],
}
)
wizard.with_context(skip_template_not_found_error=True).action_process()
return True
def _get_edi_decoder(self, file_data, new=False):
if file_data["type"] == "pdf":
res = self._import_base_import_pdf_by_template(file_data, new)
if res:
# If everything worked correctly, we return False to avoid what
# is done in the _extend_with_attachments() method of account
# with the result of the _get_edi_decoder() method.
return False
return super()._get_edi_decoder(file_data, new=new)