From 80d617876c222e5496f2fdbe492d33637c5f1884 Mon Sep 17 00:00:00 2001 From: Vincent Van Rossem Date: Mon, 28 Sep 2020 10:17:17 +0200 Subject: [PATCH] [IMP] beesdoo_account: check if user has group AND amount is < 0 --- beesdoo_account/models/account_invoice.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/beesdoo_account/models/account_invoice.py b/beesdoo_account/models/account_invoice.py index 886cfa5..237fc00 100644 --- a/beesdoo_account/models/account_invoice.py +++ b/beesdoo_account/models/account_invoice.py @@ -1,4 +1,5 @@ from odoo import api, fields, models, _ +from odoo.tools import float_compare from odoo.exceptions import UserError @@ -7,16 +8,23 @@ class AccountInvoice(models.Model): @api.multi def action_invoice_open(self): + to_open_invoices = self.filtered(lambda inv: inv.state != "open") if self.user_has_groups( "beesdoo_account." "group_validate_invoice_negative_total_amount" + ) and to_open_invoices.filtered( + lambda inv: float_compare( + inv.amount_total, + 0.0, + precision_rounding=inv.currency_id.rounding, + ) + == -1 ): - return self.action_invoice_negative_amount_open() + return self.action_invoice_negative_amount_open(to_open_invoices) return super(AccountInvoice, self).action_invoice_open() @api.multi - def action_invoice_negative_amount_open(self): - """Identical to action_invoice_open without UserError on an invoice with a negative total amount""" - to_open_invoices = self.filtered(lambda inv: inv.state != "open") + def action_invoice_negative_amount_open(self, to_open_invoices): + """Similar to action_invoice_open without UserError on an invoice with a negative total amount""" if to_open_invoices.filtered(lambda inv: not inv.partner_id): raise UserError( _(