Skip to content

Commit 16511fa

Browse files
committed
[IMP] account_invoice_import
make it optional to raise an error if an existing draft invoice exists with the same partner
1 parent fd9ad5c commit 16511fa

File tree

4 files changed

+64
-50
lines changed

4 files changed

+64
-50
lines changed

account_invoice_import/README.rst

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
Account Invoice Import
33
======================
44

5-
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
67
!! This file is generated by oca-gen-addon-readme !!
78
!! changes will be overwritten. !!
89
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:3ce0b15bb8408de71e1a614b16fe5e00ced8f366b5d6c78510c049eec85c304c
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
912
1013
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1114
:target: https://odoo-community.org/page/development-status
@@ -14,16 +17,16 @@ Account Invoice Import
1417
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1518
:alt: License: AGPL-3
1619
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
17-
:target: https://github.com/OCA/edi/tree/14.0/account_invoice_import
20+
:target: https://github.com/OCA/edi/tree/16.0/account_invoice_import
1821
:alt: OCA/edi
1922
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20-
:target: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import
23+
:target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_invoice_import
2124
:alt: Translate me on Weblate
22-
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23-
:target: https://runbot.odoo-community.org/runbot/226/14.0
24-
:alt: Try me on Runbot
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=16.0
27+
:alt: Try me on Runboat
2528

26-
|badge1| |badge2| |badge3| |badge4| |badge5|
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
2730

2831
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 `blog post <http://www.akretion.com/blog/akretions-christmas-present-for-the-odoo-community>`_.
2932

@@ -94,8 +97,8 @@ Bug Tracker
9497

9598
Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
9699
In case of trouble, please check there if your issue has already been reported.
97-
If you spotted it first, help us smashing it by providing a detailed and welcomed
98-
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
100+
If you spotted it first, help us to smash it by providing a detailed and welcomed
101+
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
99102

100103
Do not contact contributors directly about support or help with technical issues.
101104

@@ -138,6 +141,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
138141

139142
|maintainer-alexis-via|
140143

141-
This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/14.0/account_invoice_import>`_ project on GitHub.
144+
This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/16.0/account_invoice_import>`_ project on GitHub.
142145

143146
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

account_invoice_import/models/account_invoice_import_config.py

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class AccountInvoiceImportConfig(models.Model):
6969
check_company=True,
7070
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
7171
)
72+
allow_draft_invoices_same_partner = fields.Boolean(
73+
"Allow creating multiple draft invoices for the same partner"
74+
)
7275

7376
@api.depends("static_product_id", "account_id", "partner_id")
7477
def _compute_analytic_distribution(self):

account_invoice_import/static/description/index.html

+26-25
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
54
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
5+
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
76
<title>Account Invoice Import</title>
87
<style type="text/css">
98

109
/*
1110
:Author: David Goodger (goodger@python.org)
12-
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
1615
17-
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
16+
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
1918
*/
2019

