diff --git a/recurring_consignment/models/account_move_line.py b/recurring_consignment/models/account_move_line.py index c742b30f..caaf729d 100644 --- a/recurring_consignment/models/account_move_line.py +++ b/recurring_consignment/models/account_move_line.py @@ -2,7 +2,8 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import fields, models +from odoo import _, api, fields, models +from odoo.exceptions import UserError class AccountMoveLine(models.Model): @@ -16,3 +17,18 @@ class AccountMoveLine(models.Model): ) consignment_commission = fields.Float(string="Consignment Commission Rate") + + @api.constrains("consignment_invoice_id") + def _check_consignment_invoice_id(self): + for line in self.filtered(lambda x: x.consignment_invoice_id): + if line.account_id != line.consignment_invoice_id.account_id: + raise UserError( + _( + "You try to create a commission invoice for the account %s," + " with lines with account %s." + ) + % ( + line.account_id.display_name, + line.consignment_invoice_id.account_id.display_name, + ) + ) diff --git a/recurring_consignment/views/view_account_invoice.xml b/recurring_consignment/views/view_account_invoice.xml index 33920ad8..c5ecf187 100644 --- a/recurring_consignment/views/view_account_invoice.xml +++ b/recurring_consignment/views/view_account_invoice.xml @@ -25,8 +25,11 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - - + + + + + diff --git a/recurring_consignment/wizards/invoice_commission_wizard.py b/recurring_consignment/wizards/invoice_commission_wizard.py index 82db2550..4b79365e 100644 --- a/recurring_consignment/wizards/invoice_commission_wizard.py +++ b/recurring_consignment/wizards/invoice_commission_wizard.py @@ -67,10 +67,9 @@ def invoice_commission(self): move_AccountMoveLine = self.env["account.move.line"] AccountInvoice = self.env["account.invoice"] invoice_ids = [] - grouped_data = {} for wizard_line in self.wizard_line_ids: - + grouped_data = {} if not wizard_line.move_line_qty: continue