diff --git a/purchase_stock_operating_unit/README.rst b/purchase_stock_operating_unit/README.rst new file mode 100644 index 0000000000..52721b8256 --- /dev/null +++ b/purchase_stock_operating_unit/README.rst @@ -0,0 +1,99 @@ +============================= +Purchase Stock Operating Unit +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:37ed2cb55b6f6c3b29c608bde062bfa5016a03d7a144c5ffda51acc993a8c4a7 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Foperating--unit-lightgray.png?logo=github + :target: https://github.com/OCA/operating-unit/tree/18.0/purchase_stock_operating_unit + :alt: OCA/operating-unit +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/operating-unit-18-0/operating-unit-18-0-purchase_stock_operating_unit + :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/operating-unit&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is used to integrated between Purchase and Stock to send +Operating Unit in the warehouse that has been selected from Deliver To +to Stock Picking. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. Create a purchase order +2. Select Deliver To that have operating unit in warehouse +3. Confirm purchase order +4. you should have your operating unit on your stock picking + +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 +------- + +* Ecosoft + +Contributors +------------ + +- Saran Lim. +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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-Saran440| image:: https://github.com/Saran440.png?size=40px + :target: https://github.com/Saran440 + :alt: Saran440 + +Current `maintainer `__: + +|maintainer-Saran440| + +This module is part of the `OCA/operating-unit `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_stock_operating_unit/__init__.py b/purchase_stock_operating_unit/__init__.py new file mode 100644 index 0000000000..69f7babdfb --- /dev/null +++ b/purchase_stock_operating_unit/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/purchase_stock_operating_unit/__manifest__.py b/purchase_stock_operating_unit/__manifest__.py new file mode 100644 index 0000000000..570ad843ff --- /dev/null +++ b/purchase_stock_operating_unit/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Purchase Stock Operating Unit", + "summary": "Copies the operating unit of purchase picking to the stock picking", + "version": "18.0.1.0.0", + "author": "Ecosoft, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/operating-unit", + "category": "Purchase Management", + "depends": ["purchase_operating_unit", "stock_operating_unit"], + "license": "AGPL-3", + "data": [], + "installable": True, + "maintainers": ["Saran440"], +} diff --git a/purchase_stock_operating_unit/i18n/purchase_stock_operating_unit.pot b/purchase_stock_operating_unit/i18n/purchase_stock_operating_unit.pot new file mode 100644 index 0000000000..c365c7f80a --- /dev/null +++ b/purchase_stock_operating_unit/i18n/purchase_stock_operating_unit.pot @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_stock_operating_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_operating_unit +#: code:addons/purchase_stock_operating_unit/models/purchase.py:0 +#, python-format +msgid "" +"Configuration error. The Operating Unit in the Purchase and Deliver To must " +"be the same." +msgstr "" + +#. module: purchase_stock_operating_unit +#: model:ir.model,name:purchase_stock_operating_unit.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_stock_operating_unit +#: model:ir.model,name:purchase_stock_operating_unit.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" diff --git a/purchase_stock_operating_unit/models/__init__.py b/purchase_stock_operating_unit/models/__init__.py new file mode 100644 index 0000000000..985634e798 --- /dev/null +++ b/purchase_stock_operating_unit/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import purchase +from . import stock_rule diff --git a/purchase_stock_operating_unit/models/purchase.py b/purchase_stock_operating_unit/models/purchase.py new file mode 100644 index 0000000000..28b4f3c64a --- /dev/null +++ b/purchase_stock_operating_unit/models/purchase.py @@ -0,0 +1,63 @@ +# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + picking_type_id = fields.Many2one( + compute="_compute_picking_type_id", store=True, readonly=False + ) + operating_unit_id = fields.Many2one( + compute="_compute_operating_unit_id", + store=True, + readonly=False, + ) + + @api.depends("operating_unit_id") + def _compute_picking_type_id(self): + for purchase in self: + if purchase.operating_unit_id: + purchase.picking_type_id = self.env["stock.picking.type"].search( + [ + ( + "warehouse_id.operating_unit_id", + "=", + purchase.operating_unit_id.id, + ), + ("code", "=", "incoming"), + ], + limit=1, + ) + + @api.depends("picking_type_id") + def _compute_operating_unit_id(self): + for purchase in self: + if purchase.picking_type_id: + purchase.operating_unit_id = ( + purchase.picking_type_id.warehouse_id.operating_unit_id + ) + + @api.constrains("operating_unit_id", "picking_type_id") + def _check_operating_unit_picking_type(self): + for rec in self: + if ( + rec.operating_unit_id + and rec.picking_type_id.warehouse_id.operating_unit_id + and rec.operating_unit_id + != rec.picking_type_id.warehouse_id.operating_unit_id + ): + raise UserError( + self.env._( + "Configuration error. The Operating Unit in " + "the Purchase and Deliver To must be the same." + ) + ) + + def _prepare_picking(self): + vals = super()._prepare_picking() + vals["operating_unit_id"] = self.operating_unit_id.id + return vals diff --git a/purchase_stock_operating_unit/models/stock_rule.py b/purchase_stock_operating_unit/models/stock_rule.py new file mode 100644 index 0000000000..2b0060a686 --- /dev/null +++ b/purchase_stock_operating_unit/models/stock_rule.py @@ -0,0 +1,14 @@ +# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockRule(models.Model): + _inherit = "stock.rule" + + def _prepare_purchase_order(self, company_id, origins, values): + res = super()._prepare_purchase_order(company_id, origins, values) + if self.operating_unit_id: + res["operating_unit_id"] = self.operating_unit_id.id + return res diff --git a/purchase_stock_operating_unit/pyproject.toml b/purchase_stock_operating_unit/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/purchase_stock_operating_unit/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_stock_operating_unit/readme/CONTRIBUTORS.md b/purchase_stock_operating_unit/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..deb2eb2294 --- /dev/null +++ b/purchase_stock_operating_unit/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Saran Lim. \<\> +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/purchase_stock_operating_unit/readme/DESCRIPTION.md b/purchase_stock_operating_unit/readme/DESCRIPTION.md new file mode 100644 index 0000000000..ba221cbc3f --- /dev/null +++ b/purchase_stock_operating_unit/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module is used to integrated between Purchase and Stock to send +Operating Unit in the warehouse that has been selected from Deliver To +to Stock Picking. diff --git a/purchase_stock_operating_unit/readme/USAGE.md b/purchase_stock_operating_unit/readme/USAGE.md new file mode 100644 index 0000000000..46233a8de6 --- /dev/null +++ b/purchase_stock_operating_unit/readme/USAGE.md @@ -0,0 +1,6 @@ +To use this module, you need to: + +1. Create a purchase order +2. Select Deliver To that have operating unit in warehouse +3. Confirm purchase order +4. you should have your operating unit on your stock picking diff --git a/purchase_stock_operating_unit/static/description/icon.png b/purchase_stock_operating_unit/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/purchase_stock_operating_unit/static/description/icon.png differ diff --git a/purchase_stock_operating_unit/static/description/index.html b/purchase_stock_operating_unit/static/description/index.html new file mode 100644 index 0000000000..e8ca3e9501 --- /dev/null +++ b/purchase_stock_operating_unit/static/description/index.html @@ -0,0 +1,442 @@ + + + + + +Purchase Stock Operating Unit + + + +
+

