From ab680e770def3e32f88e6747240a00918c378c08 Mon Sep 17 00:00:00 2001 From: Ilyas Date: Tue, 8 Aug 2023 08:43:36 +0200 Subject: [PATCH] tests --- .../models/commission.py | 6 +---- ...sale_commission_product_criteria_domain.py | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/sale_commission_product_criteria_domain/models/commission.py b/sale_commission_product_criteria_domain/models/commission.py index 1451d9e57..901b048a9 100644 --- a/sale_commission_product_criteria_domain/models/commission.py +++ b/sale_commission_product_criteria_domain/models/commission.py @@ -156,11 +156,7 @@ def _get_single_commission_amount(self, commission, subtotal, product, quantity) if commission.commission_type not in ["product", "product_restricted"]: return self._get_commission_amount(commission, subtotal, product, quantity) item_ids = self._get_commission_items(commission, product) - partner = False - if self.object_id._name == "account.move.line": - partner = self.object_id.partner_id - elif self.object_id._name == "sale.order.line": - partner = self.object_id.order_id.partner_id + partner = self.object_id.order_id.partner_id if not partner: # if not partner or not partner.apply_commission_restrictions: return super()._get_single_commission_amount( diff --git a/sale_commission_product_criteria_domain/tests/test_sale_commission_product_criteria_domain.py b/sale_commission_product_criteria_domain/tests/test_sale_commission_product_criteria_domain.py index d1cbdc223..7e5f1cb48 100644 --- a/sale_commission_product_criteria_domain/tests/test_sale_commission_product_criteria_domain.py +++ b/sale_commission_product_criteria_domain/tests/test_sale_commission_product_criteria_domain.py @@ -11,8 +11,8 @@ def setUpClass(cls): cls.commission_model = cls.env["sale.commission"] cls.company = cls.env.ref("base.main_company") cls.res_partner_model = cls.env["res.partner"] - cls.partner = cls.env.ref("base.res_partner_12") - cls.partner2 = cls.env.ref("base.res_partner_10") + cls.partner = cls.env.ref("base.res_partner_12") # Azure + cls.partner2 = cls.env.ref("base.res_partner_10") # Deco cls.sale_order_model = cls.env["sale.order"] cls.advance_inv_model = cls.env["sale.advance.payment.inv"] cls.settle_model = cls.env["sale.commission.settlement"] @@ -25,7 +25,7 @@ def setUpClass(cls): cls.product_1.write({"invoice_policy": "order"}) cls.product_4.write({"invoice_policy": "order"}) cls.product_5.write({"invoice_policy": "order"}) - cls.product_6.write({"commission_free": True}) + cls.product_6.write({"commission_free": True, "invoice_policy": "order"}) cls.product_template_4 = cls.env.ref( "product.product_product_4_product_template" ) @@ -66,7 +66,7 @@ def test_commission_domain(self): # count related agents demo_cig_italy._compute_agents_count() - self.assertEqual(demo_cig_italy.agents_count, 1) + self.assertEqual(demo_cig_italy.agents_count, 0) # if commission is not type of restricted then CI must have no group demo_crr_item_1.commission_id = self.env.ref( @@ -116,7 +116,7 @@ def test_commission_domain(self): demo_cig_spain.unlink() # - self.env['commission.items.group'].create({'name': 'Delete Me'}).unlink() + self.env["commission.items.group"].create({"name": "Delete Me"}).unlink() # computes was modified to consider new commission type: product_restricted so = self._create_sale_order(self.product_4, self.partner) @@ -127,8 +127,20 @@ def test_commission_domain(self): so.order_line.agent_ids._compute_amount() invoice.line_ids.agent_ids._compute_amount() + self.partner.agent_ids.commission_id = self.env.ref( + "sale_commission_product_criteria.demo_commission_rules" + ).id + # computes was modified to consider new commission type: product_restricted + so = self._create_sale_order(self.product_6, self.partner) + so.recompute_lines_agents() + so.action_confirm() + invoice = self._invoice_sale_order(so) + invoice.recompute_lines_agents() + so.order_line.agent_ids._compute_amount() + invoice.line_ids.agent_ids._compute_amount() + # computes was modified to consider new commission type: product_restricted - so = self._create_sale_order(self.product_4, self.partner2) + so = self._create_sale_order(self.product_5, self.partner) so.recompute_lines_agents() so.action_confirm() invoice = self._invoice_sale_order(so)