From 925c59e1fe4436b05a3a5cd242bb314b54b24d28 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Tue, 8 Jul 2025 11:25:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E8=B4=AD=E7=94=B3=E8=AF=B7=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=9C=80=E6=B1=82=E6=98=8E=E7=BB=86=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/models/purchase_order.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sf_demand_plan/models/purchase_order.py b/sf_demand_plan/models/purchase_order.py index 9ee48bc0..5bc07313 100644 --- a/sf_demand_plan/models/purchase_order.py +++ b/sf_demand_plan/models/purchase_order.py @@ -8,6 +8,14 @@ class PurchaseOrder(models.Model): demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan", string="需求计划明细", readonly=True) + def button_confirm(self): + if self.demand_plan_line_id: + self = self.with_context( + demand_plan_line_id=self.demand_plan_line_id.id + ) + res = super(PurchaseOrder, self).button_confirm() + return res + @api.depends('origin', 'demand_plan_line_id') def _compute_purchase_type(self): for purchase in self: @@ -20,3 +28,17 @@ class PurchaseOrder(models.Model): elif purchase.demand_plan_line_id.supply_method == 'purchase': purchase.purchase_type = 'outside' + + @api.model + def create(self, vals): + res = super(PurchaseOrder, self).create(vals) + if not res.demand_plan_line_id: + origin = [origin.replace(' ', '') for origin in res.origin.split(',')] + if self.env.context.get('demand_plan_line_id'): + res.demand_plan_line_id = self.env.context.get('demand_plan_line_id') + elif 'MO' in res.origin: + # 原单据是制造订单 + mp_ids = self.env['mrp.production'].sudo().search([('name', 'in', origin)]) + if mp_ids: + res.demand_plan_line_id = mp_ids[0].demand_plan_line_id.id + return res