Skip to content

Commit

Permalink
[IMP] account_invoice_import: add support for discount
Browse files Browse the repository at this point in the history
Add support for discount on lines in the multi-line create scenario
  • Loading branch information
alexis-via committed Jul 25, 2024
1 parent 01dfaaf commit ccd0de7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions account_invoice_import/tests/test_invoice_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ def test_import_out_invoice(self):
"product": {"code": "AII-TEST-PRODUCT"},
"name": "Super product",
"qty": 3,
"price_unit": 10.22,
"discount": 10,
"price_unit": 100,
"date_start": "2017-08-01",
"date_end": "2017-08-31",
"taxes": [
Expand All @@ -334,8 +335,10 @@ def test_import_out_invoice(self):
.with_company(self.company.id)
.create_invoice(parsed_inv, import_config)
)
self.assertFalse(inv.currency_id.compare_amounts(inv.amount_untaxed, 30.66))
self.assertFalse(inv.currency_id.compare_amounts(inv.amount_total, 30.97))
self.assertFalse(
inv.currency_id.compare_amounts(inv.amount_untaxed, 270.00)
)
self.assertFalse(inv.currency_id.compare_amounts(inv.amount_total, 272.70))
self.assertEqual(
fields.Date.to_string(inv.invoice_date), parsed_inv["date"]
)
Expand Down
8 changes: 7 additions & 1 deletion account_invoice_import/wizard/account_invoice_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ def fallback_parse_pdf_invoice(self, file_data):
# },
# 'name': 'Gelierzucker Extra 250g',
# 'price_unit': 1.45, # price_unit without taxes
# 'discount': 10.0, # for 10% discount
# 'qty': 2.0,
# 'price_subtotal': 2.90, # not required, but needed
# 'price_subtotal': 2.61, # not required, but needed
# to be able to generate adjustment lines when decimal
# precision is not high enough in Odoo
# 'uom': {'unece_code': 'C62'},
Expand Down Expand Up @@ -424,6 +425,7 @@ def _prepare_line_vals_nline(self, partner, vals, parsed_inv, import_config):
{
"quantity": line["qty"],
"price_unit": line["price_unit"], # TODO fix for tax incl
"discount": line.get("discount", 0),
}
)
if start_end_dates_installed:
Expand Down Expand Up @@ -540,6 +542,7 @@ def pre_process_parsed_inv(self, parsed_inv):
if not parsed_inv.get("currency_rounding"):
self.get_precision_rounding_from_currency_helper(parsed_inv)
prec_pp = self.env["decimal.precision"].precision_get("Product Price")
prec_disc = self.env["decimal.precision"].precision_get("Discount")
prec_uom = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
Expand Down Expand Up @@ -583,6 +586,9 @@ def pre_process_parsed_inv(self, parsed_inv):
line["price_unit"] = float_round(
line["price_unit"], precision_digits=prec_pp
)
line["discount"] = float_round(
line.get("discount", 0), precision_digits=prec_disc
)
parsed_inv_for_log = dict(parsed_inv)
if "attachments" in parsed_inv_for_log:
parsed_inv_for_log.pop("attachments")
Expand Down

0 comments on commit ccd0de7

Please sign in to comment.