Skip to content

Commit 45aef84

Browse files
committed
fixup! [MIG] stock_picking_type_shipping_policy: Migration to 18.0
1 parent 14a2bde commit 45aef84

File tree

9 files changed

+73
-50
lines changed

9 files changed

+73
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2025 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
3+
import logging
4+
5+
from odoo import tools
6+
7+
_logger = logging.getLogger(__name__)
8+
9+
10+
def migrate(cr, version):
11+
if not version:
12+
return
13+
migrate_stock_picking_type_shipping_policy(cr)
14+
15+
16+
def migrate_stock_picking_type_shipping_policy(cr):
17+
_logger.info("Create 'stock_picking_type.force_move_type' column...")
18+
tools.sql.create_column(cr, "stock_picking_type", "force_move_type", "boolean")
19+
_logger.info("Update operation types configuration...")
20+
# Odoo 18.0 comes with a new '<stock.picking.type>.move_type' field sets
21+
# by default to 'direct' (= As soon as possible).
22+
# If the current module is installed, we want this field sets with the
23+
# value that was configured in old field 'shipping_policy'.
24+
queries = [
25+
"""
26+
UPDATE stock_picking_type
27+
SET force_move_type=true, move_type='direct'
28+
WHERE shipping_policy='force_as_soon_as_possible';
29+
""",
30+
"""
31+
UPDATE stock_picking_type
32+
SET force_move_type=true, move_type='one'
33+
WHERE shipping_policy='force_all_products_ready';
34+
""",
35+
]
36+
for query in queries:
37+
cr.execute(query)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from . import stock_move
1+
from . import stock_picking
22
from . import stock_picking_type

stock_picking_type_shipping_policy/models/stock_move.py

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2025 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
3+
from odoo import models
4+
5+
6+
class StockPicking(models.Model):
7+
_inherit = "stock.picking"
8+
9+
def _compute_move_type(self):
10+
# pylint: disable=missing-return
11+
super()._compute_move_type()
12+
for record in self:
13+
if record.picking_type_id.force_move_type:
14+
record.move_type = record.picking_type_id.move_type
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
# Copyright 2020 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
3-
from odoo import api, fields, models
3+
from odoo import fields, models
44

55

66
class StockPickingType(models.Model):
77
_inherit = "stock.picking.type"
88

9-
@api.model
10-
def _default_shipping_policy(self):
11-
return "procurement_group"
12-
13-
@api.model
14-
def _selection_shipping_policy(self):
15-
return [
16-
("procurement_group", "Take from procurement group"),
17-
("force_as_soon_as_possible", "Force to as soon as possible"),
18-
("force_all_products_ready", "Force to when all products are ready"),
19-
]
20-
21-
shipping_policy = fields.Selection(
9+
force_move_type = fields.Boolean(
2210
string="Force Shipping Policy",
23-
selection="_selection_shipping_policy",
24-
default=lambda r: r._default_shipping_policy(),
25-
help="Allows to force the shipping policy on pickings according to the"
26-
" picking type.",
11+
help=(
12+
"Force the shipping policy of the operation type "
13+
"(ignore the one from procurement group)"
14+
),
15+
default=False,
2716
)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Akim Juillerat \<<akim.juillerat@camptocamp.com>\>
22
- Phuc Tran Thanh \<<phuc@trobz.com>\>
3+
- Sébastien Alix \<<sebastien.alix@camptocamp.com>\>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
This module adds a Shipping Policy field on Operations Types in order to
2-
force a specific Shipping Policy on Pickings according to their types.
1+
By default Odoo takes the Shipping Policy set in the procurement group,
2+
or fallbacks on the one configured on the Operation Type.
3+
4+
This module adds a Force Shipping Policy field on Operations Types to ensure
5+
transfers will take the policy according to their types, ignoring the one set
6+
on the Procurement Group.
37

48
This is especially useful if you use a pick-pack-ship setup with the
5-
release of operation (stock_available_to_promise_release) module along
6-
side with the stock_routing_operation that may split operations by zone
9+
release of operation (`stock_available_to_promise_release`) module along
10+
side with the `stock_dynamic_routing` that may split operations by zone
711
of the warehouse. In that case, you want to be sure the pack operations
812
will wait all different picks to be processed before releasing the
913
availability of the pack operation.

stock_picking_type_shipping_policy/tests/test_stock_picking_type_shipping_policy.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def _validate_picking(self, picking):
6161
picking.move_line_ids.write({"picked": True})
6262
picking._action_done()
6363

64-
def test_shipping_policy(self):
65-
self.pack_type.shipping_policy = "force_all_products_ready"
66-
self.pick_type.shipping_policy = "force_as_soon_as_possible"
64+
def test_force_move_type(self):
65+
self.pack_type.write({"move_type": "one", "force_move_type": True})
66+
self.pick_type.write({"move_type": "direct", "force_move_type": True})
6767
move = self._run_procurement(self.product, 10)
6868
pick_picking = move.picking_id
6969
self._validate_picking(pick_picking)

stock_picking_type_shipping_policy/views/stock_picking_type.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<field name="model">stock.picking.type</field>
66
<field name="inherit_id" ref="stock.view_picking_type_form" />
77
<field name="arch" type="xml">
8-
<field name="create_backorder" position="after">
9-
<field name="shipping_policy" />
8+
<field name="move_type" position="after">
9+
<field name="force_move_type" />
1010
</field>
1111
</field>
1212
</record>

0 commit comments

Comments
 (0)