diff --git a/purchase_stock_operating_unit/README.rst b/purchase_stock_operating_unit/README.rst new file mode 100644 index 0000000000..eec35bde76 --- /dev/null +++ b/purchase_stock_operating_unit/README.rst @@ -0,0 +1,93 @@ +============================= +Purchase Stock Operating Unit +============================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.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-16-0/operating-unit-16-0-purchase_stock_operating_unit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/213/16.0 + :alt: Try me on Runbot + +|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: + +#. Create a purchase order +#. Select Deliver To that have operating unit in warehouse +#. Confirm purchase order +#. 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 smashing 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. +* Alan Ramos + +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..40074dbb9c --- /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": "16.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..7cedad723e --- /dev/null +++ b/purchase_stock_operating_unit/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import purchase_order_line +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..26c790465e --- /dev/null +++ b/purchase_stock_operating_unit/models/purchase.py @@ -0,0 +1,40 @@ +# 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, models +from odoo.exceptions import UserError + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + @api.onchange("operating_unit_id") + def _onchange_operating_unit_id(self): + if self.operating_unit_id: + self.picking_type_id = self.env["stock.picking.type"].search( + [ + ("warehouse_id.operating_unit_id", "=", self.operating_unit_id.id), + ("code", "=", "incoming"), + ], + limit=1, + ) + + @api.onchange("picking_type_id") + def _onchange_picking_type_id(self): + if self.picking_type_id: + self.operating_unit_id = self.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.operating_unit_id + != rec.picking_type_id.warehouse_id.operating_unit_id + ): + raise UserError( + _( + "Configuration error. The Operating Unit in " + "the Purchase and Deliver To must be the same." + ) + ) diff --git a/purchase_stock_operating_unit/models/purchase_order_line.py b/purchase_stock_operating_unit/models/purchase_order_line.py new file mode 100644 index 0000000000..55de1e0104 --- /dev/null +++ b/purchase_stock_operating_unit/models/purchase_order_line.py @@ -0,0 +1,15 @@ +# 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 PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + def _prepare_stock_moves(self, picking): + """Add operating unit from warehouse to picking""" + picking.operating_unit_id = ( + picking.picking_type_id.warehouse_id.operating_unit_id + ) + return super()._prepare_stock_moves(picking) 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/readme/CONTRIBUTORS.rst b/purchase_stock_operating_unit/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..734f92bd64 --- /dev/null +++ b/purchase_stock_operating_unit/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Saran Lim. +* Alan Ramos diff --git a/purchase_stock_operating_unit/readme/DESCRIPTION.rst b/purchase_stock_operating_unit/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..51538535d7 --- /dev/null +++ b/purchase_stock_operating_unit/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +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.rst b/purchase_stock_operating_unit/readme/USAGE.rst new file mode 100644 index 0000000000..0394dfa706 --- /dev/null +++ b/purchase_stock_operating_unit/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use this module, you need to: + +#. Create a purchase order +#. Select Deliver To that have operating unit in warehouse +#. Confirm purchase order +#. 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..89b848fcef --- /dev/null +++ b/purchase_stock_operating_unit/static/description/index.html @@ -0,0 +1,434 @@ + + + + + + +Purchase Stock Operating Unit + + + +
+

Purchase Stock Operating Unit

+ + +

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

+

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 smashing 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..657960b792 --- /dev/null +++ b/purchase_stock_operating_unit/tests/test_purchase_stock_operating_unit.py @@ -0,0 +1,40 @@ +# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.exceptions import UserError +from odoo.tests import Form + +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, + ) + # Add permission b2b operating unit in user1 + cls.b2b = cls.env.ref("operating_unit.b2b_operating_unit") + user = cls.env["res.users"].browse(cls.user1_id) + user.operating_unit_ids = [(4, 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, + ) + self.purchase1.button_cancel() + self.purchase1.button_draft() + # Check change picking type is not equal operating unit, it should error + with self.assertRaises(UserError): + with Form(self.purchase1) as po: + po.picking_type_id = self.picking_type2 diff --git a/setup/purchase_stock_operating_unit/odoo/addons/purchase_stock_operating_unit b/setup/purchase_stock_operating_unit/odoo/addons/purchase_stock_operating_unit new file mode 120000 index 0000000000..ea50ef7c43 --- /dev/null +++ b/setup/purchase_stock_operating_unit/odoo/addons/purchase_stock_operating_unit @@ -0,0 +1 @@ +../../../../purchase_stock_operating_unit \ No newline at end of file diff --git a/setup/purchase_stock_operating_unit/setup.py b/setup/purchase_stock_operating_unit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_stock_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)