diff --git a/purchase_order_qty_change_no_zero/README.rst b/purchase_order_qty_change_no_zero/README.rst new file mode 100644 index 00000000000..43b9d402b04 --- /dev/null +++ b/purchase_order_qty_change_no_zero/README.rst @@ -0,0 +1,97 @@ +================================= +Purchase Order Qty change no zero +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:78e6ea89b38a0718bf2c811a5e70c706101c4a3d14813cf71c1b6454d74e4470 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/14.0/purchase_order_qty_change_no_zero + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-14-0/purchase-workflow-14-0-purchase_order_qty_change_no_zero + :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/purchase-workflow&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module prevent to set the unit price to zero if only quantity has changed in purchase order line. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Create a new purchase order. +#. Add product line and set custom unit price. +#. Save purchase order. +#. Edit purchase order and change quantity. +#. The unit price is the new computed price only if it is not zero. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* `Akretion `_: + + * Clément Mombereau + +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-clementmbr| image:: https://github.com/clementmbr.png?size=40px + :target: https://github.com/clementmbr + :alt: clementmbr + +Current `maintainer `__: + +|maintainer-clementmbr| + +This module is part of the `OCA/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_order_qty_change_no_zero/__init__.py b/purchase_order_qty_change_no_zero/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_order_qty_change_no_zero/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_order_qty_change_no_zero/__manifest__.py b/purchase_order_qty_change_no_zero/__manifest__.py new file mode 100644 index 00000000000..1f0a9dc6ef9 --- /dev/null +++ b/purchase_order_qty_change_no_zero/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Akretion - Clément Mombereau +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Purchase Order Qty change no zero", + "summary": "Prevent unit price to be zero when purchase order line quantity is changed", + "version": "14.0.1.0.0", + "category": "Sale Workflow", + "website": "https://github.com/OCA/purchase-workflow", + "author": "Akretion, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["purchase"], + "maintainers": ["clementmbr"], +} diff --git a/purchase_order_qty_change_no_zero/models/__init__.py b/purchase_order_qty_change_no_zero/models/__init__.py new file mode 100644 index 00000000000..9f03530643d --- /dev/null +++ b/purchase_order_qty_change_no_zero/models/__init__.py @@ -0,0 +1 @@ +from . import purchase_order diff --git a/purchase_order_qty_change_no_zero/models/purchase_order.py b/purchase_order_qty_change_no_zero/models/purchase_order.py new file mode 100644 index 00000000000..e2e594fd823 --- /dev/null +++ b/purchase_order_qty_change_no_zero/models/purchase_order.py @@ -0,0 +1,39 @@ +# Copyright 2024 Akretion - Clément Mombereau +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +# from pprint import pprint + +from odoo import models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + def onchange(self, values, field_name, field_onchange): + res = super().onchange(values, field_name, field_onchange) + # print("\n----------- in onchange") + # print("field_name") + # pprint(field_name) + # print("values+++++") + # pprint(values) + # print("field_onchange+++++") + # pprint(field_onchange) + # print("res+++++") + # pprint(res) + # print("\n") + + if "product_qty" in field_name and "value" in res: + old_price_unit = values.get("price_unit") + new_price_unit = res["value"].get("price_unit") + if old_price_unit and not new_price_unit: + res["value"].update( + { + "price_unit": old_price_unit, + # TODO : how to update price_subtotal and price_total with + # old_price_unit and new qty? + # "price_subtotal": values["price_subtotal"], + # "price_total": values["price_total"], + } + ) + + return res diff --git a/purchase_order_qty_change_no_zero/readme/CONTRIBUTORS.rst b/purchase_order_qty_change_no_zero/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..06c50c2dfc6 --- /dev/null +++ b/purchase_order_qty_change_no_zero/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Akretion `_: + + * Clément Mombereau diff --git a/purchase_order_qty_change_no_zero/readme/DESCRIPTION.rst b/purchase_order_qty_change_no_zero/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..5616e1bb976 --- /dev/null +++ b/purchase_order_qty_change_no_zero/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module prevent to set the unit price to zero if only quantity has changed in purchase order line. diff --git a/purchase_order_qty_change_no_zero/readme/USAGE.rst b/purchase_order_qty_change_no_zero/readme/USAGE.rst new file mode 100644 index 00000000000..79a9abed8fc --- /dev/null +++ b/purchase_order_qty_change_no_zero/readme/USAGE.rst @@ -0,0 +1,7 @@ +To use this module, you need to: + +#. Create a new purchase order. +#. Add product line and set custom unit price. +#. Save purchase order. +#. Edit purchase order and change quantity. +#. The unit price is the new computed price only if it is not zero. diff --git a/purchase_order_qty_change_no_zero/static/description/icon.png b/purchase_order_qty_change_no_zero/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_order_qty_change_no_zero/static/description/icon.png differ diff --git a/purchase_order_qty_change_no_zero/static/description/index.html b/purchase_order_qty_change_no_zero/static/description/index.html new file mode 100644 index 00000000000..33dfdb2c069 --- /dev/null +++ b/purchase_order_qty_change_no_zero/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +Purchase Order Qty change no zero + + + +
+

