diff --git a/purchase_stock_tier_validation/README.rst b/purchase_stock_tier_validation/README.rst new file mode 100644 index 000000000..bce052b27 --- /dev/null +++ b/purchase_stock_tier_validation/README.rst @@ -0,0 +1,91 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============================== +Purchase Stock Tier Validation +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:regenerate_with_oca_gen_addon_readme + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Ftier--validation-lightgray.png?logo=github + :target: https://github.com/OCA/tier-validation/tree/19.0/purchase_stock_tier_validation + :alt: OCA/tier-validation +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/tier-validation-19-0/tier-validation-19-0-purchase_stock_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/tier-validation&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module excludes RFQs pending to validate or validated when procuring a product. + +If a RFQ, at some point, is requested to validate, it converts it immediately in something unmodifiable. +Then, taking this into account, if we procure a product with the same supplier as one open RFQ, it should +check if that is under validation or already validated and discard it on any of both cases. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module depends on ``purchase_tier_validation``. You can find it in +this same repository, `OCA/tier-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 +------- + +* ForgeFlow + +Contributors +------------ + +- Bernat Puig Font +- Giordano Loiaconi (migrate to v19) + +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/tier-validation `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_stock_tier_validation/__init__.py b/purchase_stock_tier_validation/__init__.py new file mode 100644 index 000000000..31660d6a9 --- /dev/null +++ b/purchase_stock_tier_validation/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/purchase_stock_tier_validation/__manifest__.py b/purchase_stock_tier_validation/__manifest__.py new file mode 100644 index 000000000..3f179173c --- /dev/null +++ b/purchase_stock_tier_validation/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Purchase Stock Tier Validation", + "summary": "Exclude RFQs pending to validate when procuring", + "version": "19.0.1.0.0", + "category": "Purchase Management", + "website": "https://github.com/OCA/tier-validation", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "maintainers": ["bosd"], + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": ["purchase_stock", "purchase_tier_validation"], +} diff --git a/purchase_stock_tier_validation/i18n/purchase_stock_tier_validation.pot b/purchase_stock_tier_validation/i18n/purchase_stock_tier_validation.pot new file mode 100644 index 000000000..ec79216e3 --- /dev/null +++ b/purchase_stock_tier_validation/i18n/purchase_stock_tier_validation.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_stock_tier_validation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.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_stock_tier_validation +#: model:ir.model,name:purchase_stock_tier_validation.model_stock_rule +msgid "Stock Rule" +msgstr "" diff --git a/purchase_stock_tier_validation/models/__init__.py b/purchase_stock_tier_validation/models/__init__.py new file mode 100644 index 000000000..31a15d1e4 --- /dev/null +++ b/purchase_stock_tier_validation/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import stock_rule diff --git a/purchase_stock_tier_validation/models/stock_rule.py b/purchase_stock_tier_validation/models/stock_rule.py new file mode 100644 index 000000000..b1e85e35d --- /dev/null +++ b/purchase_stock_tier_validation/models/stock_rule.py @@ -0,0 +1,15 @@ +# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com) +# Part of ForgeFlow. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class StockRule(models.Model): + _inherit = "stock.rule" + + def _make_po_get_domain(self, company_id, values, partner): + domain = super()._make_po_get_domain( + company_id=company_id, values=values, partner=partner + ) + domain += (("review_ids", "=", False),) + return domain diff --git a/purchase_stock_tier_validation/pyproject.toml b/purchase_stock_tier_validation/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/purchase_stock_tier_validation/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_stock_tier_validation/readme/CONTRIBUTORS.md b/purchase_stock_tier_validation/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..6479789e9 --- /dev/null +++ b/purchase_stock_tier_validation/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Bernat Puig Font \<\> +- Giordano Loiaconi \<\> (migrate to v19) diff --git a/purchase_stock_tier_validation/readme/DESCRIPTION.md b/purchase_stock_tier_validation/readme/DESCRIPTION.md new file mode 100644 index 000000000..e42436201 --- /dev/null +++ b/purchase_stock_tier_validation/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This module excludes RFQs pending to validate or validated when procuring a product. + +If a RFQ, at some point, is requested to validate, it converts it immediately in something unmodifiable. +Then, taking this into account, if we procure a product with the same supplier as one open RFQ, it should +check if that is under validation or already validated and discard it on any of both cases. diff --git a/purchase_stock_tier_validation/static/description/icon.png b/purchase_stock_tier_validation/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/purchase_stock_tier_validation/static/description/icon.png differ diff --git a/purchase_stock_tier_validation/tests/__init__.py b/purchase_stock_tier_validation/tests/__init__.py new file mode 100644 index 000000000..4d66f02ea --- /dev/null +++ b/purchase_stock_tier_validation/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_purchase_stock_tier_validation diff --git a/purchase_stock_tier_validation/tests/test_purchase_stock_tier_validation.py b/purchase_stock_tier_validation/tests/test_purchase_stock_tier_validation.py new file mode 100644 index 000000000..609b042de --- /dev/null +++ b/purchase_stock_tier_validation/tests/test_purchase_stock_tier_validation.py @@ -0,0 +1,102 @@ +# Copyright 2017-2020 ForgeFlow S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). + +from odoo import Command, fields +from odoo.tests import new_test_user, tagged + +from odoo.addons.base.tests.common import BaseCommon + + +@tagged("-at_install", "post_install") +class TestPurchaseStockTierValidation(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Get purchase order model + cls.po_model = cls.env.ref("purchase.model_purchase_order") + + # Create users + cls.test_user_1 = new_test_user( + cls.env, name="John", login="test1", groups="base.group_system" + ) + + # Create tier definitions: + cls.tier_def_obj = cls.env["tier.definition"] + cls.tier_def_obj.create( + { + "model_id": cls.po_model.id, + "review_type": "individual", + "reviewer_id": cls.test_user_1.id, + } + ) + + # Common models + cls.stock_loc = cls.env.ref("stock.stock_location_stock") + cls.warehouse = cls.env.ref("stock.warehouse0") + + # Create product + route_buy = cls.env.ref("purchase_stock.route_warehouse0_buy").id + cls.test_product = cls.env["product.product"].create( + { + "name": "Test Scrap Component 1", + "type": "consu", + "is_storable": True, + "route_ids": [Command.set([route_buy])], + "seller_ids": [ + Command.create({"partner_id": cls.partner.id, "price": 20.0}) + ], + } + ) + + def test_procurement_in_new_rfq(self): + """ + Procure a product with the same supplier as one open RFQ under validation + and check if it includes the procurement in that RFQ or in a new one. + """ + po = self.env["purchase.order"].create( + { + "partner_id": self.partner.id, + "order_line": [ + Command.create( + { + "name": "PO-Product", + "product_id": self.test_product.id, + "date_planned": fields.Datetime.now(), + "product_qty": 10, + "product_uom_id": self.test_product.uom_id.id, + "price_unit": 1000, + }, + ) + ], + } + ) + rfq_test_partner_before = self.env["purchase.order"].search( + [("partner_id", "=", self.partner.id)] + ) + self.assertEqual(len(po.mapped("order_line")), 1) + po.request_validation() + po.with_user(self.test_user_1).validate_tier() + date_planned = fields.Datetime.now() + values = { + "company_id": self.warehouse.company_id, + "date_planned": date_planned, + "warehouse_id": self.warehouse, + } + procurements = [ + self.env["stock.rule"].Procurement( + self.test_product, + 1, + self.env.ref("uom.product_uom_unit"), + self.stock_loc, + "test", + "TEST", + self.warehouse.company_id, + values, + ) + ] + self.env["stock.rule"].run(procurements) + self.assertEqual(len(po.mapped("order_line")), 1) + rfq_test_partner_after = self.env["purchase.order"].search( + [("partner_id", "=", self.partner.id)] + ) + self.assertEqual(len(rfq_test_partner_after), len(rfq_test_partner_before) + 1)