Skip to content

Commit 39d6a6f

Browse files
committed
fixup! [FIX] res_partner_operating_unit: operating_unit_ids group negation
1 parent 3bf1e37 commit 39d6a6f

3 files changed

Lines changed: 91 additions & 41 deletions

File tree

res_partner_product_pricelist_operating_unit/README.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
15
========================================
26
Partner Product Pricelist Operating Unit
37
========================================
@@ -13,7 +17,7 @@ Partner Product Pricelist Operating Unit
1317
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1418
:target: https://odoo-community.org/page/development-status
1519
:alt: Beta
16-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
1721
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1822
:alt: License: AGPL-3
1923
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
@@ -30,12 +34,12 @@ Partner Product Pricelist Operating Unit
3034

3135
This module introduces the following features:
3236

33-
- Ensures that the Product Pricelist assigned to a Partner belongs to
34-
one of the Partner's Operating Units (OUs).
35-
- Adds a constraint to prevent assigning a Pricelist from an
36-
unauthorized Operating Unit.
37-
- Filters the Pricelists in the Partner form based on the Partner's
38-
Operating Units.
37+
- Ensures that the Product Pricelist assigned to a Partner belongs to
38+
one of the Partner's Operating Units (OUs).
39+
- Adds a constraint to prevent assigning a Pricelist from an
40+
unauthorized Operating Unit.
41+
- Filters the Pricelists in the Partner form based on the Partner's
42+
Operating Units.
3943

4044
**Table of contents**
4145

@@ -45,7 +49,7 @@ This module introduces the following features:
4549
Usage
4650
=====
4751

48-
- Add a Pricelist to the Customer
52+
- Add a Pricelist to the Customer
4953

5054
Bug Tracker
5155
===========
@@ -68,7 +72,7 @@ Authors
6872
Contributors
6973
------------
7074

71-
- Vincent Van Rossem <vincent.vanrossem@camptocamp.com>
75+
- Vincent Van Rossem <vincent.vanrossem@camptocamp.com>
7276

7377
Maintainers
7478
-----------

res_partner_product_pricelist_operating_unit/static/description/index.html

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>Partner Product Pricelist Operating Unit</title>
6+
<title>README.rst</title>
77
<style type="text/css">
88

99
/*
@@ -360,16 +360,21 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document" id="partner-product-pricelist-operating-unit">
364-
<h1 class="title">Partner Product Pricelist Operating Unit</h1>
363+
<div class="document">
365364

365+
366+
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367+
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368+
</a>
369+
<div class="section" id="partner-product-pricelist-operating-unit">
370+
<h1>Partner Product Pricelist Operating Unit</h1>
366371
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367372
!! This file is generated by oca-gen-addon-readme !!
368373
!! changes will be overwritten. !!
369374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370375
!! source digest: sha256:78fb292c8f1e1718ad7edc8d1f1199839efe327922a48f467289551d4ab071b9
371376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/17.0/res_partner_product_pricelist_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/operating-unit-17-0/operating-unit-17-0-res_partner_product_pricelist_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/17.0/res_partner_product_pricelist_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/operating-unit-17-0/operating-unit-17-0-res_partner_product_pricelist_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373378
<p>This module introduces the following features:</p>
374379
<ul class="simple">
375380
<li>Ensures that the Product Pricelist assigned to a Partner belongs to
@@ -393,35 +398,35 @@ <h1 class="title">Partner Product Pricelist Operating Unit</h1>
393398
</ul>
394399
</div>
395400
<div class="section" id="usage">
396-
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
401+
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
397402
<ul class="simple">
398403
<li>Add a Pricelist to the Customer</li>
399404
</ul>
400405
</div>
401406
<div class="section" id="bug-tracker">
402-
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
407+
<h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
403408
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/operating-unit/issues">GitHub Issues</a>.
404409
In case of trouble, please check there if your issue has already been reported.
405410
If you spotted it first, help us to smash it by providing a detailed and welcomed
406411
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20res_partner_product_pricelist_operating_unit%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
407412
<p>Do not contact contributors directly about support or help with technical issues.</p>
408413
</div>
409414
<div class="section" id="credits">
410-
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
415+
<h2><a class="toc-backref" href="#toc-entry-3">Credits</a></h2>
411416
<div class="section" id="authors">
412-
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
417+
<h3><a class="toc-backref" href="#toc-entry-4">Authors</a></h3>
413418
<ul class="simple">
414419
<li>Camptocamp</li>
415420
</ul>
416421
</div>
417422
<div class="section" id="contributors">
418-
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
423+
<h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
419424
<ul class="simple">
420425
<li>Vincent Van Rossem &lt;<a class="reference external" href="mailto:vincent.vanrossem&#64;camptocamp.com">vincent.vanrossem&#64;camptocamp.com</a>&gt;</li>
421426
</ul>
422427
</div>
423428
<div class="section" id="maintainers">
424-
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
429+
<h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
425430
<p>This module is maintained by the OCA.</p>
426431
<a class="reference external image-reference" href="https://odoo-community.org">
427432
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -434,5 +439,6 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
434439
</div>
435440
</div>
436441
</div>
442+
</div>
437443
</body>
438444
</html>

res_partner_product_pricelist_operating_unit/tests/test_partner_pricelist_operating_unit.py

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,75 @@
1+
from odoo import Command
12
from odoo.exceptions import ValidationError
3+
from odoo.tests import common
24

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-
)
95

10-
11-
class TestPartnerPricelistOperatingUnit(
12-
TestResPartnerOperatingUnit, TestProductPricelistOperatingUnit
13-
):
6+
class TestPartnerPricelistOperatingUnit(common.TransactionCase):
147
@classmethod
158
def setUpClass(cls):
169
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)
2941
# Link Pricelists to Partners
3042
cls.partner1.property_product_pricelist = cls.pricelist1
3143
cls.partner2.property_product_pricelist = cls.pricelist2
3244

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+
3373
def test_00_partner_pricelist_operating_unit(self):
3474
"""Partners have correct pricelist within same OU"""
3575
self.assertEqual(self.partner1.property_product_pricelist, self.pricelist1)

0 commit comments

Comments
 (0)