Skip to content

Commit

Permalink
[FIX] pos_pricelist_show_discount: remove fragile demo data
Browse files Browse the repository at this point in the history
Removing pricelist and pos configuration from the demo data
because it creates issues when combined with l10n modules that
modify the company's currency, due to inconsistencies in currencies.

The same demo data is now created programmatically during tests instead.
  • Loading branch information
aleuffre committed Oct 13, 2023
1 parent 239d049 commit 68f3858
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 78 deletions.
2 changes: 0 additions & 2 deletions pos_pricelist_show_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"views/pos_config_view.xml",
],
"demo": [
"demo/product_pricelist_demo.xml",
"demo/pos_config_demo.xml",
"demo/res_users_demo.xml",
],
"qweb": [
Expand Down
16 changes: 0 additions & 16 deletions pos_pricelist_show_discount/demo/pos_config_demo.xml

This file was deleted.

57 changes: 0 additions & 57 deletions pos_pricelist_show_discount/demo/product_pricelist_demo.xml

This file was deleted.

83 changes: 83 additions & 0 deletions pos_pricelist_show_discount/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class PosPricelistShowDiscountCommonSetup:
@classmethod
def create_pricelists(cls, env):
pos_pricelist = env["product.pricelist"].create(
{
"name": "Pos Pricelist",
"discount_policy": "without_discount",
"item_ids": [
(
0,
0,
{
"base": "list_price",
"applied_on": "1_product",
"product_tmpl_id": env.ref(
"product.product_delivery_01_product_template"
).id,
"fixed_price": 75.0,
},
),
(
0,
0,
{
"base": "list_price",
"applied_on": "1_product",
"product_tmpl_id": env.ref(
"product.product_product_12_product_template"
).id,
"fixed_price": 60.0,
},
),
],
}
)
drp = env["product.pricelist"].create(
{
"name": "Discount Reference Pricelist",
"item_ids": [
(
0,
0,
{
"base": "list_price",
"applied_on": "1_product",
"product_tmpl_id": env.ref(
"product.product_delivery_01_product_template"
).id,
"fixed_price": 100.0,
},
),
(
0,
0,
{
"base": "list_price",
"applied_on": "1_product",
"product_tmpl_id": env.ref(
"product.product_product_12_product_template"
).id,
"fixed_price": 100.0,
},
),
],
}
)
return pos_pricelist, drp

@classmethod
def config_pos(cls, env, pricelist, discount_pricelist):
pos_config = env.ref("point_of_sale.pos_config_main")
pos_config.write(
{
"pricelist_id": pricelist.id,
"use_pricelist": True,
"available_pricelist_ids": [
(6, 0, (pricelist + discount_pricelist).ids)
],
"display_discount_from_pricelist": True,
"discount_pricelist_id": discount_pricelist.id,
}
)
return pos_config
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from odoo.exceptions import UserError, ValidationError
from odoo.tests import Form, SavepointCase

from .common import PosPricelistShowDiscountCommonSetup

class TestPosConfigDiscountPricelist(SavepointCase):

class TestPosConfigDiscountPricelist(
SavepointCase,
PosPricelistShowDiscountCommonSetup,
):
@classmethod
def setUpClass(cls):
super().setUpClass()
main_pricelist, discount_pricelist = cls.create_pricelists(cls.env)
cls.main_pos_config = cls.config_pos(
cls.env,
main_pricelist,
discount_pricelist,
)
cls.pricelist_model = cls.env["product.pricelist"]
cls.company_model = cls.env["res.company"]
cls.USD = cls.env.ref("base.USD")
cls.main_company = cls.env.ref("base.main_company")
cls.main_pos_config = cls.env.ref("point_of_sale.pos_config_main")

def test_pos_discount_pricelist_no_change_while_open(self):
self.main_pos_config.open_session_cb(check_coa=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
from odoo.tests import HttpCase, tagged

from .common import PosPricelistShowDiscountCommonSetup


@tagged("post_install", "-at_install")
class TestPosPricelistShowDiscount(HttpCase):
class TestPosPricelistShowDiscount(
HttpCase,
PosPricelistShowDiscountCommonSetup,
):
def setUp(self):
super().setUp()
main_pricelist, discount_pricelist = self.create_pricelists(self.env)
self.main_pos_config = self.config_pos(
self.env,
main_pricelist,
discount_pricelist,
)
self.main_pos_config = self.env.ref("point_of_sale.pos_config_main")

def test_pos_discount_ref_pricelist(self):
Expand Down

0 comments on commit 68f3858

Please sign in to comment.