Skip to content

Commit 6f968ca

Browse files
committed
fixup! [ADD] res_partner_product_pricelist_operating_unit
1 parent 8509d90 commit 6f968ca

7 files changed

Lines changed: 41 additions & 27 deletions

File tree

res_partner_product_pricelist_operating_unit/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Partner Product Pricelist Operating Unit
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1414
:target: https://odoo-community.org/page/development-status
1515
:alt: Beta
16-
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17-
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18-
:alt: License: LGPL-3
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
2020
:target: https://github.com/OCA/operating-unit/tree/17.0/res_partner_product_pricelist_operating_unit
2121
:alt: OCA/operating-unit

res_partner_product_pricelist_operating_unit/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Partner Product Pricelist Operating Unit",
55
"version": "17.0.1.0.0",
66
"author": "Camptocamp, Odoo Community Association (OCA)",
7-
"license": "LGPL-3",
7+
"license": "AGPL-3",
88
"website": "https://github.com/OCA/operating-unit",
99
"category": "Product",
1010
"depends": [

res_partner_product_pricelist_operating_unit/models/product_pricelist.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 2025 Camptocamp SA (https://www.camptocamp.com).
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
13
from odoo import api, models
24

35

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 2025 Camptocamp SA (https://www.camptocamp.com).
2-
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33
from odoo import _, api, models
44
from odoo.exceptions import ValidationError
55

@@ -11,11 +11,13 @@ class ResPartner(models.Model):
1111
def _compute_product_pricelist(self):
1212
return super()._compute_product_pricelist()
1313

14+
@api.constrains("operating_unit_ids", "property_product_pricelist")
1415
def _check_pricelist_operating_unit(self):
1516
for partner in self:
1617
pricelist = partner.property_product_pricelist
1718
if (
1819
pricelist
20+
and pricelist.operating_unit_id
1921
and pricelist.operating_unit_id not in partner.operating_unit_ids
2022
):
2123
raise ValidationError(
@@ -28,18 +30,7 @@ def _check_pricelist_operating_unit(self):
2830
)
2931
)
3032

31-
def write(self, vals):
32-
res = super().write(vals)
33-
# We check that both `operating_unit_ids` and `property_product_pricelist`
34-
# are in `vals` to avoid wrongly raised ValidationError
35-
if "operating_unit_ids" in vals and "property_product_pricelist" in vals:
36-
self._check_pricelist_operating_unit()
37-
return res
38-
39-
@api.model_create_multi
40-
def create(self, vals_list):
41-
partners = super().create(vals_list)
42-
for partner, vals in zip(partners, vals_list, strict=True):
43-
if "operating_unit_ids" in vals and "property_product_pricelist" in vals:
44-
partner._check_pricelist_operating_unit()
45-
return partners
33+
def _commercial_fields(self):
34+
# list of fields that are managed by the commercial entity
35+
# to which a partner belongs.
36+
return super()._commercial_fields() + ["operating_unit_ids"]

res_partner_product_pricelist_operating_unit/static/description/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h1 class="title">Partner Product Pricelist Operating Unit</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:78fb292c8f1e1718ad7edc8d1f1199839efe327922a48f467289551d4ab071b9
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
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/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--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>
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>
373373
<p>This module introduces the following features:</p>
374374
<ul class="simple">
375375
<li>Ensures that the Product Pricelist assigned to a Partner belongs to

res_partner_product_pricelist_operating_unit/tests/test_partner_pricelist_operating_unit.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ def test_00_partner_pricelist_operating_unit(self):
3838
def test_01_partner_pricelist_operating_unit(self):
3939
"""Attempt to set a pricelist from another OU"""
4040
with self.assertRaises(ValidationError) as error:
41-
self.partner1.write(
42-
{
43-
"property_product_pricelist": self.pricelist2.id,
44-
"operating_unit_ids": [(4, self.ou1.id)],
45-
}
46-
)
41+
self.partner1.property_product_pricelist = self.pricelist2.id
4742
self.assertEqual(
4843
error.exception.args[0],
4944
"Pricelist 'Product Pricelist' belongs to "

res_partner_product_pricelist_operating_unit/views/res_partner.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
3+
4+
<record id="view_partner_form" model="ir.ui.view">
5+
<field name="model">res.partner</field>
6+
<field name="inherit_id" ref="res_partner_operating_unit.view_partner_form" />
7+
<field name="arch" type="xml">
8+
<field name="operating_unit_ids" position="attributes">
9+
<attribute name="readonly">not is_company and parent_id</attribute>
10+
</field>
11+
<field name="operating_unit_ids" position="after">
12+
<div
13+
name="parent_operating_units"
14+
groups="operating_unit.group_multi_operating_unit"
15+
colspan="2"
16+
invisible="is_company or not parent_id"
17+
>
18+
<p>Operating Units are managed on <button
19+
name="open_commercial_entity"
20+
type="object"
21+
string="the parent company"
22+
class="oe_link"
23+
/></p>
24+
</div>
25+
</field>
26+
</field>
27+
</record>
28+
329
<record id="view_partner_property_form" model="ir.ui.view">
430
<field name="model">res.partner</field>
531
<field name="inherit_id" ref="product.view_partner_property_form" />

0 commit comments

Comments
 (0)