Merge pull request !9527 from 李鹏宇/dev
This commit is contained in:
@@ -116,46 +116,43 @@ class InheritPurchaseOrder(models.Model):
|
||||
line.category_id = record.category_id.id
|
||||
|
||||
def _create_picking(self):
|
||||
"""重写_create_picking方法,移除状态和产品类型检查"""
|
||||
"""重写_create_picking方法,移除产品类型和state=='purchase'的限制,
|
||||
但保留入库单已存在时不重复创建移动行的保护逻辑"""
|
||||
StockPicking = self.env['stock.picking']
|
||||
for order in self:
|
||||
# 移除状态和产品类型检查,所有订单都生成入库单
|
||||
order = order.with_company(order.company_id)
|
||||
pickings = order.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel'))
|
||||
if not pickings:
|
||||
# 没有入库单,创建新的
|
||||
res = order._prepare_picking()
|
||||
picking = StockPicking.with_user(SUPERUSER_ID).create(res)
|
||||
pickings = picking
|
||||
else:
|
||||
picking = pickings[0]
|
||||
moves = order.order_line._create_stock_moves(picking)
|
||||
moves = moves.filtered(lambda x: x.state not in ('done', 'cancel'))._action_confirm()
|
||||
seq = 0
|
||||
for move in sorted(moves, key=lambda move: move.date):
|
||||
seq += 5
|
||||
move.sequence = seq
|
||||
moves._action_assign()
|
||||
# Get following pickings (created by push rules) to confirm them as well.
|
||||
forward_pickings = self.env['stock.picking']._get_impacted_pickings(moves)
|
||||
(pickings | forward_pickings).action_confirm()
|
||||
picking.message_post_with_source(
|
||||
'mail.message_origin_link',
|
||||
render_values={'self': picking, 'origin': order},
|
||||
subtype_xmlid='mail.mt_note',
|
||||
)
|
||||
moves = order.order_line._create_stock_moves(picking)
|
||||
moves = moves.filtered(lambda x: x.state not in ('done', 'cancel'))._action_confirm()
|
||||
seq = 0
|
||||
for move in sorted(moves, key=lambda move: move.date):
|
||||
seq += 5
|
||||
move.sequence = seq
|
||||
moves._action_assign()
|
||||
forward_pickings = self.env['stock.picking']._get_impacted_pickings(moves)
|
||||
(pickings | forward_pickings).action_confirm()
|
||||
picking.message_post_with_source(
|
||||
'mail.message_origin_link',
|
||||
render_values={'self': picking, 'origin': order},
|
||||
subtype_xmlid='mail.mt_note',
|
||||
)
|
||||
# 入库单已存在时不再重复追加移动行
|
||||
return True
|
||||
|
||||
def button_confirm(self):
|
||||
"""重写button_confirm方法,确保生成入库单"""
|
||||
result = super(InheritPurchaseOrder, self).button_confirm()
|
||||
# 直接调用重写的_create_picking方法
|
||||
self._create_picking()
|
||||
return result
|
||||
"""重写button_confirm方法,去掉草稿/已发送状态限制"""
|
||||
# 直接调用原生方法,原生会在 button_approve 中调用 _create_picking
|
||||
return super(InheritPurchaseOrder, self).button_confirm()
|
||||
|
||||
def end_approval(self):
|
||||
self.button_confirm()
|
||||
self.state = 'purchase'
|
||||
self._create_picking() # 确保生成入库单
|
||||
# button_confirm → button_approve 已经调用过 _create_picking,不需要再调
|
||||
self.write({'work_end': True})
|
||||
|
||||
@api.depends(
|
||||
|
||||
Reference in New Issue
Block a user