Purchase Stock Operating Unit

+ + +

Beta License: AGPL-3 OCA/operating-unit Translate me on Weblate Try me on Runboat

+

This module is used to integrated between Purchase and Stock to send +Operating Unit in the warehouse that has been selected from Deliver To +to Stock Picking.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Create a purchase order
  2. +
  3. Select Deliver To that have operating unit in warehouse
  4. +
  5. Confirm purchase order
  6. +
  7. you should have your operating unit on your stock picking
  8. +
+
+
+

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

+
    +
  • Ecosoft
  • +
+
+
+

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.

+

Current maintainer:

+

Saran440

+

This module is part of the OCA/operating-unit project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_stock_operating_unit/tests/__init__.py b/purchase_stock_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..81c4bc610c --- /dev/null +++ b/purchase_stock_operating_unit/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_purchase_stock_operating_unit diff --git a/purchase_stock_operating_unit/tests/test_purchase_stock_operating_unit.py b/purchase_stock_operating_unit/tests/test_purchase_stock_operating_unit.py new file mode 100644 index 0000000000..fdaef5a5c6 --- /dev/null +++ b/purchase_stock_operating_unit/tests/test_purchase_stock_operating_unit.py @@ -0,0 +1,63 @@ +# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.models import Command + +from odoo.addons.purchase_operating_unit.tests.test_purchase_operating_unit import ( + TestPurchaseOperatingUnit, +) + + +class TestPurchaseStockOperatingUnit(TestPurchaseOperatingUnit): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.warehouse_b2b = cls.env.ref("stock_operating_unit.stock_warehouse_b2b") + cls.picking_type2 = cls.env["stock.picking.type"].search( + [ + ("code", "=", "incoming"), + ("warehouse_id", "=", cls.warehouse_b2b.id), + ], + limit=1, + ) + cls.user1.write( + { + "operating_unit_ids": [ + Command.link(cls.b2b.id), + ], + } + ) + + def test_01_purchase_stock_operating_unit(self): + self.assertEqual(self.purchase1.state, "purchase") + self.assertEqual( + self.purchase1.picking_ids.operating_unit_id, + self.purchase1.picking_type_id.warehouse_id.operating_unit_id, + ) + # Ensure that in case of picking type changes, + # the operating unit is also updated. + self.purchase1.button_cancel() + self.purchase1.button_draft() + self.purchase1.picking_type_id = self.picking_type2 + self.assertEqual( + self.purchase1.operating_unit_id, + self.purchase1.picking_type_id.warehouse_id.operating_unit_id, + ) + + def test_02_compute_picking_type_id(self): + self.purchase1.operating_unit_id = self.b2b + self.purchase1._compute_picking_type_id() + expected_picking_type = self.env["stock.picking.type"].search( + [ + ("warehouse_id.operating_unit_id", "=", self.b2b.id), + ("code", "=", "incoming"), + ], + limit=1, + ) + self.assertEqual(self.purchase1.picking_type_id, expected_picking_type) + + def test_03_prepare_picking(self): + picking_vals = self.purchase1._prepare_picking() + self.assertEqual( + picking_vals.get("operating_unit_id"), self.purchase1.operating_unit_id.id + )