From 8347a8b029d93d91d91bfe8d15d8f1f82004064c Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Mon, 17 Mar 2025 16:05:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=B6=E4=BB=B6=E5=9B=BE=E5=8F=B7=E9=9B=B6?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E7=A7=B0=E6=97=A0=E6=95=B0=E6=8D=AE=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/purchase_order.py | 36 ++++------------------- sf_sale/models/sale_order.py | 2 +- 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/sf_manufacturing/models/purchase_order.py b/sf_manufacturing/models/purchase_order.py index 1fbac87b..7b460958 100644 --- a/sf_manufacturing/models/purchase_order.py +++ b/sf_manufacturing/models/purchase_order.py @@ -118,7 +118,7 @@ class PurchaseOrderLine(models.Model): @api.depends('product_id') def _compute_part_number(self): for record in self: - if record.part_number: + if record.part_number and record.part_name: continue if record.product_id.categ_id.name == '坯料': product_name = '' @@ -137,34 +137,10 @@ class PurchaseOrderLine(models.Model): lambda order_line: re.search(f'{product_name}$', order_line.product_id.name) ) record.part_number = filtered_order_line.product_id.part_number - else: - record.part_number = record.product_id.part_number - - @api.depends('product_id') - def _compute_part_name(self): - for record in self: - if record.manual_part_name: - # 如果手动设置了 part_name,使用手动设置的值 - record.part_name = record.manual_part_name - continue - if record.part_name: - continue - if record.product_id.categ_id.name == '坯料': - product_name = '' - match = re.search(r'(S\d{5}-\d)', record.product_id.name) - # 如果匹配成功,提取结果 - if match: - product_name = match.group(0) - sale_order_name = '' - match_sale = re.search(r'S(\d+)', record.product_id.name) - if match_sale: - sale_order_name = match_sale.group(0) - sale_order = self.env['sale.order'].sudo().search( - [('name', '=', sale_order_name)]) - if sale_order: - filtered_order_line = sale_order.order_line.filtered( - lambda order_line: re.search(f'{product_name}$', order_line.product_id.name) - ) record.part_name = filtered_order_line.product_id.part_name else: - record.part_name = record.product_id.part_name \ No newline at end of file + record.part_number = record.product_id.part_number + record.part_name = record.product_id.part_name + if record.manual_part_name: + # 如果手动设置了 part_name,使用手动设置的值 + record.part_name = record.manual_part_name \ No newline at end of file diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index e3ac7282..49a3e48c 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -387,7 +387,7 @@ class RePurchaseOrder(models.Model): 'order_line': server_product_process, 'user_id': purchase_user_id.id }) - purchase_order.order_line._compute_part_name() + purchase_order.order_line._compute_part_number() pp.purchase_id = [(6, 0, [purchase_order.id])] # self.env.cr.commit()