From 1ff1f88eb1405c69f99e1dd745611949c56c8e4d Mon Sep 17 00:00:00 2001 From: Nikul-OSI Date: Tue, 20 Aug 2024 11:39:20 +0530 Subject: [PATCH] [ADD]sale_blanket_order_tier_validation: Added in v17 --- sale_blanket_order_tier_validation/README.rst | 112 +++++ .../__init__.py | 3 + .../__manifest__.py | 23 + .../models/__init__.py | 4 + .../models/sale_blanket_order.py | 56 +++ .../models/tier_definition.py | 18 + .../pyproject.toml | 3 + .../readme/CONFIGURE.md | 5 + .../readme/CONTRIBUTORS.md | 2 + .../readme/DESCRIPTION.md | 2 + .../readme/INSTALL.md | 2 + .../readme/USAGE.md | 15 + .../static/description/index.html | 458 ++++++++++++++++++ .../tests/__init__.py | 1 + ...test_sale_blanket_order_tier_validation.py | 124 +++++ .../views/sale_blanket_order_views.xml | 50 ++ 16 files changed, 878 insertions(+) create mode 100644 sale_blanket_order_tier_validation/README.rst create mode 100644 sale_blanket_order_tier_validation/__init__.py create mode 100644 sale_blanket_order_tier_validation/__manifest__.py create mode 100644 sale_blanket_order_tier_validation/models/__init__.py create mode 100644 sale_blanket_order_tier_validation/models/sale_blanket_order.py create mode 100644 sale_blanket_order_tier_validation/models/tier_definition.py create mode 100644 sale_blanket_order_tier_validation/pyproject.toml create mode 100644 sale_blanket_order_tier_validation/readme/CONFIGURE.md create mode 100644 sale_blanket_order_tier_validation/readme/CONTRIBUTORS.md create mode 100644 sale_blanket_order_tier_validation/readme/DESCRIPTION.md create mode 100644 sale_blanket_order_tier_validation/readme/INSTALL.md create mode 100644 sale_blanket_order_tier_validation/readme/USAGE.md create mode 100644 sale_blanket_order_tier_validation/static/description/index.html create mode 100644 sale_blanket_order_tier_validation/tests/__init__.py create mode 100644 sale_blanket_order_tier_validation/tests/test_sale_blanket_order_tier_validation.py create mode 100644 sale_blanket_order_tier_validation/views/sale_blanket_order_views.xml diff --git a/sale_blanket_order_tier_validation/README.rst b/sale_blanket_order_tier_validation/README.rst new file mode 100644 index 00000000000..4fdf7141bd3 --- /dev/null +++ b/sale_blanket_order_tier_validation/README.rst @@ -0,0 +1,112 @@ +=================================== +Sale Blanket Orders Tier Validation +=================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:adb4549c4d5a6fc42fc865560f51f2d2ab705b8ac7a18c08cced1309637bf945 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/17.0/sale_blanket_order_tier_validation + :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_blanket_order_tier_validation + :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| + +Extends the functionality of your Sale Blanket Orders to support a tier +validation process + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module depends on ``base_tier_validation``. You can find it at +`OCA/server-ux `__ + +Configuration +============= + +To configure this module, you need to: + +1. Go to *Settings > Technical > Tier Validations > Tier Definition*. +2. Create as many tiers as you want for Purchase Order model. + +Usage +===== + +To use this module, you need to: + +1. Create a Sale Blanket Orders triggering at least one "Tier + Definition". +2. Click on *Request Validation* button. +3. Under the tab *Reviews* have a look to pending reviews and their + statuses. +4. Once all reviews are validated click on *Confirm Order*. + +Additional features: + +- You can filter the Blanket Orders requesting your review through the + filter *Needs my Review*. +- User with rights to confirm the Blanket Orders (validate all tiers + that would be generated) can directly do the operation, this is, + there is no need for her/him to request a validation. + +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 +------------ + +- Patrick Wilson +- Nikul Chaudhary + +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_blanket_order_tier_validation/__init__.py b/sale_blanket_order_tier_validation/__init__.py new file mode 100644 index 00000000000..cac14e6e3c8 --- /dev/null +++ b/sale_blanket_order_tier_validation/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2024 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/sale_blanket_order_tier_validation/__manifest__.py b/sale_blanket_order_tier_validation/__manifest__.py new file mode 100644 index 00000000000..32a5203c35d --- /dev/null +++ b/sale_blanket_order_tier_validation/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2024 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale Blanket Orders Tier Validation", + "summary": """ + Extends the functionality of your Sale Blanket Orders + to support a tier validation process. + """, + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sale-workflow", + "license": "AGPL-3", + "category": "Sales", + "version": "17.0.1.0.0", + "depends": [ + "sale_blanket_order", + "base_tier_validation", + ], + "data": [ + "views/sale_blanket_order_views.xml", + ], + "application": False, + "installable": True, +} diff --git a/sale_blanket_order_tier_validation/models/__init__.py b/sale_blanket_order_tier_validation/models/__init__.py new file mode 100644 index 00000000000..45abc12b1b5 --- /dev/null +++ b/sale_blanket_order_tier_validation/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import sale_blanket_order +from . import tier_definition diff --git a/sale_blanket_order_tier_validation/models/sale_blanket_order.py b/sale_blanket_order_tier_validation/models/sale_blanket_order.py new file mode 100644 index 00000000000..4ad6dd061b2 --- /dev/null +++ b/sale_blanket_order_tier_validation/models/sale_blanket_order.py @@ -0,0 +1,56 @@ +# Copyright 2024 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models +from odoo.tools import float_is_zero + + +class SaleBlanketOrder(models.Model): + """ + Adding tier validation functionality to Blanket Orders. + """ + + _name = "sale.blanket.order" + _inherit = ["sale.blanket.order", "tier.validation"] + _state_from = ["draft"] + _state_to = ["open", "done", "expired"] + + _tier_validation_manual_config = False + + @api.depends( + "line_ids.remaining_uom_qty", + "validity_date", + "confirmed", + ) + def _compute_state(self): + """Complete override of Blanket Order Compute State Method: + The OCA Blanket Order module sets state via compute method which messes + with tier validation checks so we are going to instead set the state + to 'Open' only when clicking confirmed. This also forces process as before + just changing data would reset BO back to Open if expired.""" + today = fields.Date.today() + precision = self.env["decimal.precision"].precision_get( + "Product Unit of Measure" + ) + for order in self: + if not order.confirmed: + order.state = "draft" + elif order.validity_date <= today: + order.state = "expired" + elif float_is_zero( + sum( + order.line_ids.filtered(lambda line: not line.display_type).mapped( + "remaining_uom_qty" + ) + ), + precision_digits=precision, + ): + order.state = "done" + # Removing else statement from original method + # else: + # order.state = "open" + + def action_confirm(self): + """Set the state to 'Open' when clicking confirmed instead of during compute.""" + for rec in self: + rec.write({"state": "open"}) + return super().action_confirm() diff --git a/sale_blanket_order_tier_validation/models/tier_definition.py b/sale_blanket_order_tier_validation/models/tier_definition.py new file mode 100644 index 00000000000..aea661fd793 --- /dev/null +++ b/sale_blanket_order_tier_validation/models/tier_definition.py @@ -0,0 +1,18 @@ +# Copyright 2024 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, models + + +class TierDefinition(models.Model): + """ + Add Sale Blanket Order model to tier definitions. + """ + + _inherit = "tier.definition" + + @api.model + def _get_tier_validation_model_names(self): + """This method adds the Sale Blanket Order model to tier definitions.""" + res = super()._get_tier_validation_model_names() + res.append("sale.blanket.order") + return res diff --git a/sale_blanket_order_tier_validation/pyproject.toml b/sale_blanket_order_tier_validation/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_blanket_order_tier_validation/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_blanket_order_tier_validation/readme/CONFIGURE.md b/sale_blanket_order_tier_validation/readme/CONFIGURE.md new file mode 100644 index 00000000000..3fe3359d464 --- /dev/null +++ b/sale_blanket_order_tier_validation/readme/CONFIGURE.md @@ -0,0 +1,5 @@ +To configure this module, you need to: + +1. Go to *Settings \> Technical \> Tier Validations \> Tier + Definition*. +2. Create as many tiers as you want for Purchase Order model. diff --git a/sale_blanket_order_tier_validation/readme/CONTRIBUTORS.md b/sale_blanket_order_tier_validation/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..8aa59a82c74 --- /dev/null +++ b/sale_blanket_order_tier_validation/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Patrick Wilson \<\> +- Nikul Chaudhary \<\> diff --git a/sale_blanket_order_tier_validation/readme/DESCRIPTION.md b/sale_blanket_order_tier_validation/readme/DESCRIPTION.md new file mode 100644 index 00000000000..5088577267e --- /dev/null +++ b/sale_blanket_order_tier_validation/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +Extends the functionality of your Sale Blanket Orders +to support a tier validation process diff --git a/sale_blanket_order_tier_validation/readme/INSTALL.md b/sale_blanket_order_tier_validation/readme/INSTALL.md new file mode 100644 index 00000000000..c45725c465b --- /dev/null +++ b/sale_blanket_order_tier_validation/readme/INSTALL.md @@ -0,0 +1,2 @@ +This module depends on `base_tier_validation`. You can find it at +[OCA/server-ux](https://github.com/OCA/server-ux) diff --git a/sale_blanket_order_tier_validation/readme/USAGE.md b/sale_blanket_order_tier_validation/readme/USAGE.md new file mode 100644 index 00000000000..a591c60d551 --- /dev/null +++ b/sale_blanket_order_tier_validation/readme/USAGE.md @@ -0,0 +1,15 @@ +To use this module, you need to: + +1. Create a Sale Blanket Orders triggering at least one "Tier Definition". +2. Click on *Request Validation* button. +3. Under the tab *Reviews* have a look to pending reviews and their + statuses. +4. Once all reviews are validated click on *Confirm Order*. + +Additional features: + +- You can filter the Blanket Orders requesting your review through the filter + *Needs my Review*. +- User with rights to confirm the Blanket Orders (validate all tiers that would be + generated) can directly do the operation, this is, there is no need + for her/him to request a validation. diff --git a/sale_blanket_order_tier_validation/static/description/index.html b/sale_blanket_order_tier_validation/static/description/index.html new file mode 100644 index 00000000000..8b831b9398a --- /dev/null +++ b/sale_blanket_order_tier_validation/static/description/index.html @@ -0,0 +1,458 @@ + + + + + +Sale Blanket Orders Tier Validation + + + +
+

Sale Blanket Orders Tier Validation

+ + +

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

+

Extends the functionality of your Sale Blanket Orders to support a tier +validation process

+

Table of contents

+ +
+

Installation

+

This module depends on base_tier_validation. You can find it at +OCA/server-ux

+
+
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Go to Settings > Technical > Tier Validations > Tier Definition.
  2. +
  3. Create as many tiers as you want for Purchase Order model.
  4. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Create a Sale Blanket Orders triggering at least one “Tier +Definition”.
  2. +
  3. Click on Request Validation button.
  4. +
  5. Under the tab Reviews have a look to pending reviews and their +statuses.
  6. +
  7. Once all reviews are validated click on Confirm Order.
  8. +
+

Additional features:

+
    +
  • You can filter the Blanket Orders requesting your review through the +filter Needs my Review.
  • +
  • User with rights to confirm the Blanket Orders (validate all tiers +that would be generated) can directly do the operation, this is, +there is no need for her/him to request a validation.
  • +
+
+
+

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.

+

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_blanket_order_tier_validation/tests/__init__.py b/sale_blanket_order_tier_validation/tests/__init__.py new file mode 100644 index 00000000000..4173fd713ba --- /dev/null +++ b/sale_blanket_order_tier_validation/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_blanket_order_tier_validation diff --git a/sale_blanket_order_tier_validation/tests/test_sale_blanket_order_tier_validation.py b/sale_blanket_order_tier_validation/tests/test_sale_blanket_order_tier_validation.py new file mode 100644 index 00000000000..041448aa552 --- /dev/null +++ b/sale_blanket_order_tier_validation/tests/test_sale_blanket_order_tier_validation.py @@ -0,0 +1,124 @@ +# Import Odoo libs +from datetime import date, timedelta + +from odoo import fields +from odoo.exceptions import ValidationError +from odoo.tests import common + + +class TestSaleBlanketOrdersTierValidation(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.blanket_order_obj = cls.env["sale.blanket.order"] + cls.tier_def_obj = cls.env["tier.definition"] + cls.payment_term = cls.env.ref("account.account_payment_term_immediate") + cls.sale_pricelist = cls.env["product.pricelist"].create( + {"name": "Test Pricelist", "currency_id": cls.env.ref("base.USD").id} + ) + + # UoM + cls.categ_unit = cls.env.ref("uom.product_uom_categ_unit") + cls.uom_dozen = cls.env["uom.uom"].create( + { + "name": "Test-DozenA", + "category_id": cls.categ_unit.id, + "factor_inv": 12, + "uom_type": "bigger", + "rounding": 0.001, + } + ) + + cls.partner = cls.env["res.partner"].create( + { + "name": "TEST CUSTOMER", + "property_product_pricelist": cls.sale_pricelist.id, + } + ) + + cls.product = cls.env["product.product"].create( + { + "name": "Demo", + "categ_id": cls.env.ref("product.product_category_1").id, + "standard_price": 35.0, + "type": "consu", + "uom_id": cls.env.ref("uom.product_uom_unit").id, + "default_code": "PROD_DEL01", + } + ) + + cls.yesterday = date.today() - timedelta(days=1) + cls.tomorrow = date.today() + timedelta(days=1) + + cls.test_user_1 = cls.env["res.users"].create( + { + "name": "user_sale_manager", + "login": "user_sale_manager", + "groups_id": [ + (6, 0, [cls.env.ref("sales_team.group_sale_manager").id]) + ], + } + ) + + cls.eco_model = cls.env.ref( + "sale_blanket_order_tier_validation.model_sale_blanket_order" + ) + # Create tier definition for this test + cls.tier_def_obj.create( + { + "model_id": cls.eco_model.id, + "review_type": "individual", + "reviewer_id": cls.test_user_1.id, + "definition_domain": "[('state', '=', 'draft')]", + } + ) + + def test01_tier_validation_model_name(self): + """ + Tests to ensure that the sale.blanket.order model is now part of the options + on a tier definition. + """ + self.assertIn( + "sale.blanket.order", self.tier_def_obj._get_tier_validation_model_names() + ) + + def test02_validation_blanket_order(self): + # Create an Sale blanket order in the 'draft' stage + blanket_order = self.blanket_order_obj.create( + { + "partner_id": self.partner.id, + "validity_date": fields.Date.to_string(self.tomorrow), + "payment_term_id": self.payment_term.id, + "pricelist_id": self.sale_pricelist.id, + "line_ids": [ + ( + 0, + 0, + { + "product_id": self.product.id, + "product_uom": self.product.uom_id.id, + "original_uom_qty": 20.0, + "price_unit": 10.0, + }, + ), + ], + } + ) + self.assertEqual(blanket_order.state, "draft") + + # Request tier validation + blanket_order.request_validation() + + # Changing to new stage would cause a validation error + with self.assertRaises(ValidationError): + blanket_order.action_confirm() + + # Validate the tier validation request + blanket_order.with_user(self.test_user_1).validate_tier() + self.assertTrue(blanket_order.validated) + + # Change the sale blanket stage to normal + blanket_order.action_confirm() + + # Confirm the stage changed + self.assertEqual(blanket_order.state, "open") diff --git a/sale_blanket_order_tier_validation/views/sale_blanket_order_views.xml b/sale_blanket_order_tier_validation/views/sale_blanket_order_views.xml new file mode 100644 index 00000000000..16e6ef9c176 --- /dev/null +++ b/sale_blanket_order_tier_validation/views/sale_blanket_order_views.xml @@ -0,0 +1,50 @@ + + + + sale.blanket.order.job.tier.validation.inherit.search + sale.blanket.order + + + + + + + + + + + + sale.blanket.order.tier.validation.inherit.tree + sale.blanket.order + + + + + + + + +