-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from coopiteasy/12.0-mig-account_invoice_chec…
…k_identical_invoice [12.0][MIG] account_invoice_check_identical_invoice
- Loading branch information
Showing
10 changed files
with
585 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,56 @@ | ||
======================================= | ||
Account Invoice Check Identical Invoice | ||
======================================= | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/github-coopiteasy%2Faddons-lightgray.png?logo=github | ||
:target: https://github.com/coopiteasy/addons/tree/12.0/account_invoice_check_identical_invoice | ||
:alt: coopiteasy/addons | ||
|
||
|badge1| |badge2| | ||
|
||
This module requires to check this box to validate the invoice | ||
if invoices with the same partner, invoice date and total amount already exist. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/coopiteasy/addons/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/coopiteasy/addons/issues/new?body=module:%20account_invoice_check_identical_invoice%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Coop IT Easy SCRLfs | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Robin Keunen <[email protected]> | ||
* Vincent Van Rossem <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is part of the `coopiteasy/addons <https://github.com/coopiteasy/addons/tree/12.0/account_invoice_check_identical_invoice>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
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,15 @@ | ||
# Copyright 2017 - Today Coop IT Easy SCRLfs (<http://www.coopiteasy.be>) | ||
# - Robin Keunen <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "Account Invoice Check Identical Invoice", | ||
"summary": """ | ||
Check if invoices with the same partner, invoice date and total amount already exist""", | ||
"version": "12.0.1.0.0", | ||
"depends": ["base", "account",], | ||
"author": "Coop IT Easy SCRLfs", | ||
"category": "Accounting & Finance", | ||
"website": "https://coopiteasy.be", | ||
"data": ["views/account_invoice.xml",], | ||
"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 |
75 changes: 75 additions & 0 deletions
75
account_invoice_check_identical_invoice/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,75 @@ | ||
# Copyright 2017 - Today Coop IT Easy SCRLfs (<http://www.coopiteasy.be>) | ||
# - Robin Keunen <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import models, fields, api, _ | ||
from odoo.exceptions import ValidationError | ||
import datetime as dt | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = "account.invoice" | ||
|
||
identical_invoice_confirmed = fields.Boolean( | ||
"Confirm Identical Invoice?", | ||
default=False, | ||
copy=False, | ||
help="You need to check this box to validate the invoice if" | ||
" invoices with the same partner," | ||
" invoice date and totam alount already exist.", | ||
) | ||
identical_invoice_detected = fields.Boolean( | ||
"identical_invoice_detected", compute="_check_identical_invoice" | ||
) | ||
|
||
@api.onchange("partner_id", "date_invoice") | ||
@api.multi | ||
def _onchange_check_identical_invoice(self): | ||
self._check_identical_invoice() | ||
|
||
@api.multi | ||
def _check_identical_invoice(self): | ||
Invoice = self.env["account.invoice"] | ||
for invoice in self: | ||
duplicate_domain = [ | ||
("state", "not in", ["draft", "cancel"]), | ||
("partner_id.supplier", "=", True), | ||
("partner_id", "=", invoice.partner_id.id), | ||
] | ||
partner_invoices = Invoice.search(duplicate_domain) | ||
|
||
def equal_amount(i): | ||
return round(i.amount_total, 2) == round( | ||
invoice.amount_total, 2 | ||
) | ||
|
||
def same_date(i): | ||
return i.date_invoice == invoice.date_invoice | ||
|
||
def invoiced_today(i): | ||
return ( | ||
i.date_invoice == dt.date.today() | ||
and not invoice.date_invoice | ||
) | ||
|
||
duplicate_invoices = partner_invoices.filtered( | ||
lambda i: equal_amount(i) | ||
and (same_date(i) or invoiced_today(i)) | ||
) | ||
|
||
invoice.identical_invoice_detected = bool(duplicate_invoices) | ||
|
||
@api.multi | ||
def invoice_validate(self): | ||
self._check_identical_invoice() | ||
for invoice in self: | ||
if ( | ||
invoice.identical_invoice_detected | ||
and not invoice.identical_invoice_confirmed | ||
): | ||
raise ValidationError( | ||
"We detected invoices with the same partner, date" | ||
" and total. \n\nPlease check the" | ||
' "Confirm Identical Invoice?" box to continue' | ||
) | ||
|
||
return super(AccountInvoice, self).invoice_validate() |
2 changes: 2 additions & 0 deletions
2
account_invoice_check_identical_invoice/readme/CONTRIBUTORS.rst
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,2 @@ | ||
* Robin Keunen <[email protected]> | ||
* Vincent Van Rossem <[email protected]> |
2 changes: 2 additions & 0 deletions
2
account_invoice_check_identical_invoice/readme/DESCRIPTION.rst
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,2 @@ | ||
This module requires to check this box to validate the invoice | ||
if invoices with the same partner, invoice date and total amount already exist. |
Empty file.
Oops, something went wrong.