From 69c9058d4b2a4be8ce1960926b03843e85bcaedd Mon Sep 17 00:00:00 2001 From: PicchiSeba Date: Tue, 15 Oct 2024 15:08:44 +0200 Subject: [PATCH] [FIX]sale_commission_product_criteria: ignore error on create --- .../models/commission.py | 2 ++ .../test_sale_commission_product_criteria.py | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/sale_commission_product_criteria/models/commission.py b/sale_commission_product_criteria/models/commission.py index b43e87979..4cd64481e 100644 --- a/sale_commission_product_criteria/models/commission.py +++ b/sale_commission_product_criteria/models/commission.py @@ -45,6 +45,8 @@ def check_type_change_allowed_sale(self): ) def check_type_change_allowed_moves(self): + if not self._origin: + return aila_ids = self.env["account.invoice.line.agent"].search( [("commission_id", "=", self._origin.id)] ) diff --git a/sale_commission_product_criteria/tests/test_sale_commission_product_criteria.py b/sale_commission_product_criteria/tests/test_sale_commission_product_criteria.py index 128e6118e..00462846c 100644 --- a/sale_commission_product_criteria/tests/test_sale_commission_product_criteria.py +++ b/sale_commission_product_criteria/tests/test_sale_commission_product_criteria.py @@ -3,7 +3,7 @@ from odoo.exceptions import ValidationError -from odoo.tests.common import SavepointCase +from odoo.tests.common import Form, SavepointCase class TestSaleCommission(SavepointCase): @@ -198,3 +198,19 @@ def _invoice_sale_order(self, sale_order, date=None): invoice = sale_order.invoice_ids - old_invoices invoice.flush() return invoice + + def test_on_create_check(self): + f = Form(self.commission_model) + f.name = "New commission type" + f.save() + + so = self._create_sale_order(self.product_4, self.partner) + self.assertEqual( + so.order_line.agent_ids.commission_id, self.rules_commission_id + ) + self.assertEqual(self.rules_commission_id.commission_type, "product") + + so.action_confirm() + with self.assertRaises(ValidationError): + self.rules_commission_id.commission_type = "fixed" + self.rules_commission_id.onchange_commission_type()