[FIX] stock: avoid inter-warehouse transfer only if planned

When using an internal transfer to move some products between two
warehouses, the forecasted inventory becomes incorrect

To reproduce the issue:
(Let WH01 be the existing warehouse)
1. In Settings, enable "Multi-Warehouses"
2. Create a second warehouse WH02
3. Create a storable product P
4. Update its quantity: 1 x P at WH01/Stock
5. Create a planned internal transfer (the warehouse does not matter):
    - Source: WH01/Stock
    - Destination: WH02/Stock
    - Operations:
        - 1 x P
6. Mark the transfer as Todo
7. Consult the Forecasted Inventory report:
    - Filters:
        - Forecasted Stock
        - Product: P
    - Group By:
        - Warehouse

Error: The line for WH02 is missing and the line for WH01 is incorrect
(qty is 1 for next days while it should be 0)

The report used (`report_stock_quantity`) does not handle this transfer.
Because both locations (source and destination) are defined, the SM is
not considered as an in-move or out-move:
https://github.com/odoo/odoo/blob/07f0ffad6ecc08f4165902db45ae96e4b41199e8/addons/stock/report/report_stock_quantity.py#L38-L43
Moreover, it would be hard to change the SQL view to generate two lines
(one 'in' and one 'out') from the same SM (the internal move).

The graph on the forecasted report of product P is also incorrect (it
uses `report_stock_quantity` to get the data, so if the user selects a
specific warehouse in the filters, the result will be incorrect)

So, the user should only avoid to transfer some products between two
warehouses if the internal transfer is a planned one.

OPW-2752017

closes odoo/odoo#87965

X-original-commit: 7f56063f6fe63a70d3e23b9c5fb486cc0958dd3e
Signed-off-by: Adrien Widart <awt@odoo.com>
Signed-off-by: Arnold Moyaux <arm@odoo.com>
This commit is contained in:
Adrien Widart
2022-04-06 09:05:51 +02:00
parent 484077ef6f
commit dec47d8459
2 changed files with 18 additions and 0 deletions
+9
View File
@@ -8895,6 +8895,15 @@ msgstr ""
msgid "You need to supply a Lot/Serial number for products %s."
msgstr ""
#. module: stock
#: code:addons/stock/models/stock_picking.py:0
#, python-format
msgid ""
"You should not use a planned internal transfer to move some products between"
" two warehouses. Instead, use an immediate internal transfer or the resupply"
" route."
msgstr ""
#. module: stock
#: code:addons/stock/models/stock_warehouse.py:0
#, python-format
+9
View File
@@ -720,6 +720,15 @@ class Picking(models.Model):
@api.onchange('location_id', 'location_dest_id')
def _onchange_locations(self):
from_wh = self.location_id.warehouse_id
to_wh = self.location_dest_id.warehouse_id
is_immediate = self.immediate_transfer if self._origin else self._context.get('default_immediate_transfer')
if self.picking_type_id.code == 'internal' and not is_immediate and from_wh and to_wh and from_wh != to_wh:
return {'warning': {
'title': _("Warning"),
'message': _("You should not use a planned internal transfer to move some products between two warehouses. "
"Instead, use an immediate internal transfer or the resupply route.")
}}
(self.move_ids | self.move_ids_without_package).update({
"location_id": self.location_id,
"location_dest_id": self.location_dest_id