Skip to content

Commit

Permalink
[MIG] shopinvader_customer_price: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chafique-delli committed Feb 25, 2021
1 parent f357dc1 commit 0fa7318
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 40 deletions.
2 changes: 1 addition & 1 deletion shopinvader_customer_price/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Shopinvader Customer Price",
"summary": """Expose customer's specific prices.""",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Camptocamp,Odoo Community Association (OCA)",
"website": "https://github.com/shopinvader/odoo-shopinvader",
Expand Down
7 changes: 3 additions & 4 deletions shopinvader_customer_price/models/shopinvader_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ def _get_partner_pricelist(self, partner):

@tools.ormcache("partner.id", "self.company_id.id")
def _get_fiscal_position_id(self, partner):
fp_model = self.env["account.fiscal.position"].with_context(
force_company=self.company_id.id
)
fp_model = self.env["account.fiscal.position"].with_company(self.company_id.id)
fpos_id = fp_model.get_fiscal_position(
partner.id, delivery_id=partner.id,
partner.id,
delivery_id=partner.id,
)
return fpos_id

Expand Down
8 changes: 4 additions & 4 deletions shopinvader_customer_price/services/customer_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# @author Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.osv import expression

from odoo.addons.base_rest.components.service import to_int
from odoo.addons.component.core import Component
from odoo.osv import expression


class CustomerPriceService(Component):
"""Shopinvader service to expose customer specific product prices.
"""
"""Shopinvader service to expose customer specific product prices."""

_name = "shopinvader.customer.price.service"
_inherit = "base.shopinvader.service"
Expand Down Expand Up @@ -51,7 +51,7 @@ def _json_parser(self):

def _get_price(self, record, fname):
pricelist = self.shopinvader_backend._get_cart_pricelist(self.partner)
fposition = self.shopinvader_backend._get_fiscal_position(self.partner)
fposition = self.shopinvader_backend._get_fiscal_position_id(self.partner)
company = self.shopinvader_backend.company_id
return {
self.invader_partner.role: record._get_price(
Expand Down
4 changes: 1 addition & 3 deletions shopinvader_customer_price/tests/test_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def setUp(self):
def test_default_pricelist(self):
self.assertFalse(self.backend.cart_pricelist_partner_field_id)
cart = self.service._get()
self.assertEqual(
cart.pricelist_id, self.partner.property_product_pricelist
)
self.assertEqual(cart.pricelist_id, self.partner.property_product_pricelist)

def test_custom_pricelist(self):
self.backend.cart_pricelist_partner_field_id = self.pricelist_field
Expand Down
36 changes: 10 additions & 26 deletions shopinvader_customer_price/tests/test_customer_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def _test_response(self, res, s_variant, expected_price):

def test_get_fiscal_position(self):
self.assertEqual(
self.backend._get_fiscal_position(self.partner1), self.fiscal_pos1
self.backend._get_fiscal_position_id(self.partner1), self.fiscal_pos1
)
self.assertEqual(
self.backend._get_fiscal_position(self.partner2), self.fiscal_pos2
self.backend._get_fiscal_position_id(self.partner2), self.fiscal_pos2
)

def test_get_pricelist(self):
Expand All @@ -59,34 +59,22 @@ def test_get_price_default(self):
s_variant = self.shopinvader_variant
service = self._get_service(self.partner1)
# partner1
expected_price = s_variant._get_price(
self.base_pricelist, self.fiscal_pos1
)
res = service.dispatch(
"products", params={"ids": s_variant.ids, "one": True}
)
expected_price = s_variant._get_price(self.base_pricelist, self.fiscal_pos1)
res = service.dispatch("products", params={"ids": s_variant.ids, "one": True})
self._test_response(res, s_variant, expected_price)
# partner2
expected_price = s_variant._get_price(
self.base_pricelist, self.fiscal_pos2
)
expected_price = s_variant._get_price(self.base_pricelist, self.fiscal_pos2)
service = self._get_service(self.partner2)
res = service.dispatch(
"products", params={"ids": s_variant.ids, "one": True}
)
res = service.dispatch("products", params={"ids": s_variant.ids, "one": True})
self._test_response(res, s_variant, expected_price)

def test_get_price_custom_pricelist(self):
s_variant = self.shopinvader_variant
self.partner1.property_product_pricelist = self.discount_pricelist
# partner1
service = self._get_service(self.partner1)
res = service.dispatch(
"products", params={"ids": s_variant.ids, "one": True}
)
expected_price = s_variant._get_price(
self.discount_pricelist, self.fiscal_pos1
)
res = service.dispatch("products", params={"ids": s_variant.ids, "one": True})
expected_price = s_variant._get_price(self.discount_pricelist, self.fiscal_pos1)
self._test_response(res, s_variant, expected_price)

def test_get_price_multi(self):
Expand All @@ -98,13 +86,9 @@ def test_get_price_multi(self):
"products", params={"ids": [s_variant.id, s_variant2.id]}
)
self.assertEqual(len(res), 2)
expected_price = s_variant._get_price(
self.base_pricelist, self.fiscal_pos1
)
expected_price = s_variant._get_price(self.base_pricelist, self.fiscal_pos1)
res1 = [x for x in res if x["id"] == s_variant.id][0]
self._test_response(res1, s_variant, expected_price)
expected_price = s_variant2._get_price(
self.base_pricelist, self.fiscal_pos1
)
expected_price = s_variant2._get_price(self.base_pricelist, self.fiscal_pos1)
res2 = [x for x in res if x["id"] == s_variant2.id][0]
self._test_response(res2, s_variant2, expected_price)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="shopinvader_backend_view_form" model="ir.ui.view">
<field name="model">shopinvader.backend</field>
<field name="inherit_id" ref="shopinvader.shopinvader_backend_view_form"/>
<field name="inherit_id" ref="shopinvader.shopinvader_backend_view_form" />
<field name="arch" type="xml">
<field name="pricelist_id" position="after">
<field name="cart_pricelist_partner_field_id" />
Expand Down

0 comments on commit 0fa7318

Please sign in to comment.