Skip to content

Commit 9924c78

Browse files
committed
[FIX] stock_picking_delivery_link: Ensure the delivery type is correctly passed to context
1 parent 3a93f81 commit 9924c78

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

stock_picking_delivery_link/models/stock_picking.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,23 @@ def _pre_put_in_pack_hook(self, move_line_ids):
5656
return res
5757

5858
def _set_delivery_package_type(self, batch_pack=False):
59+
"""
60+
As we want to filter package types on carrier even on internal
61+
pickings, we pass the delivery type to the context from
62+
the related carrier taken from the delivery picking.
63+
"""
5964
self.ensure_one()
6065
res = super()._set_delivery_package_type(batch_pack=batch_pack)
66+
context = res.get("context", self.env.context)
6167
context = dict(
62-
self.env.context,
68+
context,
6369
current_package_carrier_type=self.ship_carrier_id.delivery_type,
6470
)
6571
# As we pass the `delivery_type` ('fixed' or 'base_on_rule' by default) in a
6672
# key which corresponds to the `package_carrier_type` ('none' to default), we
6773
# make a conversion. No conversion needed for other carriers as the
6874
# `delivery_type` and`package_carrier_type` will be the same in these cases.
6975
if context["current_package_carrier_type"] in ["fixed", "base_on_rule"]:
70-
context["current_package_carrier_type"] = "none"
76+
context = dict(context, current_package_carrier_type="none")
77+
res["context"] = context
7178
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2023 ACSONE SA/NV (https://www.acsone.eu)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class DeliveryCarrier(models.Model):
8+
9+
_inherit = "delivery.carrier"
10+
11+
delivery_type = fields.Selection(
12+
selection_add=[("test", "Test")], ondelete={"test": "cascade"}
13+
)

stock_picking_delivery_link/tests/test_delivery_link.py

+64
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2021-2021 Camptocamp SA
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33

4+
from odoo_test_helper import FakeModelLoader
45

56
from .common import StockPickingDeliveryLinkCommonCase
67

@@ -27,6 +28,17 @@ def setUpClass(cls):
2728
}
2829
)
2930

31+
cls.loader = FakeModelLoader(cls.env, cls.__module__)
32+
cls.loader.backup_registry()
33+
from .models.delivery_carrier import DeliveryCarrier
34+
35+
cls.loader.update_registry((DeliveryCarrier,))
36+
37+
@classmethod
38+
def tearDownClass(cls):
39+
cls.loader.restore_registry()
40+
super().tearDownClass()
41+
3042
def test_ship_data_from_pick(self):
3143
move1 = self._create_move(
3244
self.product,
@@ -138,8 +150,60 @@ def test_put_in_pack_from_pick_with_wizard(self):
138150
# check the action is a dict
139151
self.assertIsInstance(pip_action, dict)
140152
pip_action_model = pip_action["res_model"]
153+
pip_action_context = pip_action["context"]
154+
# We make sure the correct action was returned
155+
self.assertEqual(pip_action_model, "choose.delivery.package")
156+
self.assertEqual("none", pip_action_context.get("current_package_carrier_type"))
157+
158+
def test_put_in_pack_from_pick_with_wizard_carrier(self):
159+
"""
160+
Normally the "choose package type" wizard is triggered only if a carrier is
161+
set on the picking (usually on ship picking). This module permits to force
162+
the wizard if there is no carrier set but if there is a shipping carrier and
163+
set_delivery_package_type_on_put_in_pack set on the package type.
164+
165+
Try with forcing from pick picking type => wizard ok
166+
"""
167+
self.test_carrier.delivery_type = "test"
168+
self.wh.delivery_steps = "pick_ship"
169+
self.env["stock.quant"]._update_available_quantity(
170+
self.product, self.shelf1_loc, 20.0
171+
)
172+
ship_move = self.env["stock.move"].create(
173+
{
174+
"name": "The ship move",
175+
"product_id": self.product.id,
176+
"product_uom_qty": 5.0,
177+
"product_uom": self.product.uom_id.id,
178+
"location_id": self.shelf2_loc.id,
179+
"location_dest_id": self.customer_location.id,
180+
"warehouse_id": self.wh.id,
181+
"picking_type_id": self.wh.out_type_id.id,
182+
"procure_method": "make_to_order",
183+
"state": "draft",
184+
}
185+
)
186+
ship_move._assign_picking()
187+
ship_move._action_confirm()
188+
pick_move = ship_move.move_orig_ids[0]
189+
pick_picking = pick_move.picking_id
190+
ship_picking = ship_move.picking_id
191+
# set a carrier on shipment picking
192+
ship_picking.carrier_id = self.test_carrier
193+
# force wizard on pick operation picking_type_id
194+
pick_picking.picking_type_id.set_delivery_package_type_on_put_in_pack = True
195+
pick_picking.action_assign()
196+
pick_picking.move_line_ids.filtered(
197+
lambda ml: ml.product_id == self.product
198+
).qty_done = 5.0
199+
pip_action = pick_picking.action_put_in_pack()
200+
# check the action is a dict
201+
self.assertIsInstance(pip_action, dict)
202+
pip_action_model = pip_action["res_model"]
203+
pip_action_context = pip_action["context"]
141204
# We make sure the correct action was returned
142205
self.assertEqual(pip_action_model, "choose.delivery.package")
206+
self.assertEqual("test", pip_action_context.get("current_package_carrier_type"))
143207

144208
def test_put_in_pack_from_pick_without_wizard(self):
145209
"""

0 commit comments

Comments
 (0)