调整写入编程记录的位置

This commit is contained in:
mgw
2025-01-13 16:51:25 +08:00
parent b2c6c9c27d
commit d8a816c90e
3 changed files with 118 additions and 78 deletions

View File

@@ -55,7 +55,7 @@ class MrpProduction(models.Model):
production.sale_order_id = sale_order.id production.sale_order_id = sale_order.id
else: else:
logging.warning("No sale order found for production {} with product {} (name match: {})".format( logging.warning("No sale order found for production {} with product {} (name match: {})".format(
production.id, production.product_id.name, result)) production.id, production.product_id.name, result))
except Exception as e: except Exception as e:
logging.error("Error while fetching sale order for production {}: {}".format(production.id, str(e))) logging.error("Error while fetching sale order for production {}: {}".format(production.id, str(e)))
@@ -364,15 +364,16 @@ class MrpProduction(models.Model):
# if all(wo_state in 'done' for wo_state in production.workorder_ids.mapped('state')): # if all(wo_state in 'done' for wo_state in production.workorder_ids.mapped('state')):
# production.state = 'done' # production.state = 'done'
if any((wo.test_results == '返工' and wo.state == 'done' and production.programming_state in ['已编程']) if any((wo.test_results == '返工' and wo.state == 'done' and production.programming_state in ['已编程'])
or (wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中', '已编程']) or (wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中', '已编程'])
for wo in production.workorder_ids): for wo in production.workorder_ids):
production.state = 'rework' production.state = 'rework'
if any(wo.test_results == '报废' and wo.state == 'done' for wo in production.workorder_ids): if any(wo.test_results == '报废' and wo.state == 'done' for wo in production.workorder_ids):
production.state = 'scrap' production.state = 'scrap'
if any(dr.test_results == '报废' and dr.handle_result == '已处理' for dr in if any(dr.test_results == '报废' and dr.handle_result == '已处理' for dr in
production.detection_result_ids): production.detection_result_ids):
production.state = 'cancel' production.state = 'cancel'
if production.workorder_ids and all(wo_state in ('done', 'rework', 'cancel') for wo_state in production.workorder_ids.mapped('state')): if production.workorder_ids and all(
wo_state in ('done', 'rework', 'cancel') for wo_state in production.workorder_ids.mapped('state')):
if production.state not in ['scrap', 'rework', 'cancel']: if production.state not in ['scrap', 'rework', 'cancel']:
production.state = 'done' production.state = 'done'
@@ -447,7 +448,7 @@ class MrpProduction(models.Model):
if account.state not in ['cancel', False]: if account.state not in ['cancel', False]:
if account.name not in account_moves: if account.name not in account_moves:
account_moves.append(account.name) account_moves.append(account.name)
if purchase.state not in ['cancel','draft', False]: if purchase.state not in ['cancel', 'draft', False]:
purchase_orders.append(purchase.name) purchase_orders.append(purchase.name)
special_design = self.technology_design_ids.filtered( special_design = self.technology_design_ids.filtered(
lambda a: a.routing_tag == 'special' and a.is_auto is False) lambda a: a.routing_tag == 'special' and a.is_auto is False)
@@ -460,7 +461,7 @@ class MrpProduction(models.Model):
if not product_production_process: if not product_production_process:
if special.process_parameters_id not in process_parameters: if special.process_parameters_id not in process_parameters:
process_parameters.append(special.process_parameters_id.display_name) process_parameters.append(special.process_parameters_id.display_name)
if account_moves: if account_moves:
raise UserError(_("请联系工厂生产经理对该(%s)账单进行取消", ", ".join(account_moves))) raise UserError(_("请联系工厂生产经理对该(%s)账单进行取消", ", ".join(account_moves)))
if purchase_orders: if purchase_orders:
@@ -585,7 +586,7 @@ class MrpProduction(models.Model):
for rp in reproduction: for rp in reproduction:
if rp.programming_no == item['programming_no']: if rp.programming_no == item['programming_no']:
rp.write({'programming_state': '已编程未下发' if item[ rp.write({'programming_state': '已编程未下发' if item[
'programming_state'] == '已编程' else '编程中'}) 'programming_state'] == '已编程' else '编程中'})
else: else:
return item return item
@@ -605,7 +606,8 @@ class MrpProduction(models.Model):
elif self.tool_state == '2': elif self.tool_state == '2':
manufacturing_type = 'invalid_tool_rework' manufacturing_type = 'invalid_tool_rework'
res = {'programming_no': self.programming_no, res = {'programming_no': self.programming_no,
'manufacturing_type': manufacturing_type} 'manufacturing_type': manufacturing_type,
'trigger_time': trigger_time}
logging.info('res=%s:' % res) logging.info('res=%s:' % res)
configsettings = self.env['res.config.settings'].get_values() configsettings = self.env['res.config.settings'].get_values()
config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key']) config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
@@ -619,44 +621,44 @@ class MrpProduction(models.Model):
self.write({'is_rework': True}) self.write({'is_rework': True})
else: else:
raise UserError(ret['message']) raise UserError(ret['message'])
# 增加对编程记录的更新 # # 增加对编程记录的更新
cloud_programming = self._cron_get_programming_state() # cloud_programming = self._cron_get_programming_state()
if manufacturing_type == 'rework': # if manufacturing_type == 'rework':
self.programming_record_ids.create({ # self.programming_record_ids.create({
'number': len(self.programming_record_ids) + 1, # 'number': len(self.programming_record_ids) + 1,
'production_id': self.id, # 'production_id': self.id,
'reason': '返工', # 'reason': '返工',
'programming_method': cloud_programming['programme_way'], # 'programming_method': cloud_programming['programme_way'],
'current_programming_count': cloud_programming['reprogramming_num'], # 'current_programming_count': cloud_programming['reprogramming_num'],
'target_production_id': cloud_programming['production_order_no'], # 'target_production_id': cloud_programming['production_order_no'],
'apply_time': trigger_time, # 'apply_time': trigger_time,
'send_time': cloud_programming['send_time'], # 'send_time': cloud_programming['send_time'],
}) # })
elif manufacturing_type == 'scrap': # elif manufacturing_type == 'scrap':
self.programming_record_ids.create({ # self.programming_record_ids.create({
'number': len(self.programming_record_ids) + 1, # 'number': len(self.programming_record_ids) + 1,
'production_id': self.id, # 'production_id': self.id,
'reason': '报废', # 'reason': '报废',
'programming_method': cloud_programming['programme_way'], # 'programming_method': cloud_programming['programme_way'],
'current_programming_count': cloud_programming['reprogramming_num'], # 'current_programming_count': cloud_programming['reprogramming_num'],
'target_production_id': cloud_programming['production_order_no'], # 'target_production_id': cloud_programming['production_order_no'],
'apply_time': trigger_time, # 'apply_time': trigger_time,
'send_time': cloud_programming['send_time'], # 'send_time': cloud_programming['send_time'],
}) # })
elif manufacturing_type == 'invalid_tool_rework': # elif manufacturing_type == 'invalid_tool_rework':
self.programming_record_ids.create({ # self.programming_record_ids.create({
'number': len(self.programming_record_ids) + 1, # 'number': len(self.programming_record_ids) + 1,
'production_id': self.id, # 'production_id': self.id,
'reason': '无效功能刀具', # 'reason': '无效功能刀具',
'programming_method': cloud_programming['programme_way'], # 'programming_method': cloud_programming['programme_way'],
'current_programming_count': cloud_programming['reprogramming_num'], # 'current_programming_count': cloud_programming['reprogramming_num'],
'target_production_id': cloud_programming['production_order_no'], # 'target_production_id': cloud_programming['production_order_no'],
'apply_time': trigger_time, # 'apply_time': trigger_time,
'send_time': cloud_programming['send_time'], # 'send_time': cloud_programming['send_time'],
}) # })
else: # else:
logging.info('无对应状态,不需更新编程记录') # logging.info('无对应状态,不需更新编程记录')
except Exception as e: except Exception as e:
logging.info('update_programming_state error:%s' % e) logging.info('update_programming_state error:%s' % e)
@@ -974,8 +976,8 @@ class MrpProduction(models.Model):
# 对工单进行逐个插入 # 对工单进行逐个插入
for work_id in work_ids: for work_id in work_ids:
order_rework_ids = rec.workorder_ids.filtered( order_rework_ids = rec.workorder_ids.filtered(
lambda item: (item.sequence > 0 and work_id.name == item.name lambda item: (item.sequence > 0 and work_id.name == item.name
and work_id.processing_panel == item.processing_panel)) and work_id.processing_panel == item.processing_panel))
order_rework_ids = sorted(order_rework_ids, key=lambda item: item.sequence, reverse=True) order_rework_ids = sorted(order_rework_ids, key=lambda item: item.sequence, reverse=True)
work_id.sequence = order_rework_ids[0].sequence + 1 work_id.sequence = order_rework_ids[0].sequence + 1
# 对该工单之后的工单工序进行加一 # 对该工单之后的工单工序进行加一
@@ -1547,7 +1549,7 @@ class MrpProduction(models.Model):
if not vals.get('procurement_group_id'): if not vals.get('procurement_group_id'):
product_id = self.env['product.product'].browse(vals['product_id']) product_id = self.env['product.product'].browse(vals['product_id'])
if product_id.product_tmpl_id.single_manufacturing: if product_id.product_tmpl_id.single_manufacturing:
if product_id.categ_id.name =='成品': if product_id.categ_id.name == '成品':
vals['procurement_group_id'] = group_id vals['procurement_group_id'] = group_id
continue continue
if product_id.id not in product_group_id.keys(): if product_id.id not in product_group_id.keys():
@@ -1640,7 +1642,7 @@ class MrpProduction(models.Model):
raise UserError( raise UserError(
_('You must enter a serial number for each line of %s') % sml.product_id.display_name) _('You must enter a serial number for each line of %s') % sml.product_id.display_name)
return True return True
reprogramming_count = fields.Integer(string='重新编程次数', default=0) reprogramming_count = fields.Integer(string='重新编程次数', default=0)
# 申请编程 # 申请编程
@@ -1657,27 +1659,27 @@ class MrpProduction(models.Model):
# problem_productions.append(production.name) # problem_productions.append(production.name)
# if problem_productions: # if problem_productions:
# raise UserError('以下制造订单状态或编程状态不符合要求: %s' % ', '.join(problem_productions)) # raise UserError('以下制造订单状态或编程状态不符合要求: %s' % ', '.join(problem_productions))
# 上述通过后返回一个action id为sf_programming_reason_action用作二次确认wizard显示“重新编程原因XXXXX用户录入注意该制造订单产品已申请重新编程次数为N且当前编程状态为XXX” # 上述通过后返回一个action id为sf_programming_reason_action用作二次确认wizard显示“重新编程原因XXXXX用户录入注意该制造订单产品已申请重新编程次数为N且当前编程状态为XXX”
cloud_programming = self._cron_get_programming_state() cloud_programming = self._cron_get_programming_state()
return { return {
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'res_model': 'sf.programming.reason', 'res_model': 'sf.programming.reason',
'view_mode': 'form', 'view_mode': 'form',
'target': 'new', 'target': 'new',
'context': { 'context': {
'default_production_id': self.id, 'default_production_id': self.id,
'active_id': self.id, 'active_id': self.id,
# 传当前时间 # 传当前时间
'default_apply_time': fields.Datetime.now(), 'default_apply_time': fields.Datetime.now(),
}, },
'view_id': self.env.ref('sf_manufacturing.sf_programming_reason_form_view').id, 'view_id': self.env.ref('sf_manufacturing.sf_programming_reason_form_view').id,
} }
# 编程记录 # 编程记录
programming_record_ids = fields.One2many('sf.programming.record', 'production_id') programming_record_ids = fields.One2many('sf.programming.record', 'production_id')
# 编程单更新 # 编程单更新
def re_programming_update_programming_state(self): def re_programming_update_programming_state(self):
try: try:
res = {'programming_no': self.programming_no, res = {'programming_no': self.programming_no,
@@ -1699,6 +1701,7 @@ class MrpProduction(models.Model):
logging.info('update_programming_state error:%s' % e) logging.info('update_programming_state error:%s' % e)
raise UserError("更新编程单状态失败,请联系管理员") raise UserError("更新编程单状态失败,请联系管理员")
# 编程记录 # 编程记录
class sf_programming_record(models.Model): class sf_programming_record(models.Model):
_name = 'sf.programming.record' _name = 'sf.programming.record'
@@ -1750,7 +1753,7 @@ class sf_detection_result(models.Model):
'views': [(self.env.ref('sf_manufacturing.sf_test_report_form').id, 'form')], 'views': [(self.env.ref('sf_manufacturing.sf_test_report_form').id, 'form')],
'target': 'new' 'target': 'new'
} }
def write(self, vals): def write(self, vals):
if vals.get('handle_result') and vals.get('handle_result') == '已处理': if vals.get('handle_result') and vals.get('handle_result') == '已处理':
vals['handle_result_date'] = fields.Datetime.now() vals['handle_result_date'] = fields.Datetime.now()

