Skip to content

Commit

Permalink
[IMP] account_invoice_import_invoice2data: refactor code + adopt module
Browse files Browse the repository at this point in the history
  • Loading branch information
bosd committed Oct 7, 2023
1 parent 5863d99 commit 6a6192e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 1 addition & 2 deletions account_invoice_import_invoice2data/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 6a6192e

Please sign in to comment.