Accept Merge Request #1740: (feature/制造功能优化 -> develop)

Merge Request: 调整写入编程记录的位置

Created By: @马广威
Accepted By: @马广威
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1740?initial=true
This commit is contained in:
马广威
2025-01-13 16:58:14 +08:00
committed by Coding
3 changed files with 125 additions and 76 deletions

View File

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

View File

@@ -87,6 +87,7 @@
<field name="arch" type="xml">
<xpath expr="//header//button[last()]" position="after">
<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"/>
</xpath>
<xpath expr="//field[@name='state']" position="attributes">

View File

@@ -39,6 +39,7 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
res = {'status': -2, 'message': '查询到待工艺确认的制造订单'}
return json.JSONEncoder().encode(res)
if productions:
# 拉取所有加工面的程序文件
for r in ret['processing_panel'].split(','):
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': '已编程'})
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:
record_ids_obj = production.programming_record_ids.filtered(
@@ -115,7 +128,7 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
'apply_time': False,
'send_time': ret['send_time'],
})
if ret['reset_flag']:
elif ret['reset_flag']:
production.programming_record_ids.create({
'number': len(production.programming_record_ids) + 1,
'production_id': production.id,
@@ -126,23 +139,46 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
'apply_time': False,
'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({
'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)
else:
res = {'status': 0, 'message': '没有查询到该制造订单'}