Skip to content

Commit

Permalink
Merge pull request #100 from coopiteasy/12.0-mig-account_invoice_chec…
Browse files Browse the repository at this point in the history
…k_identical_invoice

[12.0][MIG] account_invoice_check_identical_invoice
  • Loading branch information
remytms authored Jun 25, 2020
2 parents ede6dda + 6eab462 commit 365b2d8
Show file tree
Hide file tree
Showing 10 changed files with 585 additions and 0 deletions.
56 changes: 56 additions & 0 deletions account_invoice_check_identical_invoice/README.rst
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.
1 change: 1 addition & 0 deletions account_invoice_check_identical_invoice/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions account_invoice_check_identical_invoice/__manifest__.py
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,
}
1 change: 1 addition & 0 deletions account_invoice_check_identical_invoice/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_invoice
75 changes: 75 additions & 0 deletions account_invoice_check_identical_invoice/models/account_invoice.py
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Robin Keunen <[email protected]>
* Vincent Van Rossem <[email protected]>
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.
Loading

0 comments on commit 365b2d8

Please sign in to comment.