From 52f80fc0c5e476b215af739e96110bb2a02f8335 Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Wed, 3 Apr 2024 10:22:44 +0700 Subject: [PATCH 1/2] [IMP] stock_move_location This improvement commit ensures the operation type is determined by the original location, aiming to prevent the misuse of incorrect operation types in scenarios where multiple internal transfer options exist. --- .../wizard/stock_move_location.py | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/stock_move_location/wizard/stock_move_location.py b/stock_move_location/wizard/stock_move_location.py index 53380c3ea..dd02c48be 100644 --- a/stock_move_location/wizard/stock_move_location.py +++ b/stock_move_location/wizard/stock_move_location.py @@ -7,26 +7,13 @@ from itertools import groupby from odoo import api, fields, models from odoo.fields import first +from odoo.osv import expression class StockMoveLocationWizard(models.TransientModel): _name = "wiz.stock.move.location" _description = "Wizard move location" - def _get_default_picking_type_id(self): - company_id = self.env.context.get("company_id") or self.env.user.company_id.id - return ( - self.env["stock.picking.type"] - .search( - [ - ("code", "=", "internal"), - ("warehouse_id.company_id", "=", company_id), - ], - limit=1, - ) - .id - ) - origin_location_disable = fields.Boolean( compute="_compute_readonly_locations", help="technical field to disable the edition of origin location.", @@ -53,7 +40,9 @@ class StockMoveLocationWizard(models.TransientModel): string="Move Location lines", ) picking_type_id = fields.Many2one( - comodel_name="stock.picking.type", default=_get_default_picking_type_id + compute="_compute_picking_type_id", + comodel_name="stock.picking.type", + readonly=False, ) picking_id = fields.Many2one( string="Connected Picking", comodel_name="stock.picking" @@ -74,6 +63,28 @@ class StockMoveLocationWizard(models.TransientModel): rec.origin_location_disable = True rec.destination_location_disable = True + @api.depends_context("company") + @api.depends("origin_location_id") + def _compute_picking_type_id(self): + company_id = self.env.context.get("company_id") or self.env.user.company_id.id + for rec in self: + picking_type = self.env["stock.picking.type"] + base_domain = [ + ("code", "=", "internal"), + ("warehouse_id.company_id", "=", company_id), + ] + if rec.origin_location_id: + location_id = rec.origin_location_id + while location_id and not picking_type: + domain = [("default_location_src_id", "=", location_id.id)] + domain = expression.AND([base_domain, domain]) + picking_type = picking_type.search(domain, limit=1) + # Move up to the parent location if no picking type found + location_id = not picking_type and location_id.location_id or False + if not picking_type: + picking_type = picking_type.search(base_domain, limit=1) + rec.picking_type_id = picking_type.id + @api.model def default_get(self, fields): res = super().default_get(fields) From c2ab842786dad440c1a5cbe76dae18856e7429c2 Mon Sep 17 00:00:00 2001 From: sergio-teruel Date: Fri, 12 Apr 2024 19:59:29 +0200 Subject: [PATCH 2/2] [FIX] stock_move_location: The new picking is created with other picking type of selected --- stock_move_location/wizard/stock_move_location.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stock_move_location/wizard/stock_move_location.py b/stock_move_location/wizard/stock_move_location.py index dd02c48be..381a216a8 100644 --- a/stock_move_location/wizard/stock_move_location.py +++ b/stock_move_location/wizard/stock_move_location.py @@ -43,6 +43,7 @@ class StockMoveLocationWizard(models.TransientModel): compute="_compute_picking_type_id", comodel_name="stock.picking.type", readonly=False, + store=True, ) picking_id = fields.Many2one( string="Connected Picking", comodel_name="stock.picking"