diff --git a/sale_product_approval_purchase/README.rst b/sale_product_approval_purchase/README.rst new file mode 100644 index 000000000000..cab6127f41c0 --- /dev/null +++ b/sale_product_approval_purchase/README.rst @@ -0,0 +1,114 @@ +================================ +Purchase Order Approval Workflow +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:83ed6597bcff5d34f8a8c1fb75578b65f2d75910965bd285dcaa2bdafe863e08 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/17.0/sale_product_approval_purchase + :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-17-0/sale-workflow-17-0-sale_product_approval_purchase + :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/sale-workflow&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the purchase related settings to products and the +product states then control whether or not the product can be purchased. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +- The product states are configured to allow/block workflows for the + purchase order. +- The product is configured via check boxes. +- The 'Can be' check boxes are readonly and controlled by the state + configuration boxes and set accordingly based on the product state + settings. + +Usage +===== + +- A User will not be able to manually add a product that is not in an + approved state for PO. +- If a product is moved to a state where the 'Approved to be Purchased' + is not set, then the purchase order will show an exception: +- If a user tries clicks the 'Confirm Order' button, then a warning + shows informing the user that there is an exception. + +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 +------------ + +- `Open Source Integrators `__. + + - Chandresh Thakkar + - Daniel Reis + - Patrick Wilson + +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-dreispt| image:: https://github.com/dreispt.png?size=40px + :target: https://github.com/dreispt + :alt: dreispt + +Current `maintainer `__: + +|maintainer-dreispt| + +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_product_approval_purchase/__init__.py b/sale_product_approval_purchase/__init__.py new file mode 100644 index 000000000000..c68fd2bbe954 --- /dev/null +++ b/sale_product_approval_purchase/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/sale_product_approval_purchase/__manifest__.py b/sale_product_approval_purchase/__manifest__.py new file mode 100644 index 000000000000..6e1d5fb78647 --- /dev/null +++ b/sale_product_approval_purchase/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Purchase Order Approval Workflow", + "summary": "Purchase Order Product Apploval Workflow", + "version": "17.0.1.0.0", + "website": "https://github.com/OCA/sale-workflow", + "category": "Products", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "maintainers": ["dreispt"], + "development_status": "Alpha", + "depends": ["purchase", "sale_product_approval"], + "data": [ + "views/product_state.xml", + "views/product_template.xml", + "views/purchase_order.xml", + "views/product_exception.xml", + ], +} diff --git a/sale_product_approval_purchase/models/__init__.py b/sale_product_approval_purchase/models/__init__.py new file mode 100644 index 000000000000..e68766189d46 --- /dev/null +++ b/sale_product_approval_purchase/models/__init__.py @@ -0,0 +1,6 @@ +# Copyright 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import product_state +from . import product_template +from . import purchase_order diff --git a/sale_product_approval_purchase/models/product_state.py b/sale_product_approval_purchase/models/product_state.py new file mode 100644 index 000000000000..fea9d70a4af9 --- /dev/null +++ b/sale_product_approval_purchase/models/product_state.py @@ -0,0 +1,10 @@ +# Copyright 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductState(models.Model): + _inherit = "product.state" + + approved_purchase = fields.Boolean(string="Approved to be Purchased", default=True) diff --git a/sale_product_approval_purchase/models/product_template.py b/sale_product_approval_purchase/models/product_template.py new file mode 100644 index 000000000000..9423d5b8c446 --- /dev/null +++ b/sale_product_approval_purchase/models/product_template.py @@ -0,0 +1,48 @@ +# Copyright 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + purchase_ok = fields.Boolean( + string="Can be Purchased", + copy=False, + readonly=True, + ) + candidate_purchase = fields.Boolean(string="Candidate to Purchase") + + @api.model + def create(self, vals): + new = super().create(vals) + new._set_purchase_ok() + return new + + def write(self, vals): + res = super().write(vals) + if "product_state_id" in vals or "candidate_purchase" in vals: + self._set_purchase_ok() + return res + + def _set_purchase_ok(self): + for product in self: + if product.product_state_id: + product.purchase_ok = ( + product.candidate_purchase + and product.product_state_id.approved_purchase + ) + if not product.purchase_ok: + order_ids = ( + self.env["purchase.order.line"] + .search( + [ + ("product_id", "in", product.product_variant_ids.ids), + ("state", "in", ["draft", "sent", "to approve"]), + ("approved_purchase", "=", True), + ] + ) + .mapped("order_id") + ) + order_ids._log_exception_activity_purchase(product) diff --git a/sale_product_approval_purchase/models/purchase_order.py b/sale_product_approval_purchase/models/purchase_order.py new file mode 100644 index 000000000000..fdb1c39573ad --- /dev/null +++ b/sale_product_approval_purchase/models/purchase_order.py @@ -0,0 +1,68 @@ +# Copyright 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import date + +from odoo import SUPERUSER_ID, _, api, fields, models +from odoo.exceptions import UserError + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + approved_purchase = fields.Boolean( + related="product_id.purchase_ok", + string="Approved for Purchase", + store=True, + default=True, + ) + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + exceptions_purchase_approval = fields.Boolean( + compute="_compute_exceptions", string="Exception", default=False + ) + override_exception = fields.Boolean(default=False) + + @api.depends("order_line.approved_purchase") + def _compute_exceptions(self): + self.exceptions_purchase_approval = any( + not line.approved_purchase for line in self.order_line + ) + + def _log_exception_activity_purchase(self, product_id): + for order in self: + note = self._render_product_state_excep(order, product_id) + order.activity_schedule( + "mail.mail_activity_data_warning", + date.today(), + note=note, + user_id=order.user_id.id or SUPERUSER_ID, + ) + + def _render_product_state_excep(self, order, product_id): + values = {"purchase_order_ref": order, "product_ref": product_id} + return self.env["ir.ui.view"]._render_template( + template=self.env.ref( + "sale_product_approval_purchase.exception_on_product" + ).id, + values=values, + ) + + def button_confirm(self): + res = super(PurchaseOrder, self).button_confirm() + for purchase in self: + if ( + purchase.exceptions_purchase_approval + and not purchase.override_exception + and not self._context.get("override_ex") + ): + raise UserError( + _( + "You can not confirm this purchase order " + "because some products are not purchasable in this order." + ) + ) + return res diff --git a/sale_product_approval_purchase/pyproject.toml b/sale_product_approval_purchase/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/sale_product_approval_purchase/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_product_approval_purchase/readme/CONFIGURE.md b/sale_product_approval_purchase/readme/CONFIGURE.md new file mode 100644 index 000000000000..cdf4bcefa2d9 --- /dev/null +++ b/sale_product_approval_purchase/readme/CONFIGURE.md @@ -0,0 +1,6 @@ +- The product states are configured to allow/block workflows for the + purchase order. +- The product is configured via check boxes. +- The 'Can be' check boxes are readonly and controlled by the state + configuration boxes and set accordingly based on the product state + settings. diff --git a/sale_product_approval_purchase/readme/CONTRIBUTORS.md b/sale_product_approval_purchase/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..72eb5ca221ff --- /dev/null +++ b/sale_product_approval_purchase/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [Open Source Integrators](https://opensourceintegrators.com). + - Chandresh Thakkar \<\> + - Daniel Reis \<\> + - Patrick Wilson \<\> diff --git a/sale_product_approval_purchase/readme/DESCRIPTION.md b/sale_product_approval_purchase/readme/DESCRIPTION.md new file mode 100644 index 000000000000..959fe4f42887 --- /dev/null +++ b/sale_product_approval_purchase/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module adds the purchase related settings to products and the +product states then control whether or not the product can be purchased. diff --git a/sale_product_approval_purchase/readme/USAGE.md b/sale_product_approval_purchase/readme/USAGE.md new file mode 100644 index 000000000000..aba3ff62f438 --- /dev/null +++ b/sale_product_approval_purchase/readme/USAGE.md @@ -0,0 +1,6 @@ +- A User will not be able to manually add a product that is not in an + approved state for PO. +- If a product is moved to a state where the 'Approved to be Purchased' + is not set, then the purchase order will show an exception: +- If a user tries clicks the 'Confirm Order' button, then a warning + shows informing the user that there is an exception. diff --git a/sale_product_approval_purchase/static/description/index.html b/sale_product_approval_purchase/static/description/index.html new file mode 100644 index 000000000000..c16905483d58 --- /dev/null +++ b/sale_product_approval_purchase/static/description/index.html @@ -0,0 +1,458 @@ + + + + + +Purchase Order Approval Workflow + + + +
+

