Skip to content

Commit

Permalink
[MIG] sale_commission_pricelist: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
feketemihai committed Jul 24, 2020
1 parent 2ec56c5 commit 5b72438
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 50 deletions.
16 changes: 9 additions & 7 deletions sale_commission_pricelist/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ Sales commissions by pricelist
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcommission-lightgray.png?logo=github
:target: https://github.com/OCA/commission/tree/12.0/sale_commission_pricelist
:target: https://github.com/OCA/commission/tree/13.0/sale_commission_pricelist
:alt: OCA/commission
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/commission-12-0/commission-12-0-sale_commission_pricelist
:target: https://translation.odoo-community.org/projects/commission-13-0/commission-13-0-sale_commission_pricelist
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/165/12.0
:target: https://runbot.odoo-community.org/runbot/165/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of sale_commission to allow you set a
commission to pricelist item.
This module extends the functionality of sale_commission to allow you set a commission to pricelist item.

The commission is applied when the pricelist rule is applied, that is after changing product or quantity of sale order line.

Expand Down Expand Up @@ -54,7 +53,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/commission/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_pricelist%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_pricelist%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -73,6 +72,9 @@ Contributors
* Carlos Dauden
* Ernesto Tejeda
* Lorenzo Battistini <[email protected]>
* `NextERP Romania <https://www.nexterp.ro>`_:

* Fekete Mihai <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
19 changes: 10 additions & 9 deletions sale_commission_pricelist/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ def _get_commission_from_pricelist(self):
rule = self.env["product.pricelist.item"].browse(rule_id)
return rule.commission_id

@api.onchange("product_id", "product_uom_qty")
def _onchange_product_id_sale_commission_pricelist(self):
commission = self._get_commission_from_pricelist()
if commission:
self.agents.update({"commission": commission.id})
@api.depends("order_id.pricelist_id")
def _compute_agent_ids(self):
super(SaleOrderLine, self)._compute_agent_ids()
for record in self:
commission = record._get_commission_from_pricelist()
if record.agent_ids and commission:
record.agent_ids.update({"commission_id": commission.id})

def _prepare_agents_vals(self):
def _prepare_agent_vals(self, agent):
self.ensure_one()
res = super(SaleOrderLine, self)._prepare_agents_vals()
res = super(SaleOrderLine, self)._prepare_agent_vals(agent)
commission = self._get_commission_from_pricelist()
if commission:
for vals in res:
vals[2]["commission"] = commission.id
res["commission_id"] = commission.id
return res
3 changes: 3 additions & 0 deletions sale_commission_pricelist/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
* Carlos Dauden
* Ernesto Tejeda
* Lorenzo Battistini <[email protected]>
* `NextERP Romania <https://www.nexterp.ro>`_:

* Fekete Mihai <[email protected]>
3 changes: 1 addition & 2 deletions sale_commission_pricelist/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
This module extends the functionality of sale_commission to allow you set a
commission to pricelist item.
This module extends the functionality of sale_commission to allow you set a commission to pricelist item.

The commission is applied when the pricelist rule is applied, that is after changing product or quantity of sale order line.
41 changes: 19 additions & 22 deletions sale_commission_pricelist/tests/test_sale_commission_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def setUpClass(cls):
0,
0,
{
"name": "10% discount and commission on Test product 2",
"applied_on": "1_product",
"name": "20% discount and commission on Test " "product 2",
"applied_on": "0_product_variant",
"product_id": cls.product2.id,
"compute_price": "formula",
"base": "list_price",
Expand All @@ -45,7 +45,7 @@ def setUpClass(cls):
0,
0,
{
"name": "20% Discount and commission",
"name": "10% Discount and commission",
"compute_price": "percentage",
"base": "list_price",
"percent_price": 10,
Expand All @@ -58,14 +58,18 @@ def setUpClass(cls):
)
Partner = cls.env["res.partner"]
cls.agent = Partner.create(
{"name": "Test Agent", "agent": True, "commission": cls.commission_agent.id}
{
"name": "Test Agent",
"agent": True,
"commission_id": cls.commission_agent.id,
}
)
cls.partner = Partner.create(
{
"name": "Partner test",
"customer": True,
"supplier": False,
"agents": [(6, 0, cls.agent.ids)],
"customer_rank": 1,
"supplier_rank": 0,
"agent_ids": [(6, 0, cls.agent.ids)],
}
)
SaleOrder = cls.env["sale.order"]
Expand All @@ -76,17 +80,13 @@ def setUpClass(cls):
cls.so_line1 = SOLine.with_context(partner_id=cls.partner.id).create(
{"order_id": cls.sale_order.id, "product_id": cls.product.id}
)
for onchange_method in cls.so_line1._onchange_methods["product_id"]:
onchange_method(cls.so_line1)
cls.so_line2 = SOLine.with_context(partner_id=cls.partner.id).create(
{"order_id": cls.sale_order.id, "product_id": cls.product2.id}
)
for onchange_method in cls.so_line2._onchange_methods["product_id"]:
onchange_method(cls.so_line2)

def test_sale_commission_pricelist(self):
self.assertEqual(self.so_line1.agents[:1].commission, self.commission_1)
self.assertEqual(self.so_line2.agents[:1].commission, self.commission_2)
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)

def test_prepare_agents_vals(self):
commission_3 = self.env["sale.commission"].create(
Expand All @@ -100,8 +100,8 @@ def test_prepare_agents_vals(self):
0,
0,
{
"name": "30% discount and commission on Test product 2",
"applied_on": "1_product",
"name": "30% discount and commission on Test " "product 2",
"applied_on": "0_product_variant",
"product_id": self.product2.id,
"compute_price": "formula",
"base": "list_price",
Expand All @@ -114,10 +114,7 @@ def test_prepare_agents_vals(self):
)
# Nothing changes
self.sale_order.pricelist_id = pricelist_3
self.assertEqual(self.so_line1.agents[:1].commission, self.commission_1)
self.assertEqual(self.so_line2.agents[:1].commission, self.commission_2)
# After click on 'Recompute lines agents' button
# self.so_line1 and self.so_line1 change
self.sale_order.recompute_lines_agents()
self.assertEqual(self.so_line1.agents[:1].commission, self.commission_agent)
self.assertEqual(self.so_line2.agents[:1].commission, commission_3)
self.assertEqual(
self.so_line1.agent_ids[:1].commission_id, self.commission_agent
)
self.assertEqual(self.so_line2.agent_ids[:1].commission_id, commission_3)
11 changes: 1 addition & 10 deletions sale_commission_pricelist/views/product_pricelist_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@
<field name="model">product.pricelist</field>
<field name="inherit_id" ref="product.product_pricelist_view" />
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='price']" position="after">
<field name="commission_id" />
</xpath>
</field>
</record>
<record id="product_normal_form_view" model="ir.ui.view">
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='price']" position="after">
<xpath expr="//tree/field[@name='fixed_price']" position="after">
<field name="commission_id" />
</xpath>
</field>
Expand Down

0 comments on commit 5b72438

Please sign in to comment.