-
-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] product_pricelist_dependency_warning
- Loading branch information
1 parent
28db8a2
commit 76eb308
Showing
18 changed files
with
985 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
============================ | ||
Pricelist Dependency Warning | ||
============================ | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:5a5575d94be502f5e6b5476f4b9fa96602f8d239f5e9cfd7b801ee7f07abe1ea | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github | ||
:target: https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_dependency_warning | ||
:alt: OCA/product-attribute | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_pricelist_dependency_warning | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
Show a warning in the pricelist when a dependency pricelist is updated. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
This module is useful in this simplified use-case: | ||
|
||
#. Create a **base** pricelist with a global price rule | ||
#. Create a **discount** pricelist with a global price rule, using a formula based on **base** and a discount. | ||
#. Change the global price rule in **base** | ||
|
||
Now the pricelist **discount** will show a warning telling you that the base price of some rules has changed. | ||
This pricelist can also be found with the filter **Base price changed** in the pricelists list. | ||
|
||
Uncheck **Base price changed** on the affected price rules to get rid of the warning. | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
The warning is only shown if depending price rules are applied on the same level (global/category/product/variant). | ||
|
||
Quantity is not considered when evaluating price rules applicability. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_pricelist_dependency_warning%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Aion Tech | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Aion Tech <https://aiontech.company/>`_: | ||
|
||
* Simone Rubino <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
.. |maintainer-SirAionTech| image:: https://github.com/SirAionTech.png?size=40px | ||
:target: https://github.com/SirAionTech | ||
:alt: SirAionTech | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-SirAionTech| | ||
|
||
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_dependency_warning>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2023 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Pricelist Dependency Warning", | ||
"summary": "Warn when a dependency pricelist is updated.", | ||
"version": "16.0.1.0.0", | ||
"author": "Aion Tech, Odoo Community Association (OCA)", | ||
"maintainers": [ | ||
"SirAionTech", | ||
], | ||
"license": "AGPL-3", | ||
"website": "https://github.com/OCA/product-attribute" | ||
"/tree/16.0/product_pricelist_dependency_warning", | ||
"category": "Product", | ||
"depends": [ | ||
"product", | ||
], | ||
"data": [ | ||
"views/product_pricelist_item_views.xml", | ||
"views/product_pricelist_views.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * product_pricelist_dependency_warning | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-11-22 09:28+0000\n" | ||
"PO-Revision-Date: 2023-11-22 09:28+0000\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: product_pricelist_dependency_warning | ||
#: model:ir.model.fields,field_description:product_pricelist_dependency_warning.field_product_pricelist_item__is_base_price_changed | ||
#: model:ir.model.fields,field_description:product_pricelist_dependency_warning.field_product_pricelist__is_base_price_changed | ||
#: model_terms:ir.ui.view,arch_db:product_pricelist_dependency_warning.product_pricelist_view_search | ||
msgid "Base price changed" | ||
msgstr "Prezzo di base cambiato" | ||
|
||
#. module: product_pricelist_dependency_warning | ||
#: model:ir.model,name:product_pricelist_dependency_warning.model_product_pricelist | ||
msgid "Pricelist" | ||
msgstr "Listino prezzi" | ||
|
||
#. module: product_pricelist_dependency_warning | ||
#: model:ir.model,name:product_pricelist_dependency_warning.model_product_pricelist_item | ||
msgid "Pricelist Rule" | ||
msgstr "Regola listino prezzi" | ||
|
||
#. module: product_pricelist_dependency_warning | ||
#: model_terms:ir.ui.view,arch_db:product_pricelist_dependency_warning.product_pricelist_view | ||
msgid "" | ||
"The base price of some Price Rules is changed,\n" | ||
" please review them and uncheck the \"Base price changed\" flag\n" | ||
" to remove this warning" | ||
msgstr "" | ||
"Il prezzo di base è cambiato per alcune Regole tariffarie,\n" | ||
" revisionarle e deselezionare \"Prezzo di base cambiato\"\n" | ||
" per rimuovere questo messaggio" | ||
|
||
#. module: product_pricelist_dependency_warning | ||
#: model:ir.model.fields,help:product_pricelist_dependency_warning.field_product_pricelist__is_base_price_changed | ||
msgid "The base price of some price rules is changed." | ||
msgstr "Il prezzo di base è cambiato per alcune Regole tariffarie." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import product_pricelist | ||
from . import product_pricelist_item |
25 changes: 25 additions & 0 deletions
25
product_pricelist_dependency_warning/models/product_pricelist.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2023 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class ProductPricelist(models.Model): | ||
_inherit = "product.pricelist" | ||
|
||
is_base_price_changed = fields.Boolean( | ||
compute="_compute_is_base_price_changed", | ||
store=True, | ||
string="Base price changed", | ||
help="The base price of some price rules is changed.", | ||
) | ||
|
||
@api.depends( | ||
"item_ids.is_base_price_changed", | ||
) | ||
def _compute_is_base_price_changed(self): | ||
for pricelist in self: | ||
lines_base_price_changed = pricelist.item_ids.mapped( | ||
"is_base_price_changed" | ||
) | ||
pricelist.is_base_price_changed = any(lines_base_price_changed) |
92 changes: 92 additions & 0 deletions
92
product_pricelist_dependency_warning/models/product_pricelist_item.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Copyright 2023 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProductPricelistItem(models.Model): | ||
_inherit = "product.pricelist.item" | ||
|
||
is_base_price_changed = fields.Boolean( | ||
string="Base price changed", | ||
) | ||
|
||
def _has_same_product_applicability(self, item): | ||
"""Return True iff `self` and `item` have the same applicability. | ||
This is not considering quantity applicability but only global/category/product/variant. | ||
This is not considering included categories and such, but only exact matches. | ||
""" | ||
if not self and not item: | ||
same_applicability = True | ||
elif not self or not item: | ||
same_applicability = False | ||
else: | ||
self.ensure_one() | ||
item.ensure_one() | ||
applied_on = self.applied_on | ||
if applied_on != item.applied_on: | ||
same_applicability = False | ||
else: | ||
same_applicability = ( | ||
# Same global | ||
applied_on == "3_global" | ||
or ( | ||
# Same category | ||
applied_on == "2_product_category" | ||
and self.categ_id == item.categ_id | ||
) | ||
or ( | ||
# Same product | ||
applied_on == "1_product" | ||
and self.product_tmpl_id == item.product_tmpl_id | ||
) | ||
or ( | ||
# Same variant | ||
applied_on == "0_product_variant" | ||
and self.product_id == item.product_id | ||
) | ||
) | ||
return same_applicability | ||
|
||
def _get_same_applicability_depending_items(self): | ||
"""Get rules depending on the pricelist of `self` that have the same applicability.""" | ||
# Group base price rules by their base pricelist | ||
base_pricelist_items = self.search( | ||
[ | ||
("base", "=", "pricelist"), | ||
] | ||
) | ||
base_pricelist_to_items = {} | ||
for base_pricelist_item in base_pricelist_items: | ||
base_pricelist = base_pricelist_item.base_pricelist_id | ||
existing_items = base_pricelist_to_items.get(base_pricelist, self.browse()) | ||
if not existing_items: | ||
base_pricelist_to_items[base_pricelist] = base_pricelist_item | ||
else: | ||
base_pricelist_to_items[base_pricelist] |= base_pricelist_item | ||
|
||
# Find rules having same applicability | ||
same_applicability_depending_items = self.browse() | ||
for changed_item in self: | ||
changed_pricelist = changed_item.pricelist_id | ||
depending_items = base_pricelist_to_items.get( | ||
changed_pricelist, | ||
self.browse(), | ||
) | ||
for depending_item in depending_items: | ||
if changed_item._has_same_product_applicability(depending_item): | ||
same_applicability_depending_items |= depending_item | ||
return same_applicability_depending_items | ||
|
||
def write(self, vals): | ||
result = super().write(vals) | ||
same_applicability_depending_items = ( | ||
self._get_same_applicability_depending_items() | ||
) | ||
same_applicability_depending_items.update( | ||
{ | ||
"is_base_price_changed": True, | ||
} | ||
) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `Aion Tech <https://aiontech.company/>`_: | ||
|
||
* Simone Rubino <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Show a warning in the pricelist when a dependency pricelist is updated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The warning is only shown if depending price rules are applied on the same level (global/category/product/variant). | ||
|
||
Quantity is not considered when evaluating price rules applicability. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This module is useful in this simplified use-case: | ||
|
||
#. Create a **base** pricelist with a global price rule | ||
#. Create a **discount** pricelist with a global price rule, using a formula based on **base** and a discount. | ||
#. Change the global price rule in **base** | ||
|
||
Now the pricelist **discount** will show a warning telling you that the base price of some rules has changed. | ||
This pricelist can also be found with the filter **Base price changed** in the pricelists list. | ||
|
||
Uncheck **Base price changed** on the affected price rules to get rid of the warning. |
Oops, something went wrong.