Skip to content

Commit 2adbd3c

Browse files
committed
Merge PR OCA#1990 into 16.0
Signed-off-by rousseldenis
2 parents 2d84db8 + c2ab842 commit 2adbd3c

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

stock_move_location/wizard/stock_move_location.py

+27-15
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,13 @@
77

88
from odoo import api, fields, models
99
from odoo.fields import first
10+
from odoo.osv import expression
1011

1112

1213
class StockMoveLocationWizard(models.TransientModel):
1314
_name = "wiz.stock.move.location"
1415
_description = "Wizard move location"
1516

16-
def _get_default_picking_type_id(self):
17-
company_id = self.env.context.get("company_id") or self.env.user.company_id.id
18-
return (
19-
self.env["stock.picking.type"]
20-
.search(
21-
[
22-
("code", "=", "internal"),
23-
("warehouse_id.company_id", "=", company_id),
24-
],
25-
limit=1,
26-
)
27-
.id
28-
)
29-
3017
origin_location_disable = fields.Boolean(
3118
compute="_compute_readonly_locations",
3219
help="technical field to disable the edition of origin location.",
@@ -53,7 +40,10 @@ def _get_default_picking_type_id(self):
5340
string="Move Location lines",
5441
)
5542
picking_type_id = fields.Many2one(
56-
comodel_name="stock.picking.type", default=_get_default_picking_type_id
43+
compute="_compute_picking_type_id",
44+
comodel_name="stock.picking.type",
45+
readonly=False,
46+
store=True,
5747
)
5848
picking_id = fields.Many2one(
5949
string="Connected Picking", comodel_name="stock.picking"
@@ -74,6 +64,28 @@ def _compute_readonly_locations(self):
7464
rec.origin_location_disable = True
7565
rec.destination_location_disable = True
7666

67+
@api.depends_context("company")
68+
@api.depends("origin_location_id")
69+
def _compute_picking_type_id(self):
70+
company_id = self.env.context.get("company_id") or self.env.user.company_id.id
71+
for rec in self:
72+
picking_type = self.env["stock.picking.type"]
73+
base_domain = [
74+
("code", "=", "internal"),
75+
("warehouse_id.company_id", "=", company_id),
76+
]
77+
if rec.origin_location_id:
78+
location_id = rec.origin_location_id
79+
while location_id and not picking_type:
80+
domain = [("default_location_src_id", "=", location_id.id)]
81+
domain = expression.AND([base_domain, domain])
82+
picking_type = picking_type.search(domain, limit=1)
83+
# Move up to the parent location if no picking type found
84+
location_id = not picking_type and location_id.location_id or False
85+
if not picking_type:
86+
picking_type = picking_type.search(base_domain, limit=1)
87+
rec.picking_type_id = picking_type.id
88+
7789
@api.model
7890
def default_get(self, fields):
7991
res = super().default_get(fields)

0 commit comments

Comments
 (0)