diff --git a/purchase_order_no_zero_price/README.rst b/purchase_order_no_zero_price/README.rst new file mode 100644 index 00000000000..246cea91d02 --- /dev/null +++ b/purchase_order_no_zero_price/README.rst @@ -0,0 +1,96 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============================ +Purchase Order No Zero Price +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4eb4147526f4d1e11825c053c153ecdc24f5f1a06d0bec22c855af18dbf34bd9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/purchase_order_no_zero_price + :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-19-0/purchase-workflow-19-0-purchase_order_no_zero_price + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Prevent zero prices on confirmed POs to help ensure proper Stock +Valuation when receiving the products. + +Also supports purchase_triple_discount module, if installed. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use: + +- Create an RFQ, and add a line with zero price. +- Confirm the RFQ, an error message will prevent that and ask you to + enter the missing prices. +- A zero subtotal line can still be entered by setting a 100% discount. + +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 +------- + +* Open Source Integrators + +Contributors +------------ + +- Daniel Reis +- Nikul Chaudhary +- Dhara Solanki +- Elliott Bristow + +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. + +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_no_zero_price/__init__.py b/purchase_order_no_zero_price/__init__.py new file mode 100644 index 00000000000..8bc7dd777ae --- /dev/null +++ b/purchase_order_no_zero_price/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/purchase_order_no_zero_price/__manifest__.py b/purchase_order_no_zero_price/__manifest__.py new file mode 100644 index 00000000000..6a0ea22961b --- /dev/null +++ b/purchase_order_no_zero_price/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright (C) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Purchase Order No Zero Price", + "version": "19.0.1.0.0", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "summary": "Prevent zero price lines on Purchase Orders", + "website": "https://github.com/OCA/purchase-workflow", + "license": "AGPL-3", + "depends": ["purchase"], + "category": "Purchase", + "data": [], + "installable": True, + "maintainer": ["dreispt"], + "development_status": "Beta", +} diff --git a/purchase_order_no_zero_price/i18n/es.po b/purchase_order_no_zero_price/i18n/es.po new file mode 100644 index 00000000000..76b19f10b7b --- /dev/null +++ b/purchase_order_no_zero_price/i18n/es.po @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_no_zero_price +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-11 17:35+0000\n" +"Last-Translator: kikopeiro \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: purchase_order_no_zero_price +#. odoo-python +#: code:addons/purchase_order_no_zero_price/models/purchase_order_line.py:0 +#, python-format +msgid "Missing unit price for Products: %s" +msgstr "Precio unitario sin establecer en los siguientes productos: %s" + +#. module: purchase_order_no_zero_price +#: model:ir.model,name:purchase_order_no_zero_price.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Linea de pedido de compra" diff --git a/purchase_order_no_zero_price/i18n/it.po b/purchase_order_no_zero_price/i18n/it.po new file mode 100644 index 00000000000..a9d71db4b44 --- /dev/null +++ b/purchase_order_no_zero_price/i18n/it.po @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_no_zero_price +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-22 19:33+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: purchase_order_no_zero_price +#. odoo-python +#: code:addons/purchase_order_no_zero_price/models/purchase_order_line.py:0 +#, python-format +msgid "Missing unit price for Products: %s" +msgstr "Prezzo unitario mancante per prodotti: %s" + +#. module: purchase_order_no_zero_price +#: model:ir.model,name:purchase_order_no_zero_price.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Riga ordine di acquisto" diff --git a/purchase_order_no_zero_price/i18n/purchase_order_no_zero_price.pot b/purchase_order_no_zero_price/i18n/purchase_order_no_zero_price.pot new file mode 100644 index 00000000000..64dee3656f0 --- /dev/null +++ b/purchase_order_no_zero_price/i18n/purchase_order_no_zero_price.pot @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_no_zero_price +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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: purchase_order_no_zero_price +#. odoo-python +#: code:addons/purchase_order_no_zero_price/models/purchase_order_line.py:0 +#, python-format +msgid "Missing unit price for Products: %s" +msgstr "" + +#. module: purchase_order_no_zero_price +#: model:ir.model,name:purchase_order_no_zero_price.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" diff --git a/purchase_order_no_zero_price/models/__init__.py b/purchase_order_no_zero_price/models/__init__.py new file mode 100644 index 00000000000..8c785a7317a --- /dev/null +++ b/purchase_order_no_zero_price/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import purchase_order_line, purchase_order diff --git a/purchase_order_no_zero_price/models/purchase_order.py b/purchase_order_no_zero_price/models/purchase_order.py new file mode 100644 index 00000000000..080c1e5c5bd --- /dev/null +++ b/purchase_order_no_zero_price/models/purchase_order.py @@ -0,0 +1,10 @@ +from odoo import models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + def button_confirm(self): + res = super().button_confirm() + self.order_line._check_price_unit_zero() + return res diff --git a/purchase_order_no_zero_price/models/purchase_order_line.py b/purchase_order_no_zero_price/models/purchase_order_line.py new file mode 100644 index 00000000000..0fa6472b57f --- /dev/null +++ b/purchase_order_no_zero_price/models/purchase_order_line.py @@ -0,0 +1,33 @@ +# Copyright (C) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, exceptions, models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + @api.constrains("price_unit", "display_type") + def _check_price_unit_zero(self): + # Prevent zero prices on confirmed POs + # to help ensure proper Stock Valuation + # when receiving the products + # Also supports `purchase_triple_discount` module + no_price_lines = self.filtered( + lambda x: ( + not x.display_type + and x.state not in ["draft", "cancel"] + and not x.price_unit + # Allow zero price for 100% discounts: + and getattr(x, "discount", 0.0) != 100.0 + and getattr(x, "discount2", 0.0) != 100.0 + and getattr(x, "discount3", 0.0) != 100.0 + ) + ) + if no_price_lines: + raise exceptions.UserError( + self.env._( + "Missing unit price for Products: %s", + ", ".join(no_price_lines.product_id.mapped("display_name")), + ) + ) diff --git a/purchase_order_no_zero_price/pyproject.toml b/purchase_order_no_zero_price/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_order_no_zero_price/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_order_no_zero_price/readme/CONTRIBUTORS.md b/purchase_order_no_zero_price/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..7d2188f8772 --- /dev/null +++ b/purchase_order_no_zero_price/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Daniel Reis \ +- Nikul Chaudhary \ +- Dhara Solanki \ +- Elliott Bristow \ diff --git a/purchase_order_no_zero_price/readme/DESCRIPTION.md b/purchase_order_no_zero_price/readme/DESCRIPTION.md new file mode 100644 index 00000000000..778d31a73f8 --- /dev/null +++ b/purchase_order_no_zero_price/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +Prevent zero prices on confirmed POs to help ensure proper Stock +Valuation when receiving the products. + +Also supports purchase_triple_discount module, if installed. diff --git a/purchase_order_no_zero_price/readme/USAGE.md b/purchase_order_no_zero_price/readme/USAGE.md new file mode 100644 index 00000000000..172049d9922 --- /dev/null +++ b/purchase_order_no_zero_price/readme/USAGE.md @@ -0,0 +1,6 @@ +To use: + +- Create an RFQ, and add a line with zero price. +- Confirm the RFQ, an error message will prevent that and ask you to + enter the missing prices. +- A zero subtotal line can still be entered by setting a 100% discount. diff --git a/purchase_order_no_zero_price/static/description/icon.png b/purchase_order_no_zero_price/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_order_no_zero_price/static/description/icon.png differ diff --git a/purchase_order_no_zero_price/static/description/index.html b/purchase_order_no_zero_price/static/description/index.html new file mode 100644 index 00000000000..1ffbb1b2099 --- /dev/null +++ b/purchase_order_no_zero_price/static/description/index.html @@ -0,0 +1,445 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Purchase Order No Zero Price

