修复返工bug
This commit is contained in:
@@ -53,7 +53,6 @@ class MrpProduction(models.Model):
|
||||
check_status = fields.Boolean(string='启用状态', default=False, readonly=True)
|
||||
active = fields.Boolean(string='已归档', default=True)
|
||||
programming_no = fields.Char('编程单号')
|
||||
reprogramming_num = fields.Integer('重新编程次数', default=0)
|
||||
work_state = fields.Char('业务状态')
|
||||
programming_state = fields.Selection(
|
||||
[('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'), ('已下发', '已下发')],
|
||||
@@ -131,13 +130,15 @@ class MrpProduction(models.Model):
|
||||
if all(wo_state not in ('progress', 'done', 'rework') for wo_state in
|
||||
production.workorder_ids.mapped('state')):
|
||||
production.state = 'pending_cam'
|
||||
if production.is_rework is True:
|
||||
production.state = 'rework'
|
||||
# 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 production.programming_state in [
|
||||
'已编程', '已下发']) or (
|
||||
'已编程']) or (
|
||||
wo.state == 'rework' and production.programming_state == '编程中') or (
|
||||
wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中',
|
||||
'已编程'])
|
||||
@@ -179,11 +180,12 @@ class MrpProduction(models.Model):
|
||||
try:
|
||||
if not self:
|
||||
reproduction = self.env['mrp.production'].search(
|
||||
[('state', '=', 'rework'), ('programming_state', '=', '编程中')])
|
||||
[('state', '=', 'rework'), ('programming_state', '=', '编程中'), ('is_rework', '=', True)])
|
||||
else:
|
||||
reproduction = self
|
||||
if reproduction:
|
||||
programming_no = [item.programming_no for item in reproduction]
|
||||
programming_no_set = set([str(item.programming_no) for item in reproduction])
|
||||
programming_no = list(programming_no_set)
|
||||
programming_no_str = ','.join(programming_no)
|
||||
res = {'programming_no': programming_no_str}
|
||||
logging.info('res=%s:' % res)
|
||||
@@ -199,7 +201,8 @@ class MrpProduction(models.Model):
|
||||
for item in result['programming_list']:
|
||||
if not self:
|
||||
production = self.env['mrp.production'].search(
|
||||
[('state', '=', 'rework'), ('programming_no', '=', item['programming_no'])])
|
||||
[('state', '=', 'rework'),
|
||||
('programming_no', '=', item['programming_no'], ('is_rework', '=', True))])
|
||||
if production:
|
||||
production.write({'programming_state': '已编程未下发' if item[
|
||||
'programming_state'] == '已编程' else '编程中'})
|
||||
@@ -746,17 +749,10 @@ class MrpProduction(models.Model):
|
||||
# 返工
|
||||
def button_rework(self):
|
||||
cloud_programming = None
|
||||
is_reprogramming = False
|
||||
if self.programming_state == '已编程' and self.reprogramming_num >= 0:
|
||||
if self.programming_state in ['已编程']:
|
||||
cloud_programming = self._cron_get_programming_state()
|
||||
if self.reprogramming_num == 0:
|
||||
self.reprogramming_num = cloud_programming['reprogramming_num']
|
||||
logging.info('cloud_programming_state:%s' % cloud_programming['programming_state'])
|
||||
logging.info('cloud_programming_state:%s' % cloud_programming['programming_state'])
|
||||
logging.info('programming_state:%s' % self.programming_state)
|
||||
if cloud_programming is None:
|
||||
if self.reprogramming_num > 1:
|
||||
is_reprogramming = False
|
||||
|
||||
return {
|
||||
'name': _('返工'),
|
||||
'type': 'ir.actions.act_window',
|
||||
@@ -765,9 +761,8 @@ class MrpProduction(models.Model):
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_production_id': self.id,
|
||||
'default_reprogramming_num': self.reprogramming_num,
|
||||
'default_programming_state': self.programming_state if cloud_programming is None else
|
||||
cloud_programming['programming_state'],
|
||||
'default_reprogramming_num': cloud_programming['reprogramming_num'],
|
||||
'default_programming_state': cloud_programming['programming_state'],
|
||||
'default_is_reprogramming': False if (cloud_programming['programming_state'] in ['编程中',
|
||||
'待编程'] and self.programming_state in [
|
||||
'编程中'])
|
||||
@@ -805,7 +800,7 @@ class MrpProduction(models.Model):
|
||||
'pending'] and m1.processing_panel == rework_item.processing_panel and m1.routing_type == 'CNC加工')
|
||||
if not pending_workorder.cnc_ids:
|
||||
production.get_new_program(rework_item.processing_panel)
|
||||
production.write({'state': 'progress', 'programming_state': '已编程'})
|
||||
production.write({'state': 'progress', 'programming_state': '已编程', 'is_rework': False})
|
||||
|
||||
# 从cloud获取重新编程过的最新程序
|
||||
def get_new_program(self, processing_panel):
|
||||
@@ -819,31 +814,32 @@ 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'])])
|
||||
[('programming_no', '=', self.programming_no), ('state', 'not in', ('cancel', 'done'))])
|
||||
if productions:
|
||||
panel_workorder = productions.workorder_ids.filtered(
|
||||
lambda
|
||||
ac: ac.processing_panel == processing_panel and ac.routing_type == 'CNC加工' and ac.state != 'rework')
|
||||
ac: ac.processing_panel == processing_panel and ac.routing_type == 'CNC加工' and ac.state not in (
|
||||
'rework', 'done'))
|
||||
if panel_workorder:
|
||||
if panel_workorder.cnc_ids:
|
||||
panel_workorder.cmm_ids.sudo().unlink()
|
||||
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',
|
||||
# processing_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:
|
||||
|
||||
Reference in New Issue
Block a user