diff --git a/sale_order_qty_change_no_recompute/README.rst b/sale_order_qty_change_no_recompute/README.rst index 18abe11df53d..3d968cec6760 100644 --- a/sale_order_qty_change_no_recompute/README.rst +++ b/sale_order_qty_change_no_recompute/README.rst @@ -14,18 +14,23 @@ Sale Order Qty change no recompute :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github - :target: https://github.com/OCA/sale-workflow/tree/15.0/sale_order_qty_change_no_recompute + :target: https://github.com/OCA/sale-workflow/tree/16.0/sale_order_qty_change_no_recompute :alt: OCA/sale-workflow .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_order_qty_change_no_recompute + :target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_order_qty_change_no_recompute :alt: Translate me on Weblate -.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/167/15.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/sale-workflow&target_branch=16.0 + :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| -This module prevent recompute if only quantity has changed in sale order line. +A lot of business don't set different prices according the quantity of the product to +sell, and they see very annoying to set a manual price after the negotiation with the +customer, and see it changed when they vary the demanded quantity. + +This module prevents this avoiding the recomputation of the price unit, discount and +pricelist item fields if only the quantity has been changed in the sales order line. **Table of contents** @@ -42,13 +47,19 @@ To use this module, you need to: #. Save sale order. #. Edit sale order and change quantity (custom unit price not been reset). +Known issues / Roadmap +====================== + +- Having this module installed may alter test results of other modules + expecting to have the price fields recomputed when changing quantities. + Bug Tracker =========== Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -90,6 +101,6 @@ Current `maintainer `__: |maintainer-victoralmau| -This module is part of the `OCA/sale-workflow `_ project on GitHub. +This module is part of the `OCA/sale-workflow `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_order_qty_change_no_recompute/__init__.py b/sale_order_qty_change_no_recompute/__init__.py index 31660d6a9650..2f9bbd06fdd1 100644 --- a/sale_order_qty_change_no_recompute/__init__.py +++ b/sale_order_qty_change_no_recompute/__init__.py @@ -1,3 +1,3 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from . import models +from . import monkeypatching diff --git a/sale_order_qty_change_no_recompute/__manifest__.py b/sale_order_qty_change_no_recompute/__manifest__.py index 7df2bc4087b4..72210cac88b4 100644 --- a/sale_order_qty_change_no_recompute/__manifest__.py +++ b/sale_order_qty_change_no_recompute/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Sale Order Qty change no recompute", "summary": "Prevent recompute if only quantity has changed in sale order line", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Sale Workflow", "website": "https://github.com/OCA/sale-workflow", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/sale_order_qty_change_no_recompute/i18n/sale_order_qty_change_no_recompute.pot b/sale_order_qty_change_no_recompute/i18n/sale_order_qty_change_no_recompute.pot index 6bbf7ef1391e..645603dd25a7 100644 --- a/sale_order_qty_change_no_recompute/i18n/sale_order_qty_change_no_recompute.pot +++ b/sale_order_qty_change_no_recompute/i18n/sale_order_qty_change_no_recompute.pot @@ -12,8 +12,3 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" - -#. module: sale_order_qty_change_no_recompute -#: model:ir.model,name:sale_order_qty_change_no_recompute.model_sale_order_line -msgid "Sales Order Line" -msgstr "" diff --git a/sale_order_qty_change_no_recompute/models/__init__.py b/sale_order_qty_change_no_recompute/models/__init__.py deleted file mode 100644 index cbd69320b05b..000000000000 --- a/sale_order_qty_change_no_recompute/models/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from . import sale_order diff --git a/sale_order_qty_change_no_recompute/models/sale_order.py b/sale_order_qty_change_no_recompute/models/sale_order.py deleted file mode 100644 index c9d471dc7153..000000000000 --- a/sale_order_qty_change_no_recompute/models/sale_order.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2021 Tecnativa - Víctor Martínez -# Copyright 2021 Tecnativa - Pedro M. Baeza -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import models -from odoo.tools import config - - -class SaleOrderLine(models.Model): - _inherit = "sale.order.line" - - def _onchange_eval(self, field_name, onchange, result): - """Remove the trigger for the undesired onchange method with this field. - - We have to act at this place, as `_onchange_methods` is defined as a - property, and thus it can't be inherited due to the conflict of - inheritance between Python and Odoo ORM, so we can consider this as a HACK. - """ - ctx = self.env.context - if field_name in {"product_uom_qty", "product_uom"} and ( - not config["test_enable"] - or (config["test_enable"] and ctx.get("prevent_onchange_quantity", False)) - ): - cls = type(self) - for method in self._onchange_methods.get(field_name, ()): - if method == cls.product_uom_change: - self._onchange_methods[field_name].remove(method) - break - return super()._onchange_eval(field_name, onchange, result) diff --git a/sale_order_qty_change_no_recompute/monkeypatching.py b/sale_order_qty_change_no_recompute/monkeypatching.py new file mode 100644 index 000000000000..d800f77d8804 --- /dev/null +++ b/sale_order_qty_change_no_recompute/monkeypatching.py @@ -0,0 +1,25 @@ +# Copyright 2023 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.fields import Field + +get_depends_original = Field.get_depends + + +def get_depends(self, model): + """Override of the Python method to remove the dependency of the unit fields.""" + depends, depends_context = get_depends_original(self, model) + if model._name == "sale.order.line" and self.name in { + "price_unit", + "discount", + "pricelist_item_id", + }: + if "product_uom_qty" in depends: + depends.remove("product_uom_qty") + if "product_uom" in depends: + depends.remove("product_uom") + return depends, depends_context + + +# Monkey-patching of the method +Field.get_depends = get_depends diff --git a/sale_order_qty_change_no_recompute/readme/DESCRIPTION.rst b/sale_order_qty_change_no_recompute/readme/DESCRIPTION.rst index d9446c434ad8..8f9632db4813 100644 --- a/sale_order_qty_change_no_recompute/readme/DESCRIPTION.rst +++ b/sale_order_qty_change_no_recompute/readme/DESCRIPTION.rst @@ -1 +1,6 @@ -This module prevent recompute if only quantity has changed in sale order line. +A lot of business don't set different prices according the quantity of the product to +sell, and they see very annoying to set a manual price after the negotiation with the +customer, and see it changed when they vary the demanded quantity. + +This module prevents this avoiding the recomputation of the price unit, discount and +pricelist item fields if only the quantity has been changed in the sales order line. diff --git a/sale_order_qty_change_no_recompute/readme/ROADMAP.rst b/sale_order_qty_change_no_recompute/readme/ROADMAP.rst new file mode 100644 index 000000000000..54135d7c7dd5 --- /dev/null +++ b/sale_order_qty_change_no_recompute/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +- Having this module installed may alter test results of other modules + expecting to have the price fields recomputed when changing quantities. diff --git a/sale_order_qty_change_no_recompute/static/description/index.html b/sale_order_qty_change_no_recompute/static/description/index.html index b54e7bd29f55..508df1f9a863 100644 --- a/sale_order_qty_change_no_recompute/static/description/index.html +++ b/sale_order_qty_change_no_recompute/static/description/index.html @@ -3,7 +3,7 @@ - + Sale Order Qty change no recompute