@@ -366,8 +365,10 @@ <h1 class="title">Account Invoice Import</h1>
366365
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367366
!! This file is generated by oca-gen-addon-readme !!
368367
!! changes will be overwritten. !!
368+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369+
!! source digest: sha256:3ce0b15bb8408de71e1a614b16fe5e00ced8f366b5d6c78510c049eec85c304c
369370
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
370-
<p><a class="reference external" 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" 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" 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" 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" href="https://runbot.odoo-community.org/runbot/226/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
371+
<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/16.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-16-0/edi-16-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=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
371372
<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>
372373
<p>In order to reliably extract the required information from the invoice, two international standards exists to describe an Invoice in XML:</p>
373374
<ul class="simple">
@@ -389,20 +390,20 @@ <h1 class="title">Account Invoice Import</h1>
389390
<p><strong>Table of contents</strong></p>
390391
<div class="contents local topic" id="contents">
391392
<ul class="simple">
392-
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
393-
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
394-
<li><a class="reference internal" href="#known-issues-roadmap" id="id3">Known issues / Roadmap</a></li>
395-
<li><a class="reference internal" href="#bug-tracker" id="id4">Bug Tracker</a></li>
396-
<li><a class="reference internal" href="#credits" id="id5">Credits</a><ul>
397-
<li><a class="reference internal" href="#authors" id="id6">Authors</a></li>
398-
<li><a class="reference internal" href="#contributors" id="id7">Contributors</a></li>
399-
<li><a class="reference internal" href="#maintainers" id="id8">Maintainers</a></li>
393+
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
394+
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
395+
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-3">Known issues / Roadmap</a></li>
396+
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li>
397+
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a><ul>
398+
<li><a class="reference internal" href="#authors" id="toc-entry-6">Authors</a></li>
399+
<li><a class="reference internal" href="#contributors" id="toc-entry-7">Contributors</a></li>
400+
<li><a class="reference internal" href="#maintainers" id="toc-entry-8">Maintainers</a></li>
400401
</ul>
401402
</li>
402403
</ul>
403404
</div>
404405
<div class="section" id="configuration">
405-
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
406+
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
406407
<p>Go to the form view of the suppliers and configure it with the following parameters:</p>
407408
<ul class="simple">
408409
<li>Individual/Company: <em>Company</em></li>
@@ -417,7 +418,7 @@ <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
417418
</ul>
418419
</div>
419420
<div class="section" id="usage">
420-
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
421+
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
421422
<p>Go to the menu <em>Invoicing &gt; Vendors &gt; Import Vendor Bill</em> and follow the instructions of the wizard. You can also start the wizard from the <em>Accounting Dashboard</em>: on the purchase journal, click on the <em>Upload</em> button.</p>
422423
<p>This module also supports the scenario where you have a draft vendor bill (generated from a purchase order for instance) and you have to update it to comply with the real invoice sent by the vendor: on the form view of the draft vendor bill, click on the button <em>Import Invoice File</em> and follow the instructions of the wizard.</p>
423424
<p>If you have a large volume of invoices to import, you may be interested by the script <strong>mass_invoice_import.py</strong> which is available in the <em>scripts</em> subdirectory of this module. If you run:</p>
@@ -428,29 +429,29 @@ <h1><a class="toc-backref" href="#id2">Usage</a></h1>
428429
<p>A particular use case of this script is to have a directory where all the invoices saved are automatically uploaded in Odoo. For that, have a look at the sample script <strong>inotify-sample.sh</strong> available in the same subdirectory. Edit this sample script to adapt it to your needs.</p>
429430
</div>
430431
<div class="section" id="known-issues-roadmap">
431-
<h1><a class="toc-backref" href="#id3">Known issues / Roadmap</a></h1>
432+
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
432433
<ul class="simple">
433434
<li>Remove dependency on <em>base_iban</em> and develop a separate glue module between this module and <em>base_iban</em></li>
434435
</ul>
435436
</div>
436437
<div class="section" id="bug-tracker">
437-
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
438+
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
438439
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/edi/issues">GitHub Issues</a>.
439440
In case of trouble, please check there if your issue has already been reported.
440-
If you spotted it first, help us smashing it by providing a detailed and welcomed
441-
<a class="reference external" href="https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
441+
If you spotted it first, help us to smash it by providing a detailed and welcomed
442+
<a class="reference external" href="https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
442443
<p>Do not contact contributors directly about support or help with technical issues.</p>
443444
</div>
444445
<div class="section" id="credits">
445-
<h1><a class="toc-backref" href="#id5">Credits</a></h1>
446+
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
446447
<div class="section" id="authors">
447-
<h2><a class="toc-backref" href="#id6">Authors</a></h2>
448+
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
448449
<ul class="simple">
449450
<li>Akretion</li>
450451
</ul>
451452
</div>
452453
<div class="section" id="contributors">
453-
<h2><a class="toc-backref" href="#id7">Contributors</a></h2>
454+
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
454455
<ul class="simple">
455456
<li>Alexis de Lattre &lt;<a class="reference external" href="mailto:alexis.delattre&#64;akretion.com">alexis.delattre&#64;akretion.com</a>&gt;</li>
456457
<li>Andrea Stirpe &lt;<a class="reference external" href="mailto:a.stirpe&#64;onestein.nl">a.stirpe&#64;onestein.nl</a>&gt;</li>
@@ -461,15 +462,15 @@ <h2><a class="toc-backref" href="#id7">Contributors</a></h2>
461462
</ul>
462463
</div>
463464
<div class="section" id="maintainers">
464-
<h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
465+
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
465466
<p>This module is maintained by the OCA.</p>
466467
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
467468
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
468469
mission is to support the collaborative development of Odoo features and
469470
promote its widespread use.</p>
470471
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
471-
<p><a class="reference external" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a></p>
472-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/edi/tree/14.0/account_invoice_import">OCA/edi</a> project on GitHub.</p>
472+
<p><a class="reference external image-reference" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a></p>
473+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/edi/tree/16.0/account_invoice_import">OCA/edi</a> project on GitHub.</p>
473474
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
474475
</div>
475476
</div>

account_invoice_import/wizard/account_invoice_import.py

+22-15
Original file line numberDiff line numberDiff line change
@@ -810,21 +810,28 @@ def import_invoice(self):
810810
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
811811
action["res_id"] = self.id
812812
else:
813-
draft_same_supplier_invs = amo.search(
814-
[
815-
("commercial_partner_id", "=", partner.id),
816-
("move_type", "=", parsed_inv["type"]),
817-
("state", "=", "draft"),
818-
]
819-
)
820-
logger.debug("draft_same_supplier_invs=%s", draft_same_supplier_invs)
821-
if draft_same_supplier_invs:
822-
wiz_vals["state"] = "update"
823-
if len(draft_same_supplier_invs) == 1:
824-
wiz_vals["invoice_id"] = draft_same_supplier_invs[0].id
825-
xmlid = "account_invoice_import.account_invoice_import_action"
826-
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
827-
action["res_id"] = self.id
813+
if not self.import_config_id.allow_draft_invoices_same_partner:
814+
draft_same_supplier_invs = amo.search(
815+
[
816+
("commercial_partner_id", "=", partner.id),
817+
("move_type", "=", parsed_inv["type"]),
818+
("state", "=", "draft"),
819+
]
820+
)
821+
logger.debug(
822+
"draft_same_supplier_invs=%s", draft_same_supplier_invs
823+
)
824+
if draft_same_supplier_invs:
825+
wiz_vals["state"] = "update"
826+
if len(draft_same_supplier_invs) == 1:
827+
wiz_vals["invoice_id"] = draft_same_supplier_invs[0].id
828+
xmlid = "account_invoice_import.account_invoice_import_action"
829+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
830+
action["res_id"] = self.id
831+
else:
832+
action = self.create_invoice_action(
833+
parsed_inv, import_config, _("Import Vendor Bill wizard")
834+
)
828835
else:
829836
action = self.create_invoice_action(
830837
parsed_inv, import_config, _("Import Vendor Bill wizard")

0 commit comments

Comments
 (0)