diff --git a/sale_stock_warehouse_multicompany/README.rst b/sale_stock_warehouse_multicompany/README.rst new file mode 100644 index 00000000000..88c102f5fb4 --- /dev/null +++ b/sale_stock_warehouse_multicompany/README.rst @@ -0,0 +1,98 @@ +================================= +sale stock warehouse multicompany +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:67949d6668369459da869bf2f201763a4fb3122e67d4a284a2bba1e044d75edf + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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%2Fmulti--company-lightgray.png?logo=github + :target: https://github.com/OCA/multi-company/tree/18.0/sale_stock_warehouse_multicompany + :alt: OCA/multi-company +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/multi-company-18-0/multi-company-18-0-sale_stock_warehouse_multicompany + :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/multi-company&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Allow multiple companies to sell the stock of a shared warehouse. + +The sales order will belong to the company making the sale. As such, the +taxes and related invoices will also belong to that selling company. The +generated stock moves will belong to the company owning the stock and +defined on the warehouse. + +This approach also allows to use any route (like cross-docking or +drop-shipment) on the sales order line. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +On the warehouse select the companies that are allowed to sell the +stock. + +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 +------- + +* Camptocamp +* BCIM + +Contributors +------------ + +- Telmo Santos +- Jacques-Etienne Baudoux (BCIM) +- Cyril Manuel Jeanneret + +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/multi-company `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_stock_warehouse_multicompany/__init__.py b/sale_stock_warehouse_multicompany/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_stock_warehouse_multicompany/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_stock_warehouse_multicompany/__manifest__.py b/sale_stock_warehouse_multicompany/__manifest__.py new file mode 100644 index 00000000000..b450fc5f613 --- /dev/null +++ b/sale_stock_warehouse_multicompany/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "sale stock warehouse multicompany", + "summary": "Allow multiple companies to sell the stock of a shared warehouse", + "version": "18.0.1.0.0", + "development_status": "Alpha", + "category": "Warehouse Management", + "website": "https://github.com/OCA/multi-company", + "author": "Camptocamp, BCIM, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["delivery"], + "data": [ + "views/stock_warehouse_views.xml", + "views/stock_route_views.xml", + ], +} diff --git a/sale_stock_warehouse_multicompany/i18n/it.po b/sale_stock_warehouse_multicompany/i18n/it.po new file mode 100644 index 00000000000..cba30881238 --- /dev/null +++ b/sale_stock_warehouse_multicompany/i18n/it.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_stock_warehouse_multicompany +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-04-02 12:35+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_warehouse_multicompany +#: model:ir.model.fields,field_description:sale_stock_warehouse_multicompany.field_stock_route__company_ids +#: model:ir.model.fields,field_description:sale_stock_warehouse_multicompany.field_stock_warehouse__company_ids +msgid "Companies" +msgstr "Aziende" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model,name:sale_stock_warehouse_multicompany.model_stock_route +msgid "Inventory Routes" +msgstr "Percorsi di inventario" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model.fields,field_description:sale_stock_warehouse_multicompany.field_sale_order_line__route_id +msgid "Route" +msgstr "Percorso" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model,name:sale_stock_warehouse_multicompany.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model,name:sale_stock_warehouse_multicompany.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model,name:sale_stock_warehouse_multicompany.model_stock_warehouse +#: model:ir.model.fields,field_description:sale_stock_warehouse_multicompany.field_sale_order__warehouse_id +msgid "Warehouse" +msgstr "Magazzino" diff --git a/sale_stock_warehouse_multicompany/i18n/sale_stock_warehouse_multicompany.pot b/sale_stock_warehouse_multicompany/i18n/sale_stock_warehouse_multicompany.pot new file mode 100644 index 00000000000..8f7b6d01453 --- /dev/null +++ b/sale_stock_warehouse_multicompany/i18n/sale_stock_warehouse_multicompany.pot @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_stock_warehouse_multicompany +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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_warehouse_multicompany +#: model:ir.model.fields,field_description:sale_stock_warehouse_multicompany.field_stock_route__company_ids +#: model:ir.model.fields,field_description:sale_stock_warehouse_multicompany.field_stock_warehouse__company_ids +msgid "Companies" +msgstr "" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model,name:sale_stock_warehouse_multicompany.model_stock_route +msgid "Inventory Routes" +msgstr "" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model.fields,field_description:sale_stock_warehouse_multicompany.field_sale_order_line__route_id +msgid "Route" +msgstr "" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model,name:sale_stock_warehouse_multicompany.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model,name:sale_stock_warehouse_multicompany.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: sale_stock_warehouse_multicompany +#: model:ir.model,name:sale_stock_warehouse_multicompany.model_stock_warehouse +#: model:ir.model.fields,field_description:sale_stock_warehouse_multicompany.field_sale_order__warehouse_id +msgid "Warehouse" +msgstr "" diff --git a/sale_stock_warehouse_multicompany/models/__init__.py b/sale_stock_warehouse_multicompany/models/__init__.py new file mode 100644 index 00000000000..861cff8675e --- /dev/null +++ b/sale_stock_warehouse_multicompany/models/__init__.py @@ -0,0 +1,4 @@ +from . import stock_warehouse +from . import sale_order +from . import sale_order_line +from . import stock_route diff --git a/sale_stock_warehouse_multicompany/models/sale_order.py b/sale_stock_warehouse_multicompany/models/sale_order.py new file mode 100644 index 00000000000..768a5eafce0 --- /dev/null +++ b/sale_stock_warehouse_multicompany/models/sale_order.py @@ -0,0 +1,14 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + warehouse_id = fields.Many2one( + "stock.warehouse", + domain="[('company_ids', 'in', company_id)]", + check_company=False, + ) diff --git a/sale_stock_warehouse_multicompany/models/sale_order_line.py b/sale_stock_warehouse_multicompany/models/sale_order_line.py new file mode 100644 index 00000000000..d4a9fdabecd --- /dev/null +++ b/sale_stock_warehouse_multicompany/models/sale_order_line.py @@ -0,0 +1,21 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + route_id = fields.Many2one( + "stock.route", + domain="[('company_ids', 'in', company_id),('sale_selectable','=', True)]", + check_company=False, + ) + + def _prepare_procurement_values(self, group_id=False): + values = super()._prepare_procurement_values(group_id=group_id) + # Procurements must be created in warehouse company + if self.order_id.warehouse_id: + values["company_id"] = self.order_id.warehouse_id.company_id + return values diff --git a/sale_stock_warehouse_multicompany/models/stock_route.py b/sale_stock_warehouse_multicompany/models/stock_route.py new file mode 100644 index 00000000000..09fc87a4edc --- /dev/null +++ b/sale_stock_warehouse_multicompany/models/stock_route.py @@ -0,0 +1,21 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models +from odoo.fields import Command + + +class StockRoute(models.Model): + _inherit = "stock.route" + + company_ids = fields.Many2many( + "res.company", + string="Companies", + compute="_compute_company_ids", + store=True, + readonly=False, + ) + + def _compute_company_ids(self): + for route in self: + route.company_ids = [Command.set(route.company_id.ids)] diff --git a/sale_stock_warehouse_multicompany/models/stock_warehouse.py b/sale_stock_warehouse_multicompany/models/stock_warehouse.py new file mode 100644 index 00000000000..5f1de049fd0 --- /dev/null +++ b/sale_stock_warehouse_multicompany/models/stock_warehouse.py @@ -0,0 +1,21 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models +from odoo.fields import Command + + +class Warehouse(models.Model): + _inherit = "stock.warehouse" + + company_ids = fields.Many2many( + "res.company", + string="Companies", + compute="_compute_company_ids", + store=True, + readonly=False, + ) + + def _compute_company_ids(self): + for warehouse in self: + warehouse.company_ids = [Command.set(warehouse.company_id.ids)] diff --git a/sale_stock_warehouse_multicompany/pyproject.toml b/sale_stock_warehouse_multicompany/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_stock_warehouse_multicompany/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_stock_warehouse_multicompany/readme/CONFIGURE.md b/sale_stock_warehouse_multicompany/readme/CONFIGURE.md new file mode 100644 index 00000000000..e5045dd62b4 --- /dev/null +++ b/sale_stock_warehouse_multicompany/readme/CONFIGURE.md @@ -0,0 +1,2 @@ +On the warehouse select the companies that are allowed to sell the +stock. diff --git a/sale_stock_warehouse_multicompany/readme/CONTRIBUTORS.md b/sale_stock_warehouse_multicompany/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..07d09e703b8 --- /dev/null +++ b/sale_stock_warehouse_multicompany/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Telmo Santos \<\> +- Jacques-Etienne Baudoux (BCIM) \<\> +- Cyril Manuel Jeanneret \<\> diff --git a/sale_stock_warehouse_multicompany/readme/DESCRIPTION.md b/sale_stock_warehouse_multicompany/readme/DESCRIPTION.md new file mode 100644 index 00000000000..ead8b5881be --- /dev/null +++ b/sale_stock_warehouse_multicompany/readme/DESCRIPTION.md @@ -0,0 +1,9 @@ +Allow multiple companies to sell the stock of a shared warehouse. + +The sales order will belong to the company making the sale. As such, the +taxes and related invoices will also belong to that selling company. The +generated stock moves will belong to the company owning the stock and +defined on the warehouse. + +This approach also allows to use any route (like cross-docking or +drop-shipment) on the sales order line. diff --git a/sale_stock_warehouse_multicompany/static/description/icon.png b/sale_stock_warehouse_multicompany/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_stock_warehouse_multicompany/static/description/icon.png differ diff --git a/sale_stock_warehouse_multicompany/static/description/index.html b/sale_stock_warehouse_multicompany/static/description/index.html new file mode 100644 index 00000000000..1d54aadc012 --- /dev/null +++ b/sale_stock_warehouse_multicompany/static/description/index.html @@ -0,0 +1,444 @@ + + + + + +sale stock warehouse multicompany + + + +
+

