|
| 1 | +from odoo import Command |
1 | 2 | from odoo.exceptions import ValidationError |
| 3 | +from odoo.tests import common |
2 | 4 |
|
3 | | -from odoo.addons.product_pricelist_operating_unit.tests.test_product_pricelist_operating_unit import ( # noqa: E501 |
4 | | - TestProductPricelistOperatingUnit, |
5 | | -) |
6 | | -from odoo.addons.res_partner_operating_unit.tests.test_res_partner_operating_unit import ( # noqa: E501 |
7 | | - TestResPartnerOperatingUnit, |
8 | | -) |
9 | 5 |
|
10 | | - |
11 | | -class TestPartnerPricelistOperatingUnit( |
12 | | - TestResPartnerOperatingUnit, TestProductPricelistOperatingUnit |
13 | | -): |
| 6 | +class TestPartnerPricelistOperatingUnit(common.TransactionCase): |
14 | 7 | @classmethod |
15 | 8 | def setUpClass(cls): |
16 | 9 | super().setUpClass() |
17 | | - # Partners already created in `TestResPartnerOperatingUnit` class: |
18 | | - # - cls.partner1: |
19 | | - # {"name": "Test Partner 1", "operating_unit_ids": [cls.ou1]} |
20 | | - # - cls.partner2: |
21 | | - # {"name": "Test Partner 2", "operating_unit_ids": [cls.b2c]} |
22 | | - |
23 | | - # Pricelists already created in `TestProductPricelistOperatingUnit` class: |
24 | | - # - cls.pricelist1: |
25 | | - # {"name": "Product Pricelist", "operating_unit_id": cls.ou1} |
26 | | - # - cls.pricelist2: |
27 | | - # {"name": "Product Pricelist", "operating_unit_id": cls.b2c} |
28 | | - |
| 10 | + cls.env = cls.env( |
| 11 | + context=dict(cls.env.context, tracking_disable=True, no_reset_password=True) |
| 12 | + ) |
| 13 | + cls.res_users_model = cls.env["res.users"] |
| 14 | + cls.product_pricelist_model = cls.env["product.pricelist"] |
| 15 | + # Company |
| 16 | + cls.company = cls.env.ref("base.main_company") |
| 17 | + # Main Operating Unit |
| 18 | + cls.ou1 = cls.env.ref("operating_unit.main_operating_unit") |
| 19 | + # B2C Operating Unit |
| 20 | + cls.b2c = cls.env.ref("operating_unit.b2c_operating_unit") |
| 21 | + # Groups |
| 22 | + cls.grp_ou_system = cls.env.ref("base.group_system") |
| 23 | + cls.grp_ou_multi = cls.env.ref("operating_unit.group_multi_operating_unit") |
| 24 | + # Create Partner 1 with Main OU |
| 25 | + cls.partner1 = cls._create_partner("Test Partner 1", cls.ou1) |
| 26 | + # Create Partner 2 with B2C OU |
| 27 | + cls.partner2 = cls._create_partner("Test Partner 2", cls.b2c) |
| 28 | + # Create User 1 with Main OU |
| 29 | + cls.user_3 = cls._create_user( |
| 30 | + "user_3", cls.grp_ou_system, cls.company, [cls.ou1] |
| 31 | + ) |
| 32 | + cls.user_3.write({"groups_id": [Command.link(cls.grp_ou_multi.id)]}) |
| 33 | + # Create User 2 with B2C OU |
| 34 | + cls.user_4 = cls._create_user( |
| 35 | + "user_4", cls.grp_ou_system, cls.company, [cls.b2c] |
| 36 | + ) |
| 37 | + cls.user_4.write({"groups_id": [Command.link(cls.grp_ou_multi.id)]}) |
| 38 | + # Create Product Pricelists |
| 39 | + cls.pricelist1 = cls._create_product_pricelist(cls.user_3, cls.ou1) |
| 40 | + cls.pricelist2 = cls._create_product_pricelist(cls.user_4, cls.b2c) |
29 | 41 | # Link Pricelists to Partners |
30 | 42 | cls.partner1.property_product_pricelist = cls.pricelist1 |
31 | 43 | cls.partner2.property_product_pricelist = cls.pricelist2 |
32 | 44 |
|
| 45 | + @classmethod |
| 46 | + def _create_partner(cls, name, operating_units): |
| 47 | + """Create a partner.""" |
| 48 | + partner = cls.env["res.partner"].create( |
| 49 | + { |
| 50 | + "name": name, |
| 51 | + "operating_unit_ids": [Command.link(ou.id) for ou in operating_units], |
| 52 | + } |
| 53 | + ) |
| 54 | + return partner |
| 55 | + |
| 56 | + @classmethod |
| 57 | + def _create_user(cls, login, group, company, operating_units, context=None): |
| 58 | + """Create a user.""" |
| 59 | + user = cls.res_users_model.create( |
| 60 | + { |
| 61 | + "name": "Test User", |
| 62 | + "login": login, |
| 63 | + "password": "demo", |
| 64 | + "email": "test@yourcompany.com", |
| 65 | + "company_id": company.id, |
| 66 | + "company_ids": [Command.link(company.id)], |
| 67 | + "operating_unit_ids": [Command.link(ou.id) for ou in operating_units], |
| 68 | + "groups_id": [Command.link(group.id)], |
| 69 | + } |
| 70 | + ) |
| 71 | + return user |
| 72 | + |
33 | 73 | def test_00_partner_pricelist_operating_unit(self): |
34 | 74 | """Partners have correct pricelist within same OU""" |
35 | 75 | self.assertEqual(self.partner1.property_product_pricelist, self.pricelist1) |
|
0 commit comments