Accept Merge Request #1182: (feature/优化工单_1 -> develop)

Merge Request: 1、添加制造订单的刀具备注字段自动计算逻辑及方法;2、优化工单状态自动计算方法;

Created By: @禹翔辉
Reviewed By: @马广威
Approved By: @马广威 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1182?initial=true
This commit is contained in:
禹翔辉
2024-07-26 10:59:05 +08:00
committed by Coding
2 changed files with 36 additions and 26 deletions

View File

@@ -29,41 +29,34 @@ class MrpProduction(models.Model):
detection_result_ids = fields.One2many('sf.detection.result', 'production_id', '检测报告')
tool_state = fields.Selection([('0', '正常'), ('1', '缺刀'), ('2', '无效刀')], string='功能刀具状态', default='0',
store=True, compute='_compute_tool_state')
tool_state_remark = fields.Text(string='功能刀具状态备注(缺刀)', readonly=True)
tool_state_remark = fields.Text(string='功能刀具状态备注(缺刀)', compute='_compute_tool_state_remark', store=True)
tool_state_remark2 = fields.Text(string='功能刀具状态备注(无效刀)', readonly=True)
@api.depends('workorder_ids.tool_state_remark')
def _compute_tool_state_remark(self):
for item in self:
if item.workorder_ids:
workorder_ids = item.workorder_ids.filtered(lambda a: a.state not in ('rework', '返工'))
if workorder_ids.filtered(lambda a: a.tool_state_remark):
work_ids = workorder_ids.filtered(lambda a: a.tool_state_remark)
tool_state_remark = ''
for work_id in work_ids:
tool_state_remark = f"{work_id.tool_state_remark}\n"
item.tool_state_remark = tool_state_remark
else:
item.tool_state_remark = False
@api.depends('workorder_ids.tool_state')
def _compute_tool_state(self):
# if self.workorder_ids:
for item in self:
if item.workorder_ids:
workorder_ids = item.workorder_ids.filtered(lambda a: a.state not in ('rework', '返工'))
if workorder_ids.filtered(lambda a: a.tool_state == '2'):
item.tool_state = '2'
elif workorder_ids.filtered(lambda a: a.tool_state == '1'):
tool_state_remark = ''
data = {}
# 获取所有缺刀工单加工面对应缺的刀
for work in workorder_ids.filtered(lambda a: a.tool_state == '1'):
if work.processing_panel not in list(data.keys()):
data.update({work.processing_panel: []})
for cnc in work.cnc_ids.filtered(lambda a: a.tool_state == '1'):
if cnc.cutting_tool_name not in data[work.processing_panel]:
data[work.processing_panel].append(cnc.cutting_tool_name)
# 按格式生成缺刀提示信息
for key in data:
if data.get(key) and not data.get(key):
if tool_state_remark != '':
tool_state_remark = f'{tool_state_remark}\n{key}缺刀:{data.get(key)}'
else:
tool_state_remark = f'{key}缺刀:{data.get(key)}'
item.tool_state = '1'
item.tool_state_remark = tool_state_remark
item.tool_state_remark2 = ''
else:
item.tool_state = '0'
item.tool_state_remark = ''
item.tool_state_remark2 = ''
# state = fields.Selection(selection_add=[
# ('pending_scheduling', '待排程'),

View File

@@ -180,11 +180,27 @@ class ResMrpWorkOrder(models.Model):
# 功能刀具状态
tool_state = fields.Selection([('0', '正常'), ('1', '缺刀'), ('2', '无效刀')], string='功能刀具状态', default='0',
store=True, compute='_compute_tool_state')
tool_state_remark = fields.Text(string='功能刀具状态备注(缺刀)', compute='_compute_tool_state_remark', store=True)
@api.depends('cnc_ids.tool_state')
def _compute_tool_state_remark(self):
for item in self:
if item.cnc_ids:
if item.cnc_ids.filtered(lambda a: a.tool_state == '2'):
item.tool_state_remark = None
elif item.cnc_ids.filtered(lambda a: a.tool_state == '1'):
tool_state_remark = f'{item.processing_panel}缺刀:['
cnc_ids = item.cnc_ids.filtered(lambda a: a.tool_state == '1')
for cnc_id in cnc_ids:
tool_state_remark = f"{tool_state_remark}'{cnc_id.cutting_tool_name}'"
item.tool_state_remark = f"{tool_state_remark}]"
else:
item.tool_state_remark = None
@api.depends('cnc_ids.tool_state')
def _compute_tool_state(self):
for item in self:
if item:
if item.cnc_ids:
if item.cnc_ids.filtered(lambda a: a.tool_state == '2'):
item.tool_state = '2'
elif item.cnc_ids.filtered(lambda a: a.tool_state == '1'):
@@ -835,9 +851,10 @@ class ResMrpWorkOrder(models.Model):
# if workorder.state not in ['cancel', 'rework']:
# workorder.state = 'rework'
if workorder.production_id.state == 'pending_cam':
if workorder.routing_type == '装夹预调' and workorder.state in ['ready', 'waiting']:
if workorder.production_id.tool_state in ['1', '2']:
workorder.state = 'waiting'
if workorder.production_id.tool_state in ['1', '2']:
work_ids = workorder.production_id.workorder_ids.filtered(
lambda a: a.routing_type == '装夹预调' and a.state in ['ready', 'waiting'])
work_ids.state = 'waiting'
logging.info('工序:%s' % workorder.sequence)
logging.info('工单最终状态:%s' % workorder.state)