From 6a6192e335b5803b7e3476d023eccccab3951e0e Mon Sep 17 00:00:00 2001 From: bosd Date: Sat, 7 Oct 2023 19:54:06 +0200 Subject: [PATCH] [IMP] account_invoice_import_invoice2data: refactor code + adopt module --- .../__manifest__.py | 3 +-- .../wizard/account_invoice_import.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/account_invoice_import_invoice2data/__manifest__.py b/account_invoice_import_invoice2data/__manifest__.py index d4446b08cb5..1af774f194f 100644 --- a/account_invoice_import_invoice2data/__manifest__.py +++ b/account_invoice_import_invoice2data/__manifest__.py @@ -9,10 +9,9 @@ "license": "AGPL-3", "summary": "Import supplier invoices using the invoice2data lib", "author": "Akretion,Odoo Community Association (OCA)", - "maintainers": ["alexis-via"], + "maintainers": ["alexis-via", "bosd"], "website": "https://github.com/OCA/edi", "depends": ["account_invoice_import"], - # "excludes": ["account_invoice_import_simple_pdf"], "external_dependencies": { "python": [ "invoice2data", diff --git a/account_invoice_import_invoice2data/wizard/account_invoice_import.py b/account_invoice_import_invoice2data/wizard/account_invoice_import.py index 3dff1251a50..f4b4852c40e 100644 --- a/account_invoice_import_invoice2data/wizard/account_invoice_import.py +++ b/account_invoice_import_invoice2data/wizard/account_invoice_import.py @@ -120,12 +120,9 @@ def invoice2data_parse_invoice(self, file_data): fileobj.close() return self.invoice2data_to_parsed_inv(invoice2data_res) - @api.model - def invoice2data_to_parsed_inv(self, invoice2data_res): - lines = invoice2data_res.get("lines", []) - + def invoice2data_prepare_lines(self, lines): + """ Manipulate line data to match with account_invoice_import""" for line in lines: - # Manipulate line data to match with account_invoice_import line["price_unit"] = float(line.get("price_unit", 0)) taxes = self.parse_invoice2data_taxes(line) line["taxes"] = taxes # or global_taxes, @@ -154,6 +151,12 @@ def invoice2data_to_parsed_inv(self, invoice2data_res): if line.get("line_note"): line["line_note"] = line.get("line_note") line["sectionheader"] = line.get("sectionheader") + return lines + + @api.model + def invoice2data_to_parsed_inv(self, invoice2data_res): + lines = invoice2data_res.get("lines", []) + prepared_lines = self.invoice2data_prepare_lines(lines) parsed_inv = { "partner": { @@ -199,7 +202,7 @@ def invoice2data_to_parsed_inv(self, invoice2data_res): "payment_reference": invoice2data_res.get("payment_reference"), "payment_unece_code": invoice2data_res.get("payment_unece_code"), "incoterm": invoice2data_res.get("incoterm"), - "lines": lines, + "lines": prepared_lines, } for field in ["invoice_number", "description"]: if isinstance(invoice2data_res.get(field), list):