Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyasProgrammer committed Aug 8, 2023
1 parent 7f91dfc commit ab680e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 1 addition & 5 deletions sale_commission_product_criteria_domain/models/commission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit ab680e7

Please sign in to comment.