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 authored and V3st1g3 committed Nov 7, 2024
1 parent 27cc7e8 commit da4ab84
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion account_invoice_import/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Account Invoice Import
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9ad4e4cf38e9978675644fa8918e5dc342177d73673e9e56d469daaafe5c0cda
!! source digest: sha256:26f0853d4122605d020e48687fa420f66fdad1a6c7e41efe74059e0a845f5348
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion account_invoice_import/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Account Invoice Import",
"version": "14.0.3.3.2",
"version": "14.0.3.4.0",
"category": "Accounting & Finance",
"license": "AGPL-3",
"summary": "Import supplier invoices/refunds as PDF or XML files",
Expand Down
14 changes: 8 additions & 6 deletions account_invoice_import/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Account Invoice Import</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9ad4e4cf38e9978675644fa8918e5dc342177d73673e9e56d469daaafe5c0cda
!! source digest: sha256:26f0853d4122605d020e48687fa420f66fdad1a6c7e41efe74059e0a845f5348
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/edi/tree/14.0/account_invoice_import"><img alt="OCA/edi" src="https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/edi&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module has been started by lazy accounting users who hate enter they vendor bills manually in Odoo. Almost all companies have several vendor bills to enter regularly in the system from the same vendors: phone bill, electricity bill, Internet access, train tickets, etc. Most of these invoices are available as PDF. If we are able to automatically extract from the PDF the required information to enter the invoice as vendor bill in Odoo, then this module will create it automatically. To know the full story behind the development of this module, read this <a class="reference external" href="http://www.akretion.com/blog/akretions-christmas-present-for-the-odoo-community">blog post</a>.</p>
Expand Down Expand Up @@ -466,7 +466,9 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
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 da4ab84

Please sign in to comment.