Purchase Order Approval Workflow

+ + +

Alpha License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

This module adds the purchase related settings to products and the +product states then control whether or not the product can be purchased.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+
    +
  • The product states are configured to allow/block workflows for the +purchase order.
  • +
  • The product is configured via check boxes.
  • +
  • The ‘Can be’ check boxes are readonly and controlled by the state +configuration boxes and set accordingly based on the product state +settings.
  • +
+
+
+

Usage

+
    +
  • A User will not be able to manually add a product that is not in an +approved state for PO.
  • +
  • If a product is moved to a state where the ‘Approved to be Purchased’ +is not set, then the purchase order will show an exception:
  • +
  • If a user tries clicks the ‘Confirm Order’ button, then a warning +shows informing the user that there is an exception.
  • +
+
+
+

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
  • +
+
+ +
+

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:

+

dreispt

+

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_product_approval_purchase/views/product_exception.xml b/sale_product_approval_purchase/views/product_exception.xml new file mode 100644 index 000000000000..cb8124f42858 --- /dev/null +++ b/sale_product_approval_purchase/views/product_exception.xml @@ -0,0 +1,31 @@ + + + + + diff --git a/sale_product_approval_purchase/views/product_state.xml b/sale_product_approval_purchase/views/product_state.xml new file mode 100644 index 000000000000..81e0186408b6 --- /dev/null +++ b/sale_product_approval_purchase/views/product_state.xml @@ -0,0 +1,17 @@ + + + + product_state_form_view_inherit_purchase + product.state + + +
+
+ +
+
+
+
+ +
diff --git a/sale_product_approval_purchase/views/product_template.xml b/sale_product_approval_purchase/views/product_template.xml new file mode 100644 index 000000000000..c970b9a94d11 --- /dev/null +++ b/sale_product_approval_purchase/views/product_template.xml @@ -0,0 +1,41 @@ + + + + product_template_form_view_inherit_purchase + product.template + + + + + + + + + + not candidate_purchase + + + + + + product_template_form_view_inherit_purchase_button + product.template + + + + + + + diff --git a/sale_product_approval_purchase/views/purchase_order.xml b/sale_product_approval_purchase/views/purchase_order.xml new file mode 100644 index 000000000000..26cf072c0fd7 --- /dev/null +++ b/sale_product_approval_purchase/views/purchase_order.xml @@ -0,0 +1,36 @@ + + + + purchase_order_line_form_view_inherit + purchase.order + + + +