+ +

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

+

Prevent zero prices on confirmed POs to help ensure proper Stock +Valuation when receiving the products.

+

Also supports purchase_triple_discount module, if installed.

+

Table of contents

+ +
+

Usage

+

To use:

+
    +
  • Create an RFQ, and add a line with zero price.
  • +
  • Confirm the RFQ, an error message will prevent that and ask you to +enter the missing prices.
  • +
  • A zero subtotal line can still be entered by setting a 100% discount.
  • +
+
+
+

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

+
    +
  • Open Source Integrators
  • +
+
+
+

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.

+

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_no_zero_price/tests/__init__.py b/purchase_order_no_zero_price/tests/__init__.py new file mode 100644 index 00000000000..aa1442a29be --- /dev/null +++ b/purchase_order_no_zero_price/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_purchase_order_no_zero_price diff --git a/purchase_order_no_zero_price/tests/test_purchase_order_no_zero_price.py b/purchase_order_no_zero_price/tests/test_purchase_order_no_zero_price.py new file mode 100644 index 00000000000..61a3c924601 --- /dev/null +++ b/purchase_order_no_zero_price/tests/test_purchase_order_no_zero_price.py @@ -0,0 +1,61 @@ +# Copyright (C) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import time + +from odoo.exceptions import UserError +from odoo.tests import common, tagged +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT + + +@tagged("post_install", "-at_install") +class TestPurchaseOrderNoZeroPrice(common.TransactionCase): + def setUp(self): + super().setUp() + + self.PurchaseOrder = self.env["purchase.order"] + # Partner + self.partner1 = self.env["res.partner"].create({"name": "Test Partner"}) + # Products + self.product1 = self.env["product.product"].create( + { + "name": "Test Product", + "type": "consu", + "is_storable": True, + "standard_price": 10.0, + } + ) + + self.purchase_order1 = self.PurchaseOrder.create( + { + "partner_id": self.partner1.id, + "order_line": [ + ( + 0, + 0, + { + "name": self.product1.name, + "product_id": self.product1.id, + "product_qty": 50, + "product_uom_id": self.product1.uom_id.id, + "price_unit": 10.0, + "date_planned": time.strftime( + DEFAULT_SERVER_DATETIME_FORMAT + ), + }, + ) + ], + } + ) + self.purchase_order2 = self.purchase_order1.copy() + + def test_check_price_unit_zero(self): + self.assertEqual(self.purchase_order1.state, "draft") + self.purchase_order1.button_confirm() + self.assertEqual(self.purchase_order1.state, "purchase") + + self.assertEqual(self.purchase_order2.state, "draft") + with self.assertRaises(UserError), self.cr.savepoint(): + self.purchase_order2.order_line.write({"price_unit": 0.0}) + self.purchase_order2.button_confirm() + self.assertEqual(self.purchase_order2.state, "draft")