sale stock warehouse multicompany

+ + +

Alpha License: AGPL-3 OCA/multi-company Translate me on Weblate Try me on Runboat

+

Allow multiple companies to sell the stock of a shared warehouse.

+

The sales order will belong to the company making the sale. As such, the +taxes and related invoices will also belong to that selling company. The +generated stock moves will belong to the company owning the stock and +defined on the warehouse.

+

This approach also allows to use any route (like cross-docking or +drop-shipment) on the sales order line.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

On the warehouse select the companies that are allowed to sell the +stock.

+
+
+

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

+
    +
  • Camptocamp
  • +
  • BCIM
  • +
+
+
+

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/multi-company project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_stock_warehouse_multicompany/tests/__init__.py b/sale_stock_warehouse_multicompany/tests/__init__.py new file mode 100644 index 00000000000..7502515514a --- /dev/null +++ b/sale_stock_warehouse_multicompany/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_stock_warehouse_multicompany diff --git a/sale_stock_warehouse_multicompany/tests/test_sale_stock_warehouse_multicompany.py b/sale_stock_warehouse_multicompany/tests/test_sale_stock_warehouse_multicompany.py new file mode 100644 index 00000000000..b6767fd94ca --- /dev/null +++ b/sale_stock_warehouse_multicompany/tests/test_sale_stock_warehouse_multicompany.py @@ -0,0 +1,64 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.fields import Command +from odoo.tests import Form, common + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +class TestPartnerMultiCompany(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env["base"].with_context(**DISABLED_MAIL_CONTEXT).env + + cls.company_1 = cls.env["res.company"].create({"name": "Test company 1"}) + cls.company_2 = cls.env["res.company"].create({"name": "Test company 2"}) + cls.warehouse_1 = cls.env["stock.warehouse"].create( + { + "name": "Base Warehouse", + "reception_steps": "one_step", + "delivery_steps": "ship_only", + "code": "BWH", + "company_ids": [Command.set((cls.company_2 + cls.company_1).ids)], + } + ) + cls.product = cls.env["product.product"].create( + { + "name": "test_product", + "type": "consu", + "invoice_policy": "delivery", + "is_storable": True, + } + ) + cls.env["stock.quant"].with_context(inventory_mode=True).create( + { + "location_id": cls.warehouse_1.wh_output_stock_loc_id.id, + "product_id": cls.product.id, + "quantity": 10.0, + } + )._apply_inventory() + + def test_sale_stock_warehouse_multicompany(self): + self.env.user.company_id = self.company_2 + + # Test company 2 create and confirm order + with Form(self.env["sale.order"]) as order_form: + order_form.partner_id = self.env.ref("base.res_partner_12") + order_form.warehouse_id = self.warehouse_1 + with order_form.order_line.new() as line_form: + line_form.product_id = self.product + line_form.product_uom_qty = 1 + self.order = order_form.save() + self.order.action_confirm() + + # Test company 1 process logitic steps from warehouse_1 + self.env.user.company_id = self.company_1 + stock_location = self.warehouse_1.lot_stock_id + self.assertEqual(self.order.picking_ids.location_id, stock_location) + # Process picking + self.order.picking_ids.move_ids_without_package.quantity = 1.0 + self.order.picking_ids.button_validate() + + self.assertEqual(self.order.order_line.qty_delivered, 1.0) diff --git a/sale_stock_warehouse_multicompany/views/stock_route_views.xml b/sale_stock_warehouse_multicompany/views/stock_route_views.xml new file mode 100644 index 00000000000..79bec1b9789 --- /dev/null +++ b/sale_stock_warehouse_multicompany/views/stock_route_views.xml @@ -0,0 +1,17 @@ + + + + stock.location.route.form.inherit + stock.route + + + + + + + + diff --git a/sale_stock_warehouse_multicompany/views/stock_warehouse_views.xml b/sale_stock_warehouse_multicompany/views/stock_warehouse_views.xml new file mode 100644 index 00000000000..075561cd1ae --- /dev/null +++ b/sale_stock_warehouse_multicompany/views/stock_warehouse_views.xml @@ -0,0 +1,17 @@ + + + + stock.warehouse.form.inherit + stock.warehouse + + + + + + + +