Purchase Order Qty change no zero

+ + +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

This module prevent to set the unit price to zero if only quantity has changed in purchase order line.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Create a new purchase order.
  2. +
  3. Add product line and set custom unit price.
  4. +
  5. Save purchase order.
  6. +
  7. Edit purchase order and change quantity.
  8. +
  9. The unit price is the new computed price only if it is not zero.
  10. +
+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

clementmbr

+

This module is part of the OCA/purchase-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_order_qty_change_no_zero/tests/__init__.py b/purchase_order_qty_change_no_zero/tests/__init__.py new file mode 100644 index 00000000000..36ed1d4ab96 --- /dev/null +++ b/purchase_order_qty_change_no_zero/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_order_qty_change_no_zero diff --git a/purchase_order_qty_change_no_zero/tests/test_sale_order_qty_change_no_zero.py b/purchase_order_qty_change_no_zero/tests/test_sale_order_qty_change_no_zero.py new file mode 100644 index 00000000000..9b5d7cdd2a5 --- /dev/null +++ b/purchase_order_qty_change_no_zero/tests/test_sale_order_qty_change_no_zero.py @@ -0,0 +1,42 @@ +# Copyright 2024 Akretion - Clément Mombereau +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests.common import Form, TransactionCase + + +class TestPurchaseOrderQtyChangeNoZero(TransactionCase): + def setUp(self): + super().setUp() + self.product_1 = self.env["product.product"].create( + {"name": "Test Product 1", "standard_price": 0, "taxes_id": False} + ) + self.product_2 = self.env["product.product"].create( + {"name": "Test Product 2", "standard_price": 30.00, "taxes_id": False} + ) + purchase_form = Form(self.env["purchase.order"]) + purchase_form.partner_id = self.env.ref("base.res_partner_12") + + with purchase_form.order_line.new() as self.line_form: + self.line_form.product_id = self.product_1 + self.line_form.product_qty = 1 + + def test_product_with_standard_price_zero(self): + self.line_form.price_unit = 10 + self.assertEqual(self.line_form.price_unit, 10) + self.assertEqual(self.line_form.price_subtotal, 10) + + # print("\n=== change quantity===\n") + self.line_form.product_qty = 2 + self.assertEqual(self.line_form.price_unit, 10) + self.assertEqual(self.line_form.price_subtotal, 20) + + # def test_product_with_standard_price_not_zero(self): + # self.line_form.product_id = self.product_2 + # self.line_form.product_qty = 2 + # self.assertEqual(self.line_form.price_unit, 30) + # self.assertEqual(self.line_form.price_subtotal, 60) + # self.line_form.price_unit = 10 + # self.assertEqual(self.line_form.price_unit, 10) + # self.assertEqual(self.line_form.price_subtotal, 20) + # self.line_form.product_qty = 1 + # self.assertEqual(self.line_form.price_unit, 30) + # self.assertEqual(self.line_form.price_subtotal, 30) diff --git a/setup/purchase_order_qty_change_no_zero/odoo/addons/purchase_order_qty_change_no_zero b/setup/purchase_order_qty_change_no_zero/odoo/addons/purchase_order_qty_change_no_zero new file mode 120000 index 00000000000..623ed1d3176 --- /dev/null +++ b/setup/purchase_order_qty_change_no_zero/odoo/addons/purchase_order_qty_change_no_zero @@ -0,0 +1 @@ +../../../../purchase_order_qty_change_no_zero \ No newline at end of file diff --git a/setup/purchase_order_qty_change_no_zero/setup.py b/setup/purchase_order_qty_change_no_zero/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/purchase_order_qty_change_no_zero/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)