View File

@@ -87,6 +87,7 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//header//button[last()]" position="after"> <xpath expr="//header//button[last()]" position="after">
<button name="action_apply_programming" type="object" string="申请编程" class="oe_highlight" <button name="action_apply_programming" type="object" string="申请编程" class="oe_highlight"
attrs="{'invisible': ['|', ('state', 'not in', ['confirmed', 'pending_cam']), ('programming_state', '!=', '已编程')]}"
groups="sf_base.group_sf_mrp_user"/> groups="sf_base.group_sf_mrp_user"/>
</xpath> </xpath>
<xpath expr="//field[@name='state']" position="attributes"> <xpath expr="//field[@name='state']" position="attributes">

View File

@@ -39,6 +39,7 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
res = {'status': -2, 'message': '查询到待工艺确认的制造订单'} res = {'status': -2, 'message': '查询到待工艺确认的制造订单'}
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
if productions: if productions:
# 拉取所有加工面的程序文件 # 拉取所有加工面的程序文件
for r in ret['processing_panel'].split(','): for r in ret['processing_panel'].split(','):
program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r)
@@ -98,6 +99,18 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
productions.write({'programming_state': '已编程', 'work_state': '已编程'}) productions.write({'programming_state': '已编程', 'work_state': '已编程'})
logging.info('已更新制造订单编程状态:%s' % productions.ids) logging.info('已更新制造订单编程状态:%s' % productions.ids)
# 对制造订单所有面的cnc工单的程序用刀进行校验
try:
logging.info(f'已更新制造订单:{productions}')
re_tool_chekout = False
re_tool_chekout = productions.production_cnc_tool_checkout()
if re_tool_chekout:
return json.JSONEncoder().encode({'status': -3, 'message': '对cnc工单的程序用刀进行校验失败'})
except Exception as e:
res = {'status': -3, 'message': '对cnc工单的程序用刀进行校验报错'}
logging.info(f'对cnc工单的程序用刀进行校验报错{e}')
return json.JSONEncoder().encode(res)
# 更新编程记录 # 更新编程记录
for production in productions: for production in productions:
record_ids_obj = production.programming_record_ids.filtered( record_ids_obj = production.programming_record_ids.filtered(
@@ -115,7 +128,7 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
'apply_time': False, 'apply_time': False,
'send_time': ret['send_time'], 'send_time': ret['send_time'],
}) })
if ret['reset_flag']: elif ret['reset_flag']:
production.programming_record_ids.create({ production.programming_record_ids.create({
'number': len(production.programming_record_ids) + 1, 'number': len(production.programming_record_ids) + 1,
'production_id': production.id, 'production_id': production.id,
@@ -126,23 +139,46 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
'apply_time': False, 'apply_time': False,
'send_time': ret['send_time'], 'send_time': ret['send_time'],
}) })
elif ret['manufacturing_type'] == 'rework':
production.programming_record_ids.create({
'number': len(production.programming_record_ids) + 1,
'production_id': production.id,
'reason': '返工',
'programming_method': ret['programme_way'],
'current_programming_count': ret['reprogramming_num'],
'target_production_id': ret['production_order_no'],
'apply_time': ret['trigger_time'],
'send_time': ret['send_time'],
})
elif ret['manufacturing_type'] == 'scrap':
production.programming_record_ids.create({
'number': len(production.programming_record_ids) + 1,
'production_id': production.id,
'reason': '报废',
'programming_method': ret['programme_way'],
'current_programming_count': ret['reprogramming_num'],
'target_production_id': ret['production_order_no'],
'apply_time': ret['trigger_time'],
'send_time': ret['send_time'],
})
elif ret['manufacturing_type'] == 'invalid_tool_rework':
production.programming_record_ids.create({
'number': len(production.programming_record_ids) + 1,
'production_id': production.id,
'reason': '无效功能刀具',
'programming_method': ret['programme_way'],
'current_programming_count': ret['reprogramming_num'],
'target_production_id': ret['production_order_no'],
'apply_time': ret['trigger_time'],
'send_time': ret['send_time'],
})
else:
logging.info('无对应状态,不需更新编程记录')
res.update({ res.update({
'production_ids': productions.ids 'production_ids': productions.ids
}) })
# 对制造订单所有面的cnc工单的程序用刀进行校验
try:
logging.info(f'已更新制造订单:{productions}')
re_tool_chekout = False
re_tool_chekout = productions.production_cnc_tool_checkout()
if re_tool_chekout:
return json.JSONEncoder().encode({'status': -3, 'message': '对cnc工单的程序用刀进行校验失败'})
except Exception as e:
# res = {'status': -2, 'message': '对cnc工单的程序用刀进行校验失败'}
logging.info(f'对cnc工单的程序用刀进行校验报错{e}')
return json.JSONEncoder().encode(res)
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
else: else:
res = {'status': 0, 'message': '没有查询到该制造订单'} res = {'status': 0, 'message': '没有查询到该制造订单'}