diff --git a/sale_stock_operating_unit/README.rst b/sale_stock_operating_unit/README.rst new file mode 100644 index 0000000000..435b6d21eb --- /dev/null +++ b/sale_stock_operating_unit/README.rst @@ -0,0 +1,98 @@ +============================= +Operating Unit in Sales Stock +============================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-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/16.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-16-0/operating-unit-16-0-sale_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 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: + +#. Use a created Operating Unit (OU) or create one in Settings -> + Users&Companies -> Operating + Units. +#. Use a created Sales Team or create a new one in Sales -> Configuration -> + Sales Team and assign an OU +#. Create a new Warehouse with the previous OU (or use a Warehouse with an + assigned OU) +#. Check the Location has the same OU as the Warehouse in Inventory -> + Configuration Locations (make sure you have Storage Locations checkbox + activated) +#. Create a new Sale Order with the Sales Team, Operating Unit and Warehouse + used/created before. +#. 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 smashing 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 +* 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. + +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..09d328cbfc --- /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": "16.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..71a9a80a9a --- /dev/null +++ b/sale_stock_operating_unit/i18n/it.po @@ -0,0 +1,55 @@ +# 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-06-12 11:09+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 +#: 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 "" + +#. module: sale_stock_operating_unit +#: 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 +#: model:ir.model.fields,field_description:sale_stock_operating_unit.field_sale_order__warehouse_id +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..68d9614b65 --- /dev/null +++ b/sale_stock_operating_unit/i18n/pt.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: 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 +#: 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 +#: 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 +#: model:ir.model.fields,field_description:sale_stock_operating_unit.field_sale_order__warehouse_id +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..d79ec3b97a --- /dev/null +++ b/sale_stock_operating_unit/i18n/sale_stock_operating_unit.pot @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_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: sale_stock_operating_unit +#: 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 +#: 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 +#: model:ir.model.fields,field_description:sale_stock_operating_unit.field_sale_order__warehouse_id +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..82374d1641 --- /dev/null +++ b/sale_stock_operating_unit/models/__init__.py @@ -0,0 +1,5 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import res_users +from . import sale_order +from . import stock_move +from . import stock_warehouse diff --git a/sale_stock_operating_unit/models/res_users.py b/sale_stock_operating_unit/models/res_users.py new file mode 100644 index 0000000000..1bc4a67350 --- /dev/null +++ b/sale_stock_operating_unit/models/res_users.py @@ -0,0 +1,20 @@ +# Copyright 2023 Jarsa +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import models + + +class ResUsers(models.Model): + _inherit = "res.users" + + def _get_default_warehouse_id(self): + warehouse = self.env["stock.warehouse"].search( + [ + ("company_id", "=", self.env.company.id), + ("operating_unit_id", "=", self.env.user.default_operating_unit_id.id), + ], + limit=1, + ) + if not warehouse: + return super()._get_default_warehouse_id() + return 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..d8699951c9 --- /dev/null +++ b/sale_stock_operating_unit/models/sale_order.py @@ -0,0 +1,62 @@ +# 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.onchange("team_id") + def _onchange_team_id(self): + if ( + self.team_id + and self.team_id.operating_unit_id + and self.team_id.operating_unit_id.id + != self.warehouse_id.operating_unit_id.id + ): + warehouses = self.env["stock.warehouse"].search( + [("operating_unit_id", "=", self.team_id.operating_unit_id.id)], limit=1 + ) + if warehouses: + self.warehouse_id = warehouses[0] + + @api.onchange("operating_unit_id") + def _onchange_operating_unit_id(self): + if ( + self.operating_unit_id + and self.operating_unit_id.id != self.warehouse_id.operating_unit_id.id + ): + warehouses = self.env["stock.warehouse"].search( + [("operating_unit_id", "=", self.operating_unit_id.id)], limit=1 + ) + if warehouses: + self.warehouse_id = warehouses[0] + + @api.onchange("warehouse_id") + def _onchange_warehouse_id(self): + if self.warehouse_id: + self.operating_unit_id = self.warehouse_id.operating_unit_id + if ( + self.team_id + and self.team_id.operating_unit_id != self.operating_unit_id + ): + self.team_id = False + + @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( + _( + "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..f41c446ee7 --- /dev/null +++ b/sale_stock_operating_unit/models/stock_warehouse.py @@ -0,0 +1,27 @@ +# 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), + ] + ) + if sales: + raise ValidationError( + _( + "Sales Order records already exist(s) for this warehouse" + " and operating unit." + ) + ) 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.rst b/sale_stock_operating_unit/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..b6987b7d99 --- /dev/null +++ b/sale_stock_operating_unit/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Eficent Business and IT Consulting Services S.L. +* Serpent Consulting Services Pvt. Ltd. +* Alejandro Padrón +* Alan Ramos diff --git a/sale_stock_operating_unit/readme/DESCRIPTION.rst b/sale_stock_operating_unit/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..4a1bbe58ae --- /dev/null +++ b/sale_stock_operating_unit/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +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.rst b/sale_stock_operating_unit/readme/USAGE.rst new file mode 100644 index 0000000000..ccc5f3babe --- /dev/null +++ b/sale_stock_operating_unit/readme/USAGE.rst @@ -0,0 +1,15 @@ +Follow these steps: + +#. Use a created Operating Unit (OU) or create one in Settings -> + Users&Companies -> Operating + Units. +#. Use a created Sales Team or create a new one in Sales -> Configuration -> + Sales Team and assign an OU +#. Create a new Warehouse with the previous OU (or use a Warehouse with an + assigned OU) +#. Check the Location has the same OU as the Warehouse in Inventory -> + Configuration Locations (make sure you have Storage Locations checkbox + activated) +#. Create a new Sale Order with the Sales Team, Operating Unit and Warehouse + used/created before. +#. 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..42bae34865 --- /dev/null +++ b/sale_stock_operating_unit/static/description/index.html @@ -0,0 +1,445 @@ + + + + + + +Operating Unit in Sales Stock + + + +
+

