子制造订单零件图号与零件名称获取方式修改
This commit is contained in:
@@ -5,6 +5,8 @@ import logging
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import traceback
|
||||
|
||||
import requests
|
||||
from itertools import groupby
|
||||
from collections import defaultdict, namedtuple
|
||||
@@ -257,14 +259,46 @@ class MrpProduction(models.Model):
|
||||
], string='工序状态', default='待装夹')
|
||||
|
||||
# 零件图号
|
||||
part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True)
|
||||
part_number = fields.Char('零件图号', compute='_compute_part_info', store=True)
|
||||
|
||||
# 上传零件图纸
|
||||
part_drawing = fields.Binary('零件图纸', related='product_id.machining_drawings', readonly=True)
|
||||
|
||||
quality_standard = fields.Binary('质检标准', related='product_id.quality_standard', readonly=True)
|
||||
|
||||
part_name = fields.Char(string='零件名称', related='product_id.part_name', readonly=True)
|
||||
part_name = fields.Char(string='零件名称', compute='_compute_part_info', store=True)
|
||||
@api.depends('product_id')
|
||||
def _compute_part_info(self):
|
||||
try:
|
||||
for production_id in self:
|
||||
if production_id.product_id.categ_id.type == '成品':
|
||||
production_id.part_number = production_id.product_id.part_number
|
||||
production_id.part_name = production_id.product_id.part_name
|
||||
elif production_id.product_id.categ_id.type == '坯料':
|
||||
product_name = ''
|
||||
match = re.search(r'(S\d{5}-\d)', production_id.product_id.name)
|
||||
# 如果匹配成功,提取结果
|
||||
if match:
|
||||
product_name = match.group(0)
|
||||
if production_id.picking_id.sale_order_id:
|
||||
sale_order = production_id.picking_id.sale_order_id
|
||||
else:
|
||||
sale_order_name = ''
|
||||
match = re.search(r'(S\d+)', production_id.product_id.name)
|
||||
if match:
|
||||
sale_order_name = match.group(0)
|
||||
sale_order = self.env['sale.order'].sudo().search(
|
||||
[('name', '=', sale_order_name)])
|
||||
filtered_order_line = sale_order.order_line.filtered(
|
||||
lambda production: re.search(f'{product_name}$', production.product_id.name)
|
||||
)
|
||||
|
||||
if filtered_order_line:
|
||||
production_id.part_number = filtered_order_line.part_number
|
||||
production_id.part_name = filtered_order_line.part_name
|
||||
except Exception as e:
|
||||
traceback_error = traceback.format_exc()
|
||||
logging.error("制造订单零件图号 零件名称获取失败:%s" % traceback_error)
|
||||
|
||||
# 判断制造的产品类型
|
||||
production_product_type = fields.Selection([
|
||||
|
||||
Reference in New Issue
Block a user