修复返工操作时工单状态及制造订单更新程序
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import base64
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
from itertools import groupby
|
||||
@@ -106,11 +107,6 @@ class MrpProduction(models.Model):
|
||||
elif not production.workorder_ids and float_compare(production.qty_producing, production.product_qty,
|
||||
precision_rounding=production.product_uom_id.rounding) >= 0:
|
||||
production.state = 'to_close'
|
||||
elif any(
|
||||
(wo.test_results == '返工' and wo.state == 'done') or wo.state == 'rework' or (
|
||||
wo.is_rework is True and wo.state == 'done') for wo in
|
||||
production.workorder_ids):
|
||||
production.state = 'rework'
|
||||
elif any(wo_state in ('progress', 'done') for wo_state in production.workorder_ids.mapped('state')):
|
||||
production.state = 'progress'
|
||||
elif production.product_uom_id and not float_is_zero(production.qty_producing,
|
||||
@@ -136,6 +132,12 @@ class MrpProduction(models.Model):
|
||||
if production.state == 'pending_cam':
|
||||
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 programming_state == '编程中') or wo.state == 'rework' or (
|
||||
wo.is_rework is True and wo.state == 'done') for wo in
|
||||
production.workorder_ids):
|
||||
production.state = 'rework'
|
||||
|
||||
def action_check(self):
|
||||
"""
|
||||
@@ -781,6 +783,18 @@ class MrpProduction(models.Model):
|
||||
# 更新程序
|
||||
def do_update_program(self):
|
||||
program_production = self
|
||||
if len(program_production) >= 1:
|
||||
same_product_id = None
|
||||
is_not_same_product = 0
|
||||
for item in program_production:
|
||||
if same_product_id is None:
|
||||
same_product_id = item.product_id
|
||||
if item.product_id != same_product_id:
|
||||
is_not_same_product += 1
|
||||
if item.state != "rework" and item.programming_state != "已编程未下发":
|
||||
raise UserError("请选择状态为返工且已编程未下发的制造订单")
|
||||
if is_not_same_product >= 1:
|
||||
raise UserError("您选择的记录中含有其他产品的制造订单,请选择同一产品的制造订单")
|
||||
grouped_program_ids = {k: list(g) for k, g in groupby(program_production, key=lambda x: x.programming_no)}
|
||||
program_to_production_names = {}
|
||||
for programming_no, program_production in grouped_program_ids.items():
|
||||
@@ -792,7 +806,7 @@ class MrpProduction(models.Model):
|
||||
new_pancel_workorder = production.workorder_ids.filtered(
|
||||
lambda m1: m1.state != 'rework' and m1.processing_panel == rework_workorder[0].processing_panel)
|
||||
if not new_pancel_workorder.cnc_ids:
|
||||
production.get_new_program(workorder[0].processing_panel)
|
||||
production.get_new_program(rework_workorder[0].processing_panel)
|
||||
rework_production = self.env['mrp.production'].search(
|
||||
[('state', '=', 'rework'), ('programming_no', '=', production.programming_no)])
|
||||
if rework_production:
|
||||
@@ -813,17 +827,17 @@ class MrpProduction(models.Model):
|
||||
r = r.json()
|
||||
result = json.loads(r['result'])
|
||||
if result['status'] == 1:
|
||||
program_path_tmp_panel = os.path.join('/tmp', result['folder_name'], 'return', processing_panel)
|
||||
if os.path.exists(program_path_tmp_panel):
|
||||
files_r = os.listdir(program_path_tmp_panel)
|
||||
if files_r:
|
||||
for file_name in files_r:
|
||||
file_path = os.path.join(program_path_tmp_panel, file_name)
|
||||
os.remove(file_path)
|
||||
download_state = self.env['sf.cnc.processing'].download_file_tmp(result['folder_name'],
|
||||
processing_panel)
|
||||
if download_state is False:
|
||||
raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no))
|
||||
# program_path_tmp_panel = os.path.join('/tmp', result['folder_name'], 'return', processing_panel)
|
||||
# if os.path.exists(program_path_tmp_panel):
|
||||
# files_r = os.listdir(program_path_tmp_panel)
|
||||
# if files_r:
|
||||
# for file_name in files_r:
|
||||
# file_path = os.path.join(program_path_tmp_panel, file_name)
|
||||
# os.remove(file_path)
|
||||
# download_state = self.env['sf.cnc.processing'].download_file_tmp(result['folder_name'],
|
||||
# processing_panel)
|
||||
# if download_state is False:
|
||||
# raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no))
|
||||
productions = self.env['mrp.production'].search(
|
||||
[('programming_no', '=', self.programming_no), ('state', 'not in', ['cancel,done'])])
|
||||
if productions:
|
||||
@@ -836,8 +850,8 @@ class MrpProduction(models.Model):
|
||||
panel_workorder.cnc_ids.sudo().unlink()
|
||||
self.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan(
|
||||
productions)
|
||||
# program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
|
||||
# panel)
|
||||
program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
|
||||
processing_panel)
|
||||
logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel)
|
||||
files_panel = os.listdir(program_path_tmp_panel)
|
||||
if files_panel:
|
||||
@@ -847,8 +861,8 @@ class MrpProduction(models.Model):
|
||||
panel_file_path = os.path.join(program_path_tmp_panel, file)
|
||||
logging.info('panel_file_path:%s' % panel_file_path)
|
||||
panel_workorder.write(
|
||||
{'cnc_ids': panel_workorder.cnc_ids.sudo()._json_cnc_processing(processing_panel, ret),
|
||||
'cmm_ids': panel_workorder.cmm_ids.sudo()._json_cmm_program(processing_panel, ret),
|
||||
{'cnc_ids': panel_workorder.cnc_ids.sudo()._json_cnc_processing(processing_panel, result),
|
||||
'cmm_ids': panel_workorder.cmm_ids.sudo()._json_cmm_program(processing_panel, result),
|
||||
'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
|
||||
pre_workorder = productions.workorder_ids.filtered(lambda
|
||||
ap: ap.routing_type == '装夹预调' and ap.processing_panel == processing_panel and ap.state != 'rework')
|
||||
@@ -859,7 +873,7 @@ class MrpProduction(models.Model):
|
||||
raise UserError(result['message'])
|
||||
except Exception as e:
|
||||
logging.info('get_new_program error:%s' % e)
|
||||
raise UserError("从cloud获取最新程序失败,请联系管理员")
|
||||
raise UserError("从云平台获取最新程序失败,请联系管理员")
|
||||
|
||||
|
||||
class sf_detection_result(models.Model):
|
||||
|
||||
@@ -824,19 +824,36 @@ class ResMrpWorkOrder(models.Model):
|
||||
def _compute_state(self):
|
||||
super()._compute_state()
|
||||
for workorder in self:
|
||||
if workorder.routing_type == '装夹预调' and workorder.state not in ['done', 'cancel', 'progress', 'rework']:
|
||||
re_work = self.env['mrp.workorder'].search(
|
||||
[('routing_type', '=', '装夹预调'), ('production_id', '=', workorder.production_id.id),
|
||||
('processing_panel', '=', workorder.processing_panel), ('state', '=', 'rework')])
|
||||
if re_work:
|
||||
workorder.state = 'waiting'
|
||||
elif workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'cancel', 'progress',
|
||||
'rework']:
|
||||
per_work = self.env['mrp.workorder'].search(
|
||||
[('routing_type', '=', '装夹预调'), ('production_id', '=', workorder.production_id.id),
|
||||
('processing_panel', '=', workorder.processing_panel), ('is_rework', '=', True)])
|
||||
if per_work:
|
||||
re_work = self.env['mrp.workorder'].search([('production_id', '=', workorder.production_id.id),
|
||||
('processing_panel', '=', workorder.processing_panel),
|
||||
('is_rework', '=', True), ('state', 'in', ['done', 'rework'])])
|
||||
if workorder.state not in ['cancel', 'progress', 'rework']:
|
||||
logging.info('工序:%s' % workorder.routing_type)
|
||||
logging.info('状态:%s' % workorder.state)
|
||||
logging.info('is_rework:%s' % workorder.is_rework)
|
||||
logging.info('面:%s' % workorder.processing_panel)
|
||||
logging.info('编程状态:%s' % workorder.production_id.programming_state)
|
||||
logging.info('制造状态:%s' % workorder.production_id.state)
|
||||
# if workorder.state =='done' and workorder.is_rework is True:
|
||||
# workorder.state = 'rework'
|
||||
# else:
|
||||
# if re_work:
|
||||
# workorder.state = 'rework'
|
||||
if workorder.production_id.state == 'rework':
|
||||
if (workorder.routing_type == 'CNC加工' and re_work.state == 'done') or (
|
||||
workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '编程中' and re_work):
|
||||
logging.info('面111:%s' % workorder.processing_panel)
|
||||
workorder.state = 'waiting'
|
||||
# else:
|
||||
# if workorder.state not in ['cancel', 'rework']:
|
||||
# workorder.state = 'rework'
|
||||
# elif workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'cancel', 'progress',
|
||||
# 'rework']:
|
||||
# per_work = self.env['mrp.workorder'].search(
|
||||
# [('routing_type', '=', '装夹预调'), ('production_id', '=', workorder.production_id.id),
|
||||
# ('processing_panel', '=', workorder.processing_panel), ('is_rework', '=', True)])
|
||||
# if per_work:
|
||||
# workorder.state = 'waiting'
|
||||
# if workorder.routing_type == 'CNC加工' and workorder.state == 'progress':
|
||||
# workorder.state = 'to be detected'
|
||||
# for workorder in self:
|
||||
@@ -1031,10 +1048,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
record.write({
|
||||
'date_planned_finished': tem_date_planned_finished # 保持原值
|
||||
})
|
||||
# if record.routing_type == 'CNC加工':
|
||||
# record.write({
|
||||
# 'date_finished': tem_date_finished # 保持原值
|
||||
# })
|
||||
|
||||
# if record.routing_type == 'CNC加工' and record.test_results in ['返工', '报废']:
|
||||
# record.production_id.action_cancel()
|
||||
# record.production_id.workorder_ids.write({'rfid_code': False, 'rfid_code_old': record.rfid_code})
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
<field name="model">mrp.production</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<!-- <xpath expr="//button[@name='do_unreserve']" position="after">-->
|
||||
<!-- <button name="do_update_program" type="object" string="更新程序"/>-->
|
||||
<!-- </xpath>-->
|
||||
<xpath expr="//button[@name='do_unreserve']" position="after">
|
||||
<button name="do_update_program" type="object" string="更新程序"
|
||||
groups="sf_base.group_sf_mrp_user"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='product_id']" position="replace"/>
|
||||
<xpath expr="//field[@name='product_qty']" position="replace"/>
|
||||
<xpath expr="//field[@name='product_uom_id']" position="replace"/>
|
||||
@@ -121,7 +122,7 @@
|
||||
confirm="是否确认更新程序"
|
||||
attrs="{'invisible': ['&',('state', '!=', 'rework'), ('programming_state', '!=', '已编程未下发')]}"/>
|
||||
<button name="button_rework" string="返工" type="object" groups="sf_base.group_sf_mrp_user"
|
||||
attrs="{'invisible': [('state', '!=', 'rework')]}"/>
|
||||
attrs="{'invisible': [('state', '!=', 'rework'), ('programming_state', '!=', '已编程')]}"/>
|
||||
<button name="button_scrap_new" string="报废" type="object" groups="sf_base.group_sf_mrp_user"
|
||||
confirm="是否确认报废" attrs="{'invisible': [('state', '!=', 'cancel')]}"/>
|
||||
</xpath>
|
||||
|
||||
@@ -36,7 +36,7 @@ class ReworkWizard(models.TransientModel):
|
||||
'detailed_reason': self.detailed_reason,
|
||||
'processing_panel': self.workorder_id.processing_panel,
|
||||
'routing_type': self.workorder_id.routing_type,
|
||||
'handle_result': '待处理' if self.test_results == '返工' else '',
|
||||
'handle_result': '待处理' if self.workorder_id.test_results == '返工' or self.workorder_id.is_rework is True else '',
|
||||
'test_results': '返工' if not self.routing_type == 'CNC加工' else self.workorder_id.test_results,
|
||||
'test_report': self.workorder_id.detection_report})]})
|
||||
self.workorder_id.button_finish()
|
||||
@@ -75,7 +75,7 @@ class ReworkWizard(models.TransientModel):
|
||||
for item in self:
|
||||
domain = [('id', '=', False)]
|
||||
production_id = item.production_id
|
||||
if product_id:
|
||||
if production_id:
|
||||
if self.env.user.has_group('sf_base.group_sf_order_user'):
|
||||
panel_ids = []
|
||||
for p in production_id.detection_result_ids.filtered(
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
<field name="is_reprogramming"
|
||||
attrs='{"invisible": [("programming_state","=",False)],"readonly": [("programming_state","in",["编程中","已编程未下发时"])]}'/>
|
||||
<field name="rework_reason"
|
||||
attrs='{"invisible": [("routing_type","!=","")],"required": [("routing_type","in",["装夹预调"])]}'/>
|
||||
attrs='{"invisible": [("routing_type","not in",["装夹预调","CNC加工"])],"required": [("routing_type","in",["装夹预调"])]}'/>
|
||||
<field name="detailed_reason"
|
||||
attrs='{"invisible": [("routing_type","!=","")],"required": [("routing_type","in",["装夹预调"])]}'/>
|
||||
attrs='{"invisible": [("routing_type","not in",["装夹预调","CNC加工"])],"required": [("routing_type","in",["装夹预调"])]}'/>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="确认" name="confirm" type="object" class="oe_highlight" confirm="是否确认返工"/>
|
||||
|
||||
Reference in New Issue
Block a user