修复计算当前货位的逻辑,减少循环次数
This commit is contained in:
@@ -812,40 +812,49 @@ class SfStockMoveLine(models.Model):
|
|||||||
# # 从目标stock.move对象获取目标stock.picking对象
|
# # 从目标stock.move对象获取目标stock.picking对象
|
||||||
# dest_picking = dest_move.picking_id if dest_move else False
|
# dest_picking = dest_move.picking_id if dest_move else False
|
||||||
# # 现在,dest_picking就是current_picking的下一步
|
# # 现在,dest_picking就是current_picking的下一步
|
||||||
|
# 添加所有需要的依赖字段
|
||||||
@api.depends('location_id')
|
@api.depends('location_id')
|
||||||
def _compute_current_location_id(self):
|
def _compute_current_location_id(self):
|
||||||
|
# 批量获取所有相关记录的picking
|
||||||
|
pickings = self.mapped('picking_id')
|
||||||
|
|
||||||
|
# 构建源picking的移库行与目标位置的映射
|
||||||
|
origin_location_map = {}
|
||||||
|
for picking in pickings:
|
||||||
|
# 获取源picking
|
||||||
|
origin_move = picking.move_ids[:1].move_orig_ids[:1]
|
||||||
|
if not origin_move:
|
||||||
|
continue
|
||||||
|
|
||||||
|
origin_picking = origin_move.picking_id
|
||||||
|
if not origin_picking:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 为每个picking构建lot_id到location的映射
|
||||||
|
origin_location_map[picking.id] = {
|
||||||
|
move_line.lot_id.id: move_line.destination_location_id
|
||||||
|
for move_line in origin_picking.move_line_ids.filtered(
|
||||||
|
lambda ml: ml.destination_location_id and ml.lot_id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
# 批量更新current_location_id
|
||||||
for record in self:
|
for record in self:
|
||||||
# 使用record代替self来引用当前遍历到的记录
|
current_picking = record.picking_id
|
||||||
logging.info('record.picking_id.name: %s' % record.picking_id.name)
|
if not current_picking:
|
||||||
logging.info('record.env: %s' % record.env['stock.picking'].search([('name', '=', record.picking_id.name)]))
|
record.current_location_id = False
|
||||||
|
continue
|
||||||
# 获取当前的stock.picking对象
|
|
||||||
current_picking = record.env['stock.picking'].search([('name', '=', record.picking_id.name)], limit=1)
|
# 获取当前picking对应的lot_location映射
|
||||||
|
lot_dest_map = origin_location_map.get(current_picking.id, {})
|
||||||
# 获取当前picking的第一个stock.move对象
|
|
||||||
current_move = current_picking.move_ids[0] if current_picking.move_ids else False
|
# 查找匹配的lot_id
|
||||||
|
for move_line in current_picking.move_line_ids:
|
||||||
# 如果存在相关的stock.move对象
|
if move_line.lot_id and move_line.lot_id.id in lot_dest_map:
|
||||||
if current_move:
|
record.current_location_id = lot_dest_map[move_line.lot_id.id]
|
||||||
# 获取源stock.move对象
|
break
|
||||||
origin_move = current_move.move_orig_ids[0] if current_move.move_orig_ids else False
|
else:
|
||||||
|
record.current_location_id = False
|
||||||
# 从源stock.move对象获取源stock.picking对象
|
|
||||||
origin_picking = origin_move.picking_id if origin_move else False
|
|
||||||
|
|
||||||
# 如果前一个调拨单有目标货位
|
|
||||||
if origin_picking:
|
|
||||||
for i in current_picking.move_line_ids:
|
|
||||||
for j in origin_picking.move_line_ids:
|
|
||||||
if j.destination_location_id and i.lot_id == j.lot_id:
|
|
||||||
# 更新当前记录的current_location_id字段
|
|
||||||
record.current_location_id = j.destination_location_id
|
|
||||||
# # 获取目标stock.move对象
|
|
||||||
# dest_move = current_move.move_dest_ids[0] if current_move.move_dest_ids else False
|
|
||||||
#
|
|
||||||
# # 从目标stock.move对象获取目标stock.picking对象
|
|
||||||
# dest_picking = dest_move.picking_id if dest_move else False
|
|
||||||
# # 现在,dest_picking就是current_picking的下一步
|
|
||||||
|
|
||||||
# 是一张单据一张单据往下走的,所以这里的目标货位是上一张单据的当前货位,且这样去计算是可以的。
|
# 是一张单据一张单据往下走的,所以这里的目标货位是上一张单据的当前货位,且这样去计算是可以的。
|
||||||
@api.depends('location_dest_id')
|
@api.depends('location_dest_id')
|
||||||
|
|||||||
Reference in New Issue
Block a user