From f7c288c1d2ca8482d1295b139ad86dec958ca1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Tue, 10 Mar 2026 15:28:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E8=B4=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/inherit_purchase_order.py | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/yuthon_purchase/models/inherit_purchase_order.py b/yuthon_purchase/models/inherit_purchase_order.py index 04ad741d0..7016e03bf 100644 --- a/yuthon_purchase/models/inherit_purchase_order.py +++ b/yuthon_purchase/models/inherit_purchase_order.py @@ -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(