-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[11.0][ADD]account_supplier_invoice_check_duplicates
- Loading branch information
1 parent
f141e1c
commit 88083f7
Showing
7 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
:target: https://www.gnu.org/licenses/agpl | ||
:alt: License: AGPL-3 | ||
|
||
==================================== | ||
Supplier Invoices - Check duplicates | ||
==================================== | ||
|
||
This module adds logic to prevent entering two times the same supplier invoice. | ||
|
||
By default a duplicate is detected when there is already an open or paid invoice | ||
with | ||
|
||
- same supplier | ||
- same supplier invoice number | ||
|
||
In case no supplier invoice number has been encoded extra checks are added to detect duplicates : | ||
|
||
- same date | ||
- same amount | ||
|
||
This logic can be customized via the _get_dup_domain method. | ||
|
||
The duplicate checking can be bypassed via the 'Force Encoding' flag. | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
- Align this module with the OCA 'account_invoice_supplier_ref_unique' module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2009-2019 Noviat. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Supplier Invoice - Check Duplicates', | ||
'version': '11.0.1.0.0', | ||
'category': 'Accounting & Finance', | ||
'website': 'https://www.noviat.com', | ||
'author': 'Noviat', | ||
'license': 'AGPL-3', | ||
'complexity': 'normal', | ||
'summary': 'Supplier Invoice - Check Duplicates', | ||
'data': [ | ||
'views/account_invoice_views.xml', | ||
], | ||
'depends': [ | ||
'account_supplier_invoice_number', | ||
], | ||
'excludes': [ | ||
'account_invoice_supplier_ref_unique', | ||
], | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import account_invoice |
69 changes: 69 additions & 0 deletions
69
account_supplier_invoice_check_duplicates/models/account_invoice.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright 2009-2019 Noviat. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models, _ | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = 'account.invoice' | ||
|
||
force_encoding = fields.Boolean( | ||
string='Force Encoding', | ||
readonly=True, states={'draft': [('readonly', False)]}, | ||
help="Accept the encoding of this invoice although " | ||
"it looks like a duplicate.") | ||
|
||
def _check_duplicate_supplier_reference(self): | ||
""" | ||
Replace the standard addons _check_duplicate_supplier_reference | ||
since this one is too restrictive (blocking) for certain use cases. | ||
""" | ||
for invoice in self: | ||
if invoice.type in ('in_invoice', 'in_refund') \ | ||
and not invoice.force_encoding: | ||
invoice._check_si_duplicate() | ||
|
||
def _get_dup_domain(self): | ||
""" | ||
Override this method to customize customer specific | ||
duplicate check query. | ||
""" | ||
return [ | ||
('type', '=', self.type), | ||
('commercial_partner_id', '=', self.commercial_partner_id.id), | ||
('state', 'in', ['open', 'paid']), | ||
('company_id', '=', self.company_id.id), | ||
('id', '!=', self.id)] | ||
|
||
def _get_dup_domain_extra(self): | ||
""" | ||
Extra search term to detect duplicates in case no | ||
supplier_invoice_number has been specified. | ||
""" | ||
return [('date_invoice', '=', self.date_invoice), | ||
('amount_total', '=', self.amount_total)] | ||
|
||
def _get_dup(self): | ||
""" | ||
Override this method to customize customer specific | ||
duplicate check logic | ||
""" | ||
# find duplicates by date, amount | ||
domain = self._get_dup_domain() | ||
# add supplier invoice number | ||
if self.supplier_invoice_number: | ||
dom_dups = domain + [ | ||
('supplier_invoice_number', 'ilike', | ||
self.supplier_invoice_number)] | ||
else: | ||
dom_dups = domain + self._get_dup_domain_extra() | ||
return self.search(dom_dups) | ||
|
||
def _check_si_duplicate(self): | ||
dups = self._get_dup() | ||
if dups: | ||
raise UserError(_( | ||
"This Supplier Invoice has already been encoded !" | ||
"\nDuplicate Invoice: %s") | ||
% ', '.join([x.number for x in dups])) |
Binary file added
BIN
+17.1 KB
account_supplier_invoice_check_duplicates/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
account_supplier_invoice_check_duplicates/views/account_invoice_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="invoice_supplier_form" model="ir.ui.view"> | ||
<field name="name">account.invoice.supplier.form.inherit</field> | ||
<field name="model">account.invoice</field> | ||
<field name="inherit_id" ref="account.invoice_supplier_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="date_due" position="after"> | ||
<field name="force_encoding"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |