diff --git a/sale_stock_operating_unit/README.rst b/sale_stock_operating_unit/README.rst new file mode 100644 index 0000000000..9527a9c724 --- /dev/null +++ b/sale_stock_operating_unit/README.rst @@ -0,0 +1,103 @@ +============================= +Operating Unit in Sales Stock +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3e114c52a9f81f8de766dfe37806c0206c32bb8c3627f11a28fa3261b70ab733 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-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/sale_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-sale_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 was written to extend the Sales and the Stock capabilities +of Odoo. This module introduces some new operating unit (OU) +capabilities in order to enhance the performance of already existing OU +features for Sales and Stock. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Follow these steps: + +1. Use a created Operating Unit (OU) or create one in Settings -> + Users&Companies -> Operating Units. +2. Use a created Sales Team or create a new one in Sales -> + Configuration -> Sales Team and assign an OU +3. Create a new Warehouse with the previous OU (or use a Warehouse with + an assigned OU) +4. Check the Location has the same OU as the Warehouse in Inventory -> + Configuration Locations (make sure you have Storage Locations + checkbox activated) +5. Create a new Sale Order with the Sales Team, Operating Unit and + Warehouse used/created before. +6. OU, Picking Type and Location are propagated to the 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 +------- + +* Eficent +* Serpent Consulting Services Pvt. Ltd. + +Contributors +------------ + +- Eficent Business and IT Consulting Services S.L. +- Serpent Consulting Services Pvt. Ltd. +- Alejandro Padrón +- `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. + +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/sale_stock_operating_unit/__init__.py b/sale_stock_operating_unit/__init__.py new file mode 100644 index 0000000000..133f68732d --- /dev/null +++ b/sale_stock_operating_unit/__init__.py @@ -0,0 +1,2 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import models diff --git a/sale_stock_operating_unit/__manifest__.py b/sale_stock_operating_unit/__manifest__.py new file mode 100644 index 0000000000..6a0d9a97e2 --- /dev/null +++ b/sale_stock_operating_unit/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2015-19 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# Copyright 2015-19 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Operating Unit in Sales Stock", + "summary": "An operating unit (OU) is an organizational entity part of a " + "company", + "version": "18.0.1.0.0", + "author": "Eficent, Serpent Consulting Services Pvt. Ltd., " + "Odoo Community Association (OCA)", + "license": "LGPL-3", + "website": "https://github.com/OCA/operating-unit", + "category": "Sales Management", + "depends": [ + "sale_stock", + "sale_operating_unit", + "stock_operating_unit", + ], + "installable": True, +} diff --git a/sale_stock_operating_unit/i18n/it.po b/sale_stock_operating_unit/i18n/it.po new file mode 100644 index 0000000000..3d0a63822d --- /dev/null +++ b/sale_stock_operating_unit/i18n/it.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_stock_operating_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-09-22 16:38+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: sale_stock_operating_unit +#. odoo-python +#: code:addons/sale_stock_operating_unit/models/sale_order.py:0 +#, python-format +msgid "" +"Configuration error!\n" +"The OperatingUnit in the Sales Order and in the Warehouse must be the same." +msgstr "" +"Errore di configurazione!\n" +"L'Unità Operativa nell'ordine di vendita e nel magazzino deve essere la " +"stessa." + +#. module: sale_stock_operating_unit +#: model:ir.model,name:sale_stock_operating_unit.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" + +#. module: sale_stock_operating_unit +#. odoo-python +#: code:addons/sale_stock_operating_unit/models/stock_warehouse.py:0 +#, python-format +msgid "" +"Sales Order records already exist(s) for this warehouse and operating unit." +msgstr "" +"Esistono già degli ordini di vendita per questo magazzino e Unità Operativa." + +#. module: sale_stock_operating_unit +#: model:ir.model,name:sale_stock_operating_unit.model_stock_move +msgid "Stock Move" +msgstr "Movimento di magazzino" + +#. module: sale_stock_operating_unit +#: model:ir.model,name:sale_stock_operating_unit.model_stock_warehouse +msgid "Warehouse" +msgstr "Magazzino" + +#~ msgid "Sale Order" +#~ msgstr "Ordine di Vendita" diff --git a/sale_stock_operating_unit/i18n/pt.po b/sale_stock_operating_unit/i18n/pt.po new file mode 100644 index 0000000000..d3ffcd5545 --- /dev/null +++ b/sale_stock_operating_unit/i18n/pt.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_stock_operating_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-02-29 15:13+0000\n" +"Last-Translator: Pedro Castro Silva \n" +"Language-Team: none\n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: sale_stock_operating_unit +#. odoo-python +#: code:addons/sale_stock_operating_unit/models/sale_order.py:0 +#, python-format +msgid "" +"Configuration error!\n" +"The OperatingUnit in the Sales Order and in the Warehouse must be the same." +msgstr "" +"Erro de Configuração!\n" +"As Unidades Operacionais na Encomenda de Venda e no Armazém têm que ser " +"iguais." + +#. module: sale_stock_operating_unit +#: model:ir.model,name:sale_stock_operating_unit.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_stock_operating_unit +#. odoo-python +#: code:addons/sale_stock_operating_unit/models/stock_warehouse.py:0 +#, python-format +msgid "" +"Sales Order records already exist(s) for this warehouse and operating unit." +msgstr "" +"Já existem registos de Encomendas de Vendas para este armazém e unidade " +"operacional." + +#. module: sale_stock_operating_unit +#: model:ir.model,name:sale_stock_operating_unit.model_stock_move +msgid "Stock Move" +msgstr "Movimento de Stock" + +#. module: sale_stock_operating_unit +#: model:ir.model,name:sale_stock_operating_unit.model_stock_warehouse +msgid "Warehouse" +msgstr "Armazém" + +#~ msgid "Sale Order" +#~ msgstr "Encomenda de Venda" diff --git a/sale_stock_operating_unit/i18n/sale_stock_operating_unit.pot b/sale_stock_operating_unit/i18n/sale_stock_operating_unit.pot new file mode 100644 index 0000000000..d851384371 --- /dev/null +++ b/sale_stock_operating_unit/i18n/sale_stock_operating_unit.pot @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_stock_operating_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.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: sale_stock_operating_unit +#. odoo-python +#: code:addons/sale_stock_operating_unit/models/sale_order.py:0 +#, python-format +msgid "" +"Configuration error!\n" +"The OperatingUnit in the Sales Order and in the Warehouse must be the same." +msgstr "" + +#. module: sale_stock_operating_unit +#: model:ir.model,name:sale_stock_operating_unit.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_stock_operating_unit +#. odoo-python +#: code:addons/sale_stock_operating_unit/models/stock_warehouse.py:0 +#, python-format +msgid "" +"Sales Order records already exist(s) for this warehouse and operating unit." +msgstr "" + +#. module: sale_stock_operating_unit +#: model:ir.model,name:sale_stock_operating_unit.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: sale_stock_operating_unit +#: model:ir.model,name:sale_stock_operating_unit.model_stock_warehouse +msgid "Warehouse" +msgstr "" diff --git a/sale_stock_operating_unit/models/__init__.py b/sale_stock_operating_unit/models/__init__.py new file mode 100644 index 0000000000..18ebfa1c1e --- /dev/null +++ b/sale_stock_operating_unit/models/__init__.py @@ -0,0 +1,4 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import sale_order +from . import stock_move +from . import stock_warehouse diff --git a/sale_stock_operating_unit/models/sale_order.py b/sale_stock_operating_unit/models/sale_order.py new file mode 100644 index 0000000000..8a70e96921 --- /dev/null +++ b/sale_stock_operating_unit/models/sale_order.py @@ -0,0 +1,45 @@ +# Copyright 2015-19 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# Copyright 2015-19 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import api, models +from odoo.exceptions import ValidationError + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.depends("user_id", "company_id", "operating_unit_id") + def _compute_warehouse_id(self): + res = super()._compute_warehouse_id() + for sale in self: + if sale.warehouse_id.operating_unit_id != sale.operating_unit_id: + warehouse = self.env["stock.warehouse"].search( + [ + ( + "operating_unit_id", + "=", + sale.operating_unit_id.id, + ), + ], + limit=1, + ) + if warehouse: + sale.warehouse_id = warehouse.id + return res + + @api.constrains("operating_unit_id", "warehouse_id") + def _check_wh_operating_unit(self): + for rec in self: + if ( + rec.warehouse_id.operating_unit_id + and rec.operating_unit_id + and rec.operating_unit_id != rec.warehouse_id.operating_unit_id + ): + raise ValidationError( + self.env._( + "Configuration error!\nThe Operating" + "Unit in the Sales Order and in the" + " Warehouse must be the same." + ) + ) diff --git a/sale_stock_operating_unit/models/stock_move.py b/sale_stock_operating_unit/models/stock_move.py new file mode 100644 index 0000000000..cd0a93a083 --- /dev/null +++ b/sale_stock_operating_unit/models/stock_move.py @@ -0,0 +1,24 @@ +# Copyright 2015-19 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# Copyright 2015-19 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import models + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _get_new_picking_values(self): + """ + Override to add Operating Units to Picking. + """ + values = super()._get_new_picking_values() + + values.update( + { + "operating_unit_id": self.sale_line_id.operating_unit_id.id + or self.operating_unit_id.id + } + ) + + return values diff --git a/sale_stock_operating_unit/models/stock_warehouse.py b/sale_stock_operating_unit/models/stock_warehouse.py new file mode 100644 index 0000000000..da1f16d3b4 --- /dev/null +++ b/sale_stock_operating_unit/models/stock_warehouse.py @@ -0,0 +1,28 @@ +# Copyright 2015-19 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# Copyright 2015-19 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import api, models +from odoo.exceptions import ValidationError + + +class StockWarehouse(models.Model): + _inherit = "stock.warehouse" + + @api.constrains("operating_unit_id") + def _check_existing_so_in_wh(self): + for rec in self: + sales = self.env["sale.order"].search( + [ + ("warehouse_id", "=", rec.id), + ("operating_unit_id", "!=", rec.operating_unit_id.id), + ], + limit=1, + ) + if sales: + raise ValidationError( + self.env._( + "Sales Order records already exist(s) for this warehouse" + " and operating unit." + ) + ) diff --git a/sale_stock_operating_unit/pyproject.toml b/sale_stock_operating_unit/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/sale_stock_operating_unit/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_stock_operating_unit/readme/CONFIGURATION.rst b/sale_stock_operating_unit/readme/CONFIGURATION.rst new file mode 100644 index 0000000000..01a0841ee6 --- /dev/null +++ b/sale_stock_operating_unit/readme/CONFIGURATION.rst @@ -0,0 +1,2 @@ +Go to 'Settings / Technical / Actions / User-defined Defaults' and remove +the default set for the Shop. diff --git a/sale_stock_operating_unit/readme/CONTRIBUTORS.md b/sale_stock_operating_unit/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..d5beec9979 --- /dev/null +++ b/sale_stock_operating_unit/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- Eficent Business and IT Consulting Services S.L. + \<\> +- Serpent Consulting Services Pvt. Ltd. \<\> +- Alejandro Padrón \<\> +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/sale_stock_operating_unit/readme/DESCRIPTION.md b/sale_stock_operating_unit/readme/DESCRIPTION.md new file mode 100644 index 0000000000..60c409b7c2 --- /dev/null +++ b/sale_stock_operating_unit/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module was written to extend the Sales and the Stock capabilities +of Odoo. This module introduces some new operating unit (OU) +capabilities in order to enhance the performance of already existing OU +features for Sales and Stock. diff --git a/sale_stock_operating_unit/readme/USAGE.md b/sale_stock_operating_unit/readme/USAGE.md new file mode 100644 index 0000000000..d3133993c7 --- /dev/null +++ b/sale_stock_operating_unit/readme/USAGE.md @@ -0,0 +1,14 @@ +Follow these steps: + +1. Use a created Operating Unit (OU) or create one in Settings -\> + Users&Companies -\> Operating Units. +2. Use a created Sales Team or create a new one in Sales -\> + Configuration -\> Sales Team and assign an OU +3. Create a new Warehouse with the previous OU (or use a Warehouse with + an assigned OU) +4. Check the Location has the same OU as the Warehouse in Inventory -\> + Configuration Locations (make sure you have Storage Locations + checkbox activated) +5. Create a new Sale Order with the Sales Team, Operating Unit and + Warehouse used/created before. +6. OU, Picking Type and Location are propagated to the Picking. diff --git a/sale_stock_operating_unit/static/description/icon.png b/sale_stock_operating_unit/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/sale_stock_operating_unit/static/description/icon.png differ diff --git a/sale_stock_operating_unit/static/description/index.html b/sale_stock_operating_unit/static/description/index.html new file mode 100644 index 0000000000..3cc992c205 --- /dev/null +++ b/sale_stock_operating_unit/static/description/index.html @@ -0,0 +1,452 @@ + + + + + +Operating Unit in Sales Stock + + + +
+

Operating Unit in Sales Stock

+ + +

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

+

This module was written to extend the Sales and the Stock capabilities +of Odoo. This module introduces some new operating unit (OU) +capabilities in order to enhance the performance of already existing OU +features for Sales and Stock.

+

Table of contents

+ +
+

Usage

+

Follow these steps:

+
    +
  1. Use a created Operating Unit (OU) or create one in Settings -> +Users&Companies -> Operating Units.
  2. +
  3. Use a created Sales Team or create a new one in Sales -> +Configuration -> Sales Team and assign an OU
  4. +
  5. Create a new Warehouse with the previous OU (or use a Warehouse with +an assigned OU)
  6. +
  7. Check the Location has the same OU as the Warehouse in Inventory -> +Configuration Locations (make sure you have Storage Locations +checkbox activated)
  8. +
  9. Create a new Sale Order with the Sales Team, Operating Unit and +Warehouse used/created before.
  10. +
  11. OU, Picking Type and Location are propagated to the Picking.
  12. +
+
+
+

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

+
    +
  • Eficent
  • +
  • Serpent Consulting Services Pvt. Ltd.
  • +
+
+
+

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.

+

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/sale_stock_operating_unit/tests/__init__.py b/sale_stock_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..0d6189565e --- /dev/null +++ b/sale_stock_operating_unit/tests/__init__.py @@ -0,0 +1,2 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import test_sale_stock_operating_unit diff --git a/sale_stock_operating_unit/tests/test_sale_stock_operating_unit.py b/sale_stock_operating_unit/tests/test_sale_stock_operating_unit.py new file mode 100644 index 0000000000..20cd10bacf --- /dev/null +++ b/sale_stock_operating_unit/tests/test_sale_stock_operating_unit.py @@ -0,0 +1,55 @@ +# Copyright 2015-19 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# Copyright 2015-19 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + + +from odoo.addons.sale_operating_unit.tests.test_sale_operating_unit import ( + TestSaleOperatingUnit, +) +from odoo.addons.stock_operating_unit.tests.test_stock_operating_unit import ( + TestStockOperatingUnit, +) + + +class TestSaleStockOperatingUnit(TestStockOperatingUnit, TestSaleOperatingUnit): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Products + cls.stored_product = cls.env.ref("stock.product_cable_management_box") + cls.stored_product.write({"invoice_policy": "order"}) + + cls.sale3 = cls._create_sale_order( + cls.user1.id, + cls.customer, + cls.stored_product, + cls.pricelist, + cls.sale_team_ou1, + ) + cls.sale4 = cls._create_sale_order( + cls.user2.id, + cls.customer, + cls.stored_product, + cls.pricelist, + cls.sale_team_b2c, + ) + + def test_security(self): + """Test Sale Operating Unit""" + # Confirm Sale1 + self._confirm_sale(self.sale3) + # Checks that OU in sale order and stock picking matches or not. + self.assertEqual( + self.sale3.operating_unit_id, + self.sale3.picking_ids.operating_unit_id, + "OU in Sale Order and Picking should be same", + ) + # Confirm Sale2 + self._confirm_sale(self.sale4) + # Checks that OU in sale order and stock picking matches or not. + self.assertEqual( + self.sale4.operating_unit_id, + self.sale4.picking_ids.operating_unit_id, + "OU in Sale Order and Picking should be same", + ) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..b1c191281a --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,3 @@ +odoo-addon-sale_operating_unit @ git+https://github.com/OCA/operating-unit.git@refs/pull/756/head#subdirectory=sale_operating_unit +odoo-addon-account_operating_unit @ git+https://github.com/OCA/operating-unit.git@refs/pull/726/head#subdirectory=account_operating_unit +odoo-addon-sales_team_operating_unit @ git+https://github.com/OCA/operating-unit.git@refs/pull/729/head#subdirectory=sales_team_operating_unit