Skip to content

Commit b774d2a

Browse files
committed
[ADD] module product_pricelist_filter
1 parent 2488d82 commit b774d2a

File tree

10 files changed

+225
-0
lines changed

10 files changed

+225
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
========================
2+
product_pricelist_filter
3+
========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:7a6d9356a792ca0862383aa32f1668a4c75e08b499ccce4231012b796ed8f2ec
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
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
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github
20+
:target: https://github.com/OCA/product-attribute/tree/14.0/product_form_pricelist
21+
:alt: OCA/product-attribute
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/product-attribute-14-0/product-attribute-14-0-product_form_pricelist
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=14.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allow to add a filter on product when using a global rule on pricelists
32+
33+
**Table of contents**
34+
35+
.. contents::
36+
:local:
37+
38+
Usage
39+
=====
40+
41+
To use this module:
42+
43+
#. Go to Pricelist view
44+
#. Edit the Pricelist Rules from view
45+
46+
Bug Tracker
47+
===========
48+
49+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/issues>`_.
50+
In case of trouble, please check there if your issue has already been reported.
51+
If you spotted it first, help us to smash it by providing a detailed and welcomed
52+
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_form_pricelist%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
53+
54+
Do not contact contributors directly about support or help with technical issues.
55+
56+
Credits
57+
=======
58+
59+
Authors
60+
~~~~~~~
61+
62+
* Akretion
63+
64+
Contributors
65+
~~~~~~~~~~~~
66+
67+
* Mathieu Delva <mathieu.delva@akretion.com>
68+
69+
Maintainers
70+
~~~~~~~~~~~
71+
72+
This module is maintained by the OCA.
73+
74+
.. image:: https://odoo-community.org/logo.png
75+
:alt: Odoo Community Association
76+
:target: https://odoo-community.org
77+
78+
OCA, or the Odoo Community Association, is a nonprofit organization whose
79+
mission is to support the collaborative development of Odoo features and
80+
promote its widespread use.
81+
82+
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/14.0/product_form_pricelist>`_ project on GitHub.
83+
84+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2025 Akretion (https://www.akretion.com).
2+
# @author Mathieu DELVA <mathieu.delva@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
{
6+
"name": "Pricelist Filter",
7+
"summary": "Add domain on pricelist Item",
8+
"version": "14.0.1.0.0",
9+
"category": "",
10+
"website": "https://gitlab.akretion.com/abilis-team/abilis",
11+
"author": " Akretion, Odoo Community Association (OCA)",
12+
"license": "AGPL-3",
13+
"application": False,
14+
"installable": True,
15+
"external_dependencies": {
16+
"python": [],
17+
"bin": [],
18+
},
19+
"depends": [
20+
"product",
21+
],
22+
"data": ["views/product_pricelist.xml"],
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import product_pricelist
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2025 Akretion (https://www.akretion.com).
2+
# @author Mathieu DELVA <mathieu.delva@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
from odoo import api, fields, models
5+
from odoo.tools import safe_eval
6+
7+
8+
class ProductPricelistItem(models.Model):
9+
_inherit = "product.pricelist.item"
10+
11+
filter_domain = fields.Char(
12+
string="Apply On",
13+
default="[]",
14+
help="Find matching option by document values",
15+
)
16+
17+
def _is_applicable_for(self, product, qty_in_product_uom):
18+
if self.filter_domain:
19+
domain = safe_eval.safe_eval(self.filter_domain)
20+
prd = product.filtered_domain(domain)
21+
if prd:
22+
return super()._is_applicable_for(prd, qty_in_product_uom)
23+
return super()._is_applicable_for(product, qty_in_product_uom)
24+
25+
@api.onchange("applied_on")
26+
def _onchange_applied_on(self):
27+
if self.applied_on != "3_global":
28+
self.filter_domain = ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Mathieu Delva <mathieu.delva@akretion.com>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module allow to add a filter on product when using a global rule on pricelists
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_pricelist
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2021 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <sebastien.beau@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
6+
from odoo.tests import SavepointCase
7+
8+
9+
class TestPricelist(SavepointCase):
10+
@classmethod
11+
def setUpClass(cls):
12+
super().setUpClass()
13+
cls.tmpl = cls.env["product.template"].create(
14+
{"name": "Foo", "default_code": "test_pricelist"}
15+
)
16+
cls.variant = cls.tmpl.product_variant_ids
17+
cls.public_pricelist = cls.env.ref("product.list0")
18+
19+
cls.sale_id = cls.env.ref("sale.sale_order_18")
20+
21+
def test_pricelist_filter(self):
22+
self.public_pricelist.item_ids = [
23+
(
24+
0,
25+
0,
26+
{
27+
"applied_on": "3_global",
28+
"filter_domain": "[['default_code','ilike','test']]",
29+
"fixed_price": 10,
30+
},
31+
)
32+
]
33+
34+
self.sale_id.order_line = [
35+
(
36+
0,
37+
0,
38+
{
39+
"product_id": self.variant.id,
40+
"product_uom_qty": 1,
41+
},
42+
)
43+
]
44+
order_line = self.sale_id.order_line.filtered(
45+
lambda r: r.product_id == self.variant
46+
)
47+
self.assertEqual(order_line.price_unit, 10)
48+
49+
def test_pricelist_without_filter(self):
50+
self.public_pricelist.item_ids = [(5, 0, 0)]
51+
self.sale_id.order_line = [
52+
(
53+
0,
54+
0,
55+
{
56+
"product_id": self.variant.id,
57+
"product_uom_qty": 1,
58+
},
59+
)
60+
]
61+
order_line = self.sale_id.order_line.filtered(
62+
lambda r: r.product_id == self.variant
63+
)
64+
self.assertEqual(order_line.price_unit, self.variant.lst_price)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
4+
<record id="product_pricelist_item_form_view" model="ir.ui.view">
5+
<field name="name">product.pricelist.item.form</field>
6+
<field name="model">product.pricelist.item</field>
7+
<field name="inherit_id" ref="product.product_pricelist_item_form_view" />
8+
<field name="arch" type="xml">
9+
<group name="pricelist_rule_computation" position="before">
10+
<group>
11+
<field
12+
name="filter_domain"
13+
widget="domain"
14+
options="{'model': 'product.product', 'in_dialog': True}"
15+
attrs="{'invisible': [('applied_on','!=','3_global')]}"
16+
/>
17+
</group>
18+
</group>
19+
</field>
20+
</record>
21+
</odoo>

0 commit comments

Comments
 (0)