零件图号零件名称数据填充

This commit is contained in:
liaodanlong
2025-03-17 11:26:42 +08:00
parent ef5eea1845
commit 0a1b48ed93
2 changed files with 38 additions and 14 deletions

View File

@@ -109,15 +109,16 @@ class PurchaseOrder(models.Model):
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
part_number = fields.Char('零件图号', store=True, compute='_compute_related_product')
part_name = fields.Char('零件名称', store=True,
compute='_compute_related_product')
part_number = fields.Char('零件图号', store=True, compute='_compute_part_number')
part_name = fields.Char('零件名称', store=True, compute='_compute_part_name')
related_product = fields.Many2one('product.product', string='关联产品',
help='经此产品工艺加工成的成品')
manual_part_name = fields.Char()
@api.depends('product_id')
def _compute_related_product(self):
def _compute_part_number(self):
for record in self:
if record.part_number or record.part_name:
if record.part_number:
continue
if record.product_id.categ_id.name == '坯料':
product_name = ''
@@ -135,13 +136,35 @@ class PurchaseOrderLine(models.Model):
filtered_order_line = sale_order.order_line.filtered(
lambda order_line: re.search(f'{product_name}$', order_line.product_id.name)
)
record.part_number = filtered_order_line.product_id.part_number if filtered_order_line else None
record.part_name = filtered_order_line.product_id.part_name if filtered_order_line else None
record.part_number = filtered_order_line.product_id.part_number
else:
record.part_number = record.product_id.part_number
record.part_name = record.product_id.part_name
# if record.product_id.detailed_type:
# production_id = self.env['mrp.production'].search([('name', '=', record.order_id.origin)])
# record.related_product = production_id.product_id if production_id else False
# else:
# record.related_product = False
@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

View File

@@ -375,7 +375,7 @@ class RePurchaseOrder(models.Model):
'product_uom': server_template.uom_id.id,
'related_product': production.product_id.id,
'part_number': pp.part_number,
'part_name': pp.part_name,
'manual_part_name': pp.part_name,
}))
# 获取服务商品最后一个供应商的采购员
purchase_user_id = server_template.seller_ids[-1].partner_id.purchase_user_id
@@ -387,6 +387,7 @@ class RePurchaseOrder(models.Model):
'order_line': server_product_process,
'user_id': purchase_user_id.id
})
purchase_order.order_line._compute_part_name()
pp.purchase_id = [(6, 0, [purchase_order.id])]
# self.env.cr.commit()