Operating Unit in Sales Stock

+ + +

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

+

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 smashing 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..819b75fe9b --- /dev/null +++ b/sale_stock_operating_unit/tests/test_sale_stock_operating_unit.py @@ -0,0 +1,151 @@ +# 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.tests import common + + +class TestSaleStockOperatingUnit(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.res_groups = cls.env["res.groups"] + cls.res_users_model = cls.env["res.users"] + cls.warehouse_model = cls.env["stock.warehouse"] + cls.sale_model = cls.env["sale.order"] + cls.sale_line_model = cls.env["sale.order.line"] + cls.sale_team_model = cls.env["crm.team"] + # Company + cls.company = cls.env.ref("base.main_company") + # Groups + cls.grp_sale_user = cls.env.ref("sales_team.group_sale_manager") + cls.grp_acc_user = cls.env.ref("account.group_account_invoice") + # Main Operating Unit + cls.ou1 = cls.env.ref("operating_unit.main_operating_unit") + # B2C Operating Unit + cls.b2c = cls.env.ref("operating_unit.b2c_operating_unit") + # Customer + cls.customer = cls.env.ref("base.res_partner_2") + # Price list + cls.pricelist = cls.env.ref("product.list0") + # Products + cls.product1 = cls.env.ref("product.product_product_7") + cls.product1.write({"invoice_policy": "order"}) + # Create user1 + cls.user1 = cls._create_user( + "user_1", + [cls.grp_sale_user, cls.grp_acc_user], + cls.company, + [cls.ou1, cls.b2c], + ) + # Create user2 + cls.user2 = cls._create_user( + "user_2", [cls.grp_sale_user, cls.grp_acc_user], cls.company, [cls.b2c] + ) + + # Create sales team OU1 + cls.sale_team_ou1 = cls._create_sale_team(cls.user1.id, cls.ou1) + + # Create sales team OU2 + cls.sale_team_b2c = cls._create_sale_team(cls.user2.id, cls.b2c) + + # Warehouses + cls.ou1_wh = cls.env.ref("stock.warehouse0") + cls.b2c_wh = cls.env.ref("stock_operating_unit.stock_warehouse_b2c") + # Locations + cls.b2c_wh.lot_stock_id.write( + {"company_id": cls.company.id, "operating_unit_id": cls.b2c.id} + ) + + # Create Sale Order1 + cls.sale1 = cls._create_sale_order( + cls.user1.id, + cls.customer, + cls.product1, + cls.pricelist, + cls.sale_team_ou1, + cls.ou1_wh, + ) + # Create Sale Order2 + cls.sale2 = cls._create_sale_order( + cls.user2.id, + cls.customer, + cls.product1, + cls.pricelist, + cls.sale_team_b2c, + cls.b2c_wh, + ) + + @classmethod + def _create_user(cls, login, groups, company, operating_units): + """Create a user.""" + group_ids = [group.id for group in groups] + user = cls.res_users_model.create( + { + "name": "Test Sales User", + "login": login, + "password": "demo", + "email": "example@yourcompany.com", + "company_id": company.id, + "company_ids": [(4, company.id)], + "operating_unit_ids": [(4, ou.id) for ou in operating_units], + "groups_id": [(6, 0, group_ids)], + } + ) + return user + + @classmethod + def _create_sale_team(cls, uid, operating_unit): + """Create a sale team.""" + team = ( + cls.sale_team_model.with_user(uid) + .with_context(mail_create_nosubscribe=True) + .create( + {"name": operating_unit.name, "operating_unit_id": operating_unit.id} + ) + ) + return team + + @classmethod + def _create_sale_order(cls, uid, customer, product, pricelist, team, wh): + """Create a sale order.""" + sale = cls.sale_model.with_user(uid).create( + { + "partner_id": customer.id, + "partner_invoice_id": customer.id, + "partner_shipping_id": customer.id, + "pricelist_id": pricelist.id, + "team_id": team.id, + "operating_unit_id": team.operating_unit_id.id, + "warehouse_id": wh.id, + } + ) + cls.sale_line_model.with_user(uid).create( + {"order_id": sale.id, "product_id": product.id, "name": "Sale Order Line"} + ) + return sale + + @classmethod + def _confirm_sale(cls, sale): + sale.action_confirm() + return True + + def test_security(self): + """Test Sale Operating Unit""" + # Confirm Sale1 + self._confirm_sale(self.sale1) + # Checks that OU in sale order and stock picking matches or not. + self.assertEqual( + self.sale1.operating_unit_id, + self.sale1.picking_ids.operating_unit_id, + "OU in Sale Order and Picking should be same", + ) + # Confirm Sale2 + self._confirm_sale(self.sale2) + # Checks that OU in sale order and stock picking matches or not. + self.assertEqual( + self.sale2.operating_unit_id, + self.sale2.picking_ids.operating_unit_id, + "OU in Sale Order and Picking should be same", + ) diff --git a/setup/sale_stock_operating_unit/odoo/addons/sale_stock_operating_unit b/setup/sale_stock_operating_unit/odoo/addons/sale_stock_operating_unit new file mode 120000 index 0000000000..9f5ec43e9d --- /dev/null +++ b/setup/sale_stock_operating_unit/odoo/addons/sale_stock_operating_unit @@ -0,0 +1 @@ +../../../../sale_stock_operating_unit \ No newline at end of file diff --git a/setup/sale_stock_operating_unit/setup.py b/setup/sale_stock_operating_unit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/sale_stock_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)