diff --git a/sale_order_approval_block/README.rst b/sale_order_approval_block/README.rst new file mode 100644 index 00000000000..575b8fd1e57 --- /dev/null +++ b/sale_order_approval_block/README.rst @@ -0,0 +1,85 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +========================= +Sale Order Approval Block +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:00866fd230bf28cbdee4973f95d7a710b5e1a7df2a50afc6b72ab54d87311e6e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/19.0/sale_order_approval_block + :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-19-0/sale-workflow-19-0-sale_order_approval_block + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Adds an approval block mechanism to Sale Orders, allowing them to be +blocked with a specific reason until explicitly released. + +Blocked orders cannot be confirmed until the block is removed. + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* ForgeFlow + +Contributors +------------ + +- `ForgeFlow `__ + + - Aaron Henriquez aaron.henriquez@forgeflow.com + +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/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_approval_block/__init__.py b/sale_order_approval_block/__init__.py new file mode 100644 index 00000000000..aee8895e7a3 --- /dev/null +++ b/sale_order_approval_block/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/sale_order_approval_block/__manifest__.py b/sale_order_approval_block/__manifest__.py new file mode 100644 index 00000000000..0f6b356de52 --- /dev/null +++ b/sale_order_approval_block/__manifest__.py @@ -0,0 +1,19 @@ +{ + "name": "Sale Order Approval Block", + "version": "19.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/sale-workflow", + "summary": "Block sale orders with approval reasons", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": [ + "sale_exception", + ], + "data": [ + "security/ir.model.access.csv", + "security/sale_order_approval_block_security.xml", + "data/sale_exception_data.xml", + "views/sale_approval_block_reason_view.xml", + "views/sale_order_view.xml", + ], +} diff --git a/sale_order_approval_block/data/sale_exception_data.xml b/sale_order_approval_block/data/sale_exception_data.xml new file mode 100644 index 00000000000..661abe612fb --- /dev/null +++ b/sale_order_approval_block/data/sale_exception_data.xml @@ -0,0 +1,14 @@ + + + + Approval Blocked + The approval has been blocked, + with a Blocking reason. + 100 + sale.order + if 'approval_block_id' in self._fields and self.approval_block_id: failed = True + + + diff --git a/sale_order_approval_block/models/__init__.py b/sale_order_approval_block/models/__init__.py new file mode 100644 index 00000000000..67a256def38 --- /dev/null +++ b/sale_order_approval_block/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_approval_block_reason +from . import sale_order diff --git a/sale_order_approval_block/models/sale_approval_block_reason.py b/sale_order_approval_block/models/sale_approval_block_reason.py new file mode 100644 index 00000000000..be28fb8bf71 --- /dev/null +++ b/sale_order_approval_block/models/sale_approval_block_reason.py @@ -0,0 +1,10 @@ +from odoo import fields, models + + +class SaleApprovalBlockReason(models.Model): + _name = "sale.approval.block.reason" + _description = "Sale Approval Block Reason" + + name = fields.Char(required=True) + description = fields.Text() + active = fields.Boolean(default=True) diff --git a/sale_order_approval_block/models/sale_order.py b/sale_order_approval_block/models/sale_order.py new file mode 100644 index 00000000000..4d1e21cb1ef --- /dev/null +++ b/sale_order_approval_block/models/sale_order.py @@ -0,0 +1,63 @@ +from odoo import api, fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + approval_block_id = fields.Many2one( + comodel_name="sale.approval.block.reason", + string="Approval Block Reason", + ) + approval_blocked = fields.Boolean( + compute="_compute_approval_blocked", + ) + + @api.depends("approval_block_id") + def _compute_approval_blocked(self): + for rec in self: + rec.approval_blocked = bool(rec.approval_block_id) + + @api.model_create_multi + def create(self, vals_list): + records = super().create(vals_list) + for vals, so in zip(vals_list, records, strict=False): + if vals.get("approval_block_id"): + so.message_post( + body=self.env._( + 'Order "%(order)s" blocked with reason "%(reason)s"', + order=so.name, + reason=so.approval_block_id.name, + ) + ) + return records + + def write(self, vals): + res = super().write(vals) + for so in self: + if vals.get("approval_block_id"): + so.message_post( + body=self.env._( + 'Order "%(order)s" blocked with reason "%(reason)s"', + order=so.name, + reason=so.approval_block_id.name, + ) + ) + elif "approval_block_id" in vals and not vals["approval_block_id"]: + so.message_post( + body=self.env._( + 'Order "%(order)s" approval block released.', + order=so.name, + ) + ) + return res + + def button_approve(self, force=False): + for rec in self: + if rec.approval_block_id: + rec.button_release_approval_block() + return super().button_approve(force=force) + + def button_release_approval_block(self): + for order in self: + order.approval_block_id = False + return True diff --git a/sale_order_approval_block/pyproject.toml b/sale_order_approval_block/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_order_approval_block/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_order_approval_block/readme/CONTRIBUTORS.md b/sale_order_approval_block/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..ec68773f316 --- /dev/null +++ b/sale_order_approval_block/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [ForgeFlow](https://www.forgeflow.com) + - Aaron Henriquez diff --git a/sale_order_approval_block/readme/DESCRIPTION.md b/sale_order_approval_block/readme/DESCRIPTION.md new file mode 100644 index 00000000000..73345db800d --- /dev/null +++ b/sale_order_approval_block/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +Adds an approval block mechanism to Sale Orders, allowing them to be +blocked with a specific reason until explicitly released. + +Blocked orders cannot be confirmed until the block is removed. diff --git a/sale_order_approval_block/security/ir.model.access.csv b/sale_order_approval_block/security/ir.model.access.csv new file mode 100644 index 00000000000..c35580299dc --- /dev/null +++ b/sale_order_approval_block/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_order_approval_block_reason,sale.order.block.reason,model_sale_approval_block_reason,sales_team.group_sale_salesman,1,0,0,0 +access_sale_order_approval_block_reason_manager,sale.order.block.reason,model_sale_approval_block_reason,sales_team.group_sale_manager,1,1,1,1 diff --git a/sale_order_approval_block/security/sale_order_approval_block_security.xml b/sale_order_approval_block/security/sale_order_approval_block_security.xml new file mode 100644 index 00000000000..797f05a3f93 --- /dev/null +++ b/sale_order_approval_block/security/sale_order_approval_block_security.xml @@ -0,0 +1,13 @@ + + + + Release Quote with approval block + + + + + + diff --git a/sale_order_approval_block/static/description/index.html b/sale_order_approval_block/static/description/index.html new file mode 100644 index 00000000000..420f62a5c1e --- /dev/null +++ b/sale_order_approval_block/static/description/index.html @@ -0,0 +1,434 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Sale Order Approval Block

+ +

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

+

Adds an approval block mechanism to Sale Orders, allowing them to be +blocked with a specific reason until explicitly released.

+

Blocked orders cannot be confirmed until the block is removed.

+

Table of contents

+ +
+

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

+
    +
  • ForgeFlow
  • +
+
+ +
+

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/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_approval_block/tests/__init__.py b/sale_order_approval_block/tests/__init__.py new file mode 100644 index 00000000000..60705234cb3 --- /dev/null +++ b/sale_order_approval_block/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_sale_order_approval_block +from . import test_sale_approval_block_reason diff --git a/sale_order_approval_block/tests/test_sale_approval_block_reason.py b/sale_order_approval_block/tests/test_sale_approval_block_reason.py new file mode 100644 index 00000000000..41b98015141 --- /dev/null +++ b/sale_order_approval_block/tests/test_sale_approval_block_reason.py @@ -0,0 +1,39 @@ +from .test_sale_order_approval_block import TestSaleOrderApprovalBlock + + +class TestSoApprovalBlockReason(TestSaleOrderApprovalBlock): + def test_so_approval_block_manual_release(self): + sale = self._create_sale( + [(self.product1, 1), (self.product2, 5), (self.product3, 8)] + ) + + sale.approval_block_id = self.so_approval_block_reason.id + self.assertTrue(sale.approval_blocked) + + sale.with_user(self.user2_id).button_release_approval_block() + self.assertFalse(sale.approval_block_id) + + sale.with_user(self.user1_id).action_confirm() + self.assertEqual(sale.state, "sale") + + def test_so_approval_block_release_via_wizard(self): + sale = self._create_sale( + [(self.product1, 1), (self.product2, 5), (self.product3, 8)] + ) + + sale.approval_block_id = self.so_approval_block_reason.id + sale.with_user(self.user2_id).action_confirm() + self.assertEqual(sale.state, "draft") + + wizard = ( + self.env["sale.exception.confirm"] + .with_context( + active_id=sale.id, + active_ids=[sale.id], + active_model=sale._name, + ) + .create({"ignore": True}) + ) + wizard.action_confirm() + + self.assertEqual(sale.state, "sale") diff --git a/sale_order_approval_block/tests/test_sale_order_approval_block.py b/sale_order_approval_block/tests/test_sale_order_approval_block.py new file mode 100644 index 00000000000..a5ca873ad56 --- /dev/null +++ b/sale_order_approval_block/tests/test_sale_order_approval_block.py @@ -0,0 +1,96 @@ +from odoo.tests.common import TransactionCase + + +class TestSaleOrderApprovalBlock(TransactionCase): + def setUp(self): + super().setUp() + self.users_obj = self.env["res.users"] + self.so_obj = self.env["sale.order"] + self.so_block_obj = self.env["sale.approval.block.reason"] + + # company + self.company1 = self.env.ref("base.main_company") + + # groups + self.group_sale_user = self.env.ref("sales_team.group_sale_salesman_all_leads") + self.group_sale_manager = self.env.ref("sales_team.group_sale_manager") + + # Partner + self.partner1 = self.env["res.partner"].create( + { + "name": "Partner 1", + "email": "partner1@yourcompany.com", + "company_id": self.company1.id, + } + ) + + # Products + self.product1 = self.env["product.product"].create( + { + "name": "Product 1", + } + ) + self.product2 = self.env["product.product"].create( + { + "name": "Product 2", + } + ) + self.product3 = self.env["product.product"].create( + { + "name": "Product 3", + } + ) + + # Users + self.user1_id = self._create_user( + "user_sale_1", [self.group_sale_user], self.company1 + ) + self.user2_id = self._create_user( + "user_sale_2", [self.group_sale_manager], self.company1 + ) + + # Approval block reason + self._create_block_reason() + + def _create_block_reason(self): + self.so_approval_block_reason = self.so_block_obj.create( + {"name": "Needs Permission", "description": "Permission to confirm"} + ) + + def _create_user(self, login, groups, company): + group_ids = [group.id for group in groups] + user = self.users_obj.with_context(no_reset_password=True).create( + { + "name": "Sale User", + "login": login, + "password": "test", + "email": "test@yourcompany.com", + "company_id": company.id, + "company_ids": [(4, company.id)], + "group_ids": [(6, 0, group_ids)], + } + ) + return user.id + + def _create_sale(self, line_products): + lines = [] + for product, qty in line_products: + lines.append( + ( + 0, + 0, + { + "product_id": product.id, + "product_uom_qty": qty, + "price_unit": 100, + }, + ) + ) + sale = self.so_obj.create( + { + "partner_id": self.partner1.id, + "order_line": lines, + "company_id": self.company1.id, + } + ) + return sale diff --git a/sale_order_approval_block/views/sale_approval_block_reason_view.xml b/sale_order_approval_block/views/sale_approval_block_reason_view.xml new file mode 100644 index 00000000000..11e048f50ae --- /dev/null +++ b/sale_order_approval_block/views/sale_approval_block_reason_view.xml @@ -0,0 +1,47 @@ + + + + sale.approval.block.reason.tree + sale.approval.block.reason + + + + + + + + + + sale.approval.block.reason.form + sale.approval.block.reason + +
+ + + + + + + +
+
+
+ + + Sale Approval Block Reasons + sale.approval.block.reason + list,form + + + +
diff --git a/sale_order_approval_block/views/sale_order_view.xml b/sale_order_approval_block/views/sale_order_view.xml new file mode 100644 index 00000000000..bd2675e7abe --- /dev/null +++ b/sale_order_approval_block/views/sale_order_view.xml @@ -0,0 +1,54 @@ + + + + sale.order.form.block.reason + sale.order + + + + + + + + + + +