零件图号零件名称无数据 问题修复
This commit is contained in:
@@ -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
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user