Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions sale_order_line_multi_warehouse/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
===============================
Sale Order Line Multi Warehouse
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2c9466792ac5c98a547be1e21f46abc8416d09b97355bfe600145b595b09213f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/16.0/sale_order_line_multi_warehouse
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_order_line_multi_warehouse
: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/sale-workflow&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to select multiple warehouses in sale order lines so the sale order is split into multiple pickings depending on the warehouses selected in the lines.

**Table of contents**

.. contents::
:local:

Configuration
=============

To activate the sale orders multi-warehouse options you need to:

#. Go to Inventory > Configuration > Settings.
#. Activate the "Multi Warehouse in Sale Orders" option, under the "Warehouse" section. This field is only visible for users in group "Inventory / Administrator". When a sale order is created, multi warehouse options in sale order lines will be enabled/disabled depending on the value in this field on creation.

It is necessary to set alternative warehouses to a warehouse so they can be selected in sale order lines when the warehouse is set in the "Warehouse" field in a sale order. To set alternative warehouses you need to:

#. Go to Inventory > Configuration > Warehouses and see a warehouse's form view.
#. Select the warehouse's alternative warehouses in the "Altenative Warehouses" field. This field is only visible for users in group "Inventory / Administrator".
Comment thread
manuelregidor marked this conversation as resolved.

Usage
=====

* To split a sale order line into multiple warehouses you need to click on the tree graph icon in a sale order line. A popup will open, where warehouses and quantities can be selected. Only the warehouses set in the "Alternative Warehouses" field in the warehouse set in the sale order can be selected. Sale order line quantity and its warehouse distributions line quantities are synchronized as follows:
* When quantity is increased in a sale order line:
* In case there is a warehouse distribution line related to the warehouse set in the sale order, the increased quantity is added to the quantity in this warehouse fistribution line.
* In case there is not a warehouse distribution line related to the warehouse set in the sale order, a new warehouse distribution line related to the warehouse set in the sale order is created containing the increased amount.
* When quantity is decreased in a sale order line:
* In case there is a warehouse distribution line related to the warehouse set in the sale order, the decreased quantity is substracted from the quantity amount in this warehouse distribution line. When the amount set in this warehouse distribution line is not enough, the pending amount is randomly substracted from the rest of warehouse distribution lines.
* In case there is not a warehouse distribution line related to the warehouse set in the sale order, the decreased quantity is randomly subsctracted from the available warehouse distribution lines.
* When quantity is modified in a warehouse distribution line, the amount in the sale order line is automatically updated so it matches the total amount in the sale warehouse distribution lines.

* When the multi warehouse options in sale order lines are enabled, changing the general sale order warehouse needs to be done through a wizard, located in the "Other Info" tab, in the "Delivery" section. The button is only visible for users in group "Technical / Manage Multiple Warehouses".

* A sale order line cannot have multiple warehouse distribution lines related to the same warehouse.

* Once the sale order is validated, the order will be split into multiple pickings, one for each warehouse selected in the warehouse distribution lines.

* **IMPORTANT: In case this module is uninstalled, the warehouse distribution lines will be lost.**

Known issues / Roadmap
======================

* The warehouse distribution lines display could be improved in the future so it looks similar to the pop up used for analytic distribution.

* Module sale_procurement_group_by_line should not be used along with this module as it provides the base to split sale order lines depending on different criteria, which might make sale_order_line_multi_warehouse module malfunction.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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 <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_order_line_multi_warehouse%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Sygel

Contributors
~~~~~~~~~~~~

* Manuel Regidor <manuel.regidor@sygel.es>
* Valentín Vinagre <valentin.vinagre@sygel.es>

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/sale-workflow <https://github.com/OCA/sale-workflow/tree/16.0/sale_order_line_multi_warehouse>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions sale_order_line_multi_warehouse/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2021 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
from . import wizard
26 changes: 26 additions & 0 deletions sale_order_line_multi_warehouse/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2021 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Sale Order Line Multi Warehouse",
"summary": "Sale Order Line Multi Warehouse",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Sales",
"website": "https://github.com/OCA/sale-workflow",
Comment thread
manuelregidor marked this conversation as resolved.
"author": "Sygel, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"sale_stock",
],
"data": [
"security/ir.model.access.csv",
"views/stock_warehouse_views.xml",
"views/sale_order_line_warehouse_views.xml",
"views/sale_order_views.xml",
"views/res_config_settings_views.xml",
"wizard/so_multi_warehouse_change_wizard_views.xml",
],
}
11 changes: 11 additions & 0 deletions sale_order_line_multi_warehouse/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import stock_warehouse
from . import sale_order_line_warehouse
from . import sale_order_line
from . import sale_order
from . import stock_move
from . import stock_rule
from . import res_company
from . import res_config_settings
10 changes: 10 additions & 0 deletions sale_order_line_multi_warehouse/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2024 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

allow_sale_multi_warehouse = fields.Boolean()
14 changes: 14 additions & 0 deletions sale_order_line_multi_warehouse/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

allow_sale_multi_warehouse = fields.Boolean(
related="company_id.allow_sale_multi_warehouse",
string="Multi Warehouse in Sale Orders",
readonly=False,
)
61 changes: 61 additions & 0 deletions sale_order_line_multi_warehouse/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2024 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class SaleOrder(models.Model):
_inherit = "sale.order"

allow_sale_multi_warehouse = fields.Boolean(
related="company_id.allow_sale_multi_warehouse", store=True
)
suitable_warehouse_ids = fields.Many2many(
string="Suitable Warehouses",
comodel_name="stock.warehouse",
compute="_compute_suitable_warehouse_ids",
)

@api.depends("warehouse_id")
def _compute_suitable_warehouse_ids(self):
for order in self:
order.suitable_warehouse_ids = (
order.warehouse_id + order.warehouse_id.alternative_warehouse_ids
)

def get_incompatible_multi_warehouse_lines(self, warehouse):
self.ensure_one()
compatible_warehouse_ids = warehouse + warehouse.alternative_warehouse_ids
return self.order_line.mapped("sale_order_line_warehouse_ids").filtered(
lambda a: a.warehouse_id.id not in compatible_warehouse_ids.ids
)

def _action_confirm(self):
for order in self:
if order.get_incompatible_multi_warehouse_lines(self.warehouse_id):
raise ValidationError(

Check warning on line 37 in sale_order_line_multi_warehouse/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_order_line_multi_warehouse/models/sale_order.py#L37

Added line #L37 was not covered by tests
_(
"Some sale order line assignment lines are not compatible with "
"the selected warehouse. Quotation %(order)s could not be validated.",
order=order.name,
)
)
return super()._action_confirm()

def action_open_so_multi_warehouse_change(self):
self.ensure_one()
view_id = self.env.ref(

Check warning on line 48 in sale_order_line_multi_warehouse/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_order_line_multi_warehouse/models/sale_order.py#L47-L48

Added lines #L47 - L48 were not covered by tests
"sale_order_line_multi_warehouse.so_multi_warehouse_change_wizard_view"
)
ctx = {

Check warning on line 51 in sale_order_line_multi_warehouse/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_order_line_multi_warehouse/models/sale_order.py#L51

Added line #L51 was not covered by tests
"default_sale_order_id": self.id,
}
return {

Check warning on line 54 in sale_order_line_multi_warehouse/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_order_line_multi_warehouse/models/sale_order.py#L54

Added line #L54 was not covered by tests
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": "so.multi.warehouse.change.wizard",
"target": "new",
"view_id": view_id.id,
"context": ctx,
}
Loading