零件图号零件名称无数据 问题修复

This commit is contained in:
liaodanlong
2025-03-17 16:05:42 +08:00
parent 0a1b48ed93
commit 8347a8b029
2 changed files with 7 additions and 31 deletions

View File

@@ -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
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

View File

@@ -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()