From d3e1b7d8a3bcd564b7a82b03fd70e650c94f6ba2 Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Tue, 13 Jul 2021 17:41:11 +0200 Subject: [PATCH] [FIX] ai_check_identical_invoice: check on invoice type --- .../models/account_invoice.py | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/account_invoice_check_identical_invoice/models/account_invoice.py b/account_invoice_check_identical_invoice/models/account_invoice.py index 0b81f5bc7..a7fac0635 100644 --- a/account_invoice_check_identical_invoice/models/account_invoice.py +++ b/account_invoice_check_identical_invoice/models/account_invoice.py @@ -16,27 +16,23 @@ class AccountInvoice(models.Model): 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.", + " invoice date and total amount already exist.", ) identical_invoice_detected = fields.Boolean( "identical_invoice_detected", compute="_compute_identical_invoice" ) - @api.onchange("partner_id", "date_invoice") - @api.multi - def _onchange_compute_identical_invoice(self): - self._compute_identical_invoice() - @api.multi + @api.depends("partner_id", "date_invoice", "amount_total") def _compute_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) + partner_invoices = self.env["account.invoice"].search( + [ + ("state", "not in", ["draft", "cancel"]), + ("type", "=", "in_invoice"), + ("partner_id", "=", invoice.partner_id.id), + ] + ) def equal_amount(i): return round(i.amount_total, 2) == round( @@ -61,7 +57,6 @@ def invoiced_today(i): @api.multi def invoice_validate(self): - self._compute_identical_invoice() for invoice in self: if ( invoice.identical_invoice_detected