-
-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] sale_commission_pricelist: Migration to 17.0
- Loading branch information
1 parent
ce142ac
commit 8efe850
Showing
4 changed files
with
46 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
# Copyright 2018 Carlos Dauden - Tecnativa <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests.common import SavepointCase | ||
from odoo.tests.common import Form | ||
|
||
from odoo.addons.account_commission.tests.test_account_commission import ( | ||
TestAccountCommission, | ||
) | ||
|
||
class TestSaleCommissionPricelist(SavepointCase): | ||
|
||
class TestSaleCommissionPricelist(TestAccountCommission): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.product = cls.env["product.product"].create( | ||
{"name": "Test Product 1", "list_price": 100} | ||
) | ||
cls.product2 = cls.env["product.product"].create( | ||
{"name": "Test Product 2", "list_price": 200} | ||
) | ||
SaleCommission = cls.env["sale.commission"] | ||
cls.commission_agent = SaleCommission.create( | ||
{"name": "0.5% commission", "fix_qty": 0.5} | ||
) | ||
cls.commission_1 = SaleCommission.create( | ||
{"name": "1% commission", "fix_qty": 1.0} | ||
) | ||
cls.commission_2 = SaleCommission.create( | ||
{"name": "2% commission", "fix_qty": 2.0} | ||
) | ||
cls.sale_order_model = cls.env["sale.order"] | ||
cls.pricelist = cls.env["product.pricelist"].create( | ||
{ | ||
"name": "Test commission pricelist", | ||
|
@@ -34,11 +23,11 @@ def setUpClass(cls): | |
{ | ||
"name": "20% discount and commission on Test " "product 2", | ||
"applied_on": "0_product_variant", | ||
"product_id": cls.product2.id, | ||
"product_id": cls.product.id, | ||
"compute_price": "formula", | ||
"base": "list_price", | ||
"price_discount": 20, | ||
"commission_id": cls.commission_2.id, | ||
"commission_id": cls.commission_section_paid.id, | ||
}, | ||
), | ||
( | ||
|
@@ -50,46 +39,48 @@ def setUpClass(cls): | |
"base": "list_price", | ||
"percent_price": 10, | ||
"applied_on": "3_global", | ||
"commission_id": cls.commission_1.id, | ||
"commission_id": cls.commission_section_invoice.id, | ||
}, | ||
), | ||
], | ||
} | ||
) | ||
Partner = cls.env["res.partner"] | ||
cls.agent = Partner.create( | ||
{ | ||
"name": "Test Agent", | ||
"agent": True, | ||
"commission_id": cls.commission_agent.id, | ||
} | ||
) | ||
cls.partner = Partner.create( | ||
cls.product2 = cls.env["product.product"].create( | ||
{ | ||
"name": "Partner test", | ||
"customer_rank": 1, | ||
"supplier_rank": 0, | ||
"agent_ids": [(6, 0, cls.agent.ids)], | ||
"name": "Test product2 for commissions", | ||
"list_price": 5, | ||
} | ||
) | ||
SaleOrder = cls.env["sale.order"] | ||
cls.sale_order = SaleOrder.create( | ||
{"partner_id": cls.partner.id, "pricelist_id": cls.pricelist.id} | ||
) | ||
SOLine = cls.env["sale.order.line"] | ||
cls.so_line1 = SOLine.with_context(partner_id=cls.partner.id).create( | ||
{"order_id": cls.sale_order.id, "product_id": cls.product.id} | ||
) | ||
cls.so_line2 = SOLine.with_context(partner_id=cls.partner.id).create( | ||
{"order_id": cls.sale_order.id, "product_id": cls.product2.id} | ||
) | ||
cls.agent = cls.env.ref("commission.res_partner_pritesh_sale_agent") | ||
cls.partner.agent_ids = [(6, 0, cls.agent.ids)] | ||
|
||
def _create_sale_order(self): | ||
order_form = Form(self.sale_order_model) | ||
order_form.partner_id = self.partner | ||
order_form.pricelist_id = self.pricelist | ||
with order_form.order_line.new() as line_form: | ||
line_form.product_id = self.product | ||
|
||
with order_form.order_line.new() as line_form: | ||
line_form.product_id = self.product2 | ||
|
||
order = order_form.save() | ||
|
||
return order | ||
|
||
def test_sale_commission_pricelist(self): | ||
self.assertEqual(self.so_line1.agent_ids[:1].commission_id, self.commission_1) | ||
self.assertEqual(self.so_line2.agent_ids[:1].commission_id, self.commission_2) | ||
sale_order = self._create_sale_order() | ||
self.assertEqual( | ||
sale_order.order_line[0].agent_ids[:1].commission_id, | ||
self.commission_section_paid, | ||
) | ||
self.assertEqual( | ||
sale_order.order_line[1].agent_ids[:1].commission_id, | ||
self.commission_section_invoice, | ||
) | ||
|
||
def test_prepare_agents_vals(self): | ||
commission_3 = self.env["sale.commission"].create( | ||
commission_3 = self.env["commission"].create( | ||
{"name": "3% commission", "fix_qty": 3.0} | ||
) | ||
pricelist_3 = self.env["product.pricelist"].create( | ||
|
@@ -113,8 +104,8 @@ def test_prepare_agents_vals(self): | |
} | ||
) | ||
# Nothing changes | ||
self.sale_order.pricelist_id = pricelist_3 | ||
sale_order = self._create_sale_order() | ||
sale_order.pricelist_id = pricelist_3 | ||
self.assertEqual( | ||
self.so_line1.agent_ids[:1].commission_id, self.commission_agent | ||
sale_order.order_line[1].agent_ids[:1].commission_id, commission_3 | ||
) | ||
self.assertEqual(self.so_line2.agent_ids[:1].commission_id, commission_3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters