Skip to content

Commit

Permalink
Merge PR #435 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by ilyasProgrammer
  • Loading branch information
OCA-git-bot committed Jun 27, 2023
2 parents 1aa4615 + 95711c1 commit fd092a6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
2 changes: 0 additions & 2 deletions sale_commission_product_criteria/models/commission.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ class CommissionItem(models.Model):
domain=[("commission_type", "=", "product")],
required=True,
)
use_pricelist = fields.Boolean()
pricelist_id = fields.Many2one("product.pricelist")
product_tmpl_id = fields.Many2one(
"product.template",
"Product",
Expand Down
2 changes: 0 additions & 2 deletions sale_commission_product_criteria/views/views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
/>
<field name="applied_on" widget="radio" />
<field name="based_on" invisible="1" />
<field name="use_pricelist" invisible="1" />
<field
name="categ_id"
attrs="{
Expand Down Expand Up @@ -173,7 +172,6 @@
<field name="commission_id" />
<field name="name" />
<field name="applied_on" optional="hide" />
<field name="use_pricelist" invisible="1" />
<field name="commission_value" />
<field name="based_on" />
</tree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class CommissionItem(models.Model):
discount_from = fields.Float("Discount From")
discount_to = fields.Float("Discount To")

@api.onchange("based_on")
def onchange_based_on(self):
if self.based_on != "discount":
self.update({"discount_from": 0, "discount_to": 0})

@api.constrains("discount_from", "discount_to")
def _check_discounts(self):
if any(item.discount_from > item.discount_to for item in self):
Expand Down
12 changes: 3 additions & 9 deletions sale_commission_product_criteria_discount/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def _get_single_commission_amount(self, commission, subtotal, product, quantity)
item_ids = self._get_commission_items(commission, product)
if not item_ids:
return 0.0
so_id = self.object_id.order_id
# Check discount condition
item_ids = self.env["commission.item"].browse(item_ids)
commission_item = False
for item_id in item_ids:
commission_item = self.env["commission.item"].browse(item_id)
commission_item = item_id
discount = self._get_discount_value(commission_item)
if commission_item.based_on != "sol":
if (
Expand All @@ -33,13 +33,7 @@ def _get_single_commission_amount(self, commission, subtotal, product, quantity)
):
break # suitable item found
else:
if (
commission_item.pricelist_id
and so_id.pricelist_id.id != commission_item.pricelist_id.id
):
commission_item = False # unsuitable item
else:
break # suitable item found
break # suitable item found
commission_item = False
if not commission_item:
# all commission items rejected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def setUpClass(cls):
cls.com_item_4 = cls.env.ref(
"sale_commission_product_criteria.demo_commission_rules_item_4"
)
cls.com_item_5 = cls.env.ref(
"sale_commission_product_criteria_discount.demo_commission_rules_item_disc_1"
)
cls.no_rules_commission_id = cls.env["sale.commission"].create(
{
"name": "No Rules Commission",
Expand Down Expand Up @@ -213,6 +216,13 @@ def test_sale_commission_product_criteria_items(self):
so.recompute_lines_agents()
so.order_line.agent_ids._compute_amount()
self.assertEqual(so.order_line.agent_ids.amount, 0.0)
# onchange_based_on
self.com_item_4.onchange_based_on()
self.assertEqual(self.com_item_4.discount_to, 0)
self.assertEqual(self.com_item_4.discount_from, 0)
self.com_item_5.onchange_based_on()
self.assertEqual(self.com_item_5.discount_to, 100)
self.assertEqual(self.com_item_5.discount_from, 10.01)

def _create_sale_order(self, product, partner):
return self.sale_order_model.create(
Expand Down

0 comments on commit fd092a6

Please sign in to comment.