diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py
index ce77e87e..df28003e 100644
--- a/sf_manufacturing/models/mrp_production.py
+++ b/sf_manufacturing/models/mrp_production.py
@@ -136,7 +136,8 @@ class MrpProduction(models.Model):
# production.state = 'done'
if any(
(
- wo.test_results == '返工' and wo.state == 'done' and production.programming_state == '已编程') or (
+ wo.test_results == '返工' and wo.state == 'done' and production.programming_state in [
+ '已编程', '已下发']) or (
wo.state == 'rework' and production.programming_state == '编程中') or (
wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中',
'已编程'])
@@ -203,7 +204,7 @@ class MrpProduction(models.Model):
production.write({'programming_state': '已编程未下发' if item[
'programming_state'] == '已编程' else '编程中'})
else:
- return item['programming_state']
+ return item
else:
raise UserError(ret['message'])
@@ -744,10 +745,12 @@ class MrpProduction(models.Model):
# 返工
def button_rework(self):
- cloud_programming_state = None
- if self.programming_state != '已编程' and self.reprogramming_num >= 1:
- cloud_programming_state = self._cron_get_programming_state()
- logging.info('cloud_programming_state:%s' % cloud_programming_state)
+ cloud_programming = None
+ if self.programming_state == '已编程' and self.reprogramming_num >= 0:
+ 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('programming_state:%s' % self.programming_state)
return {
'name': _('返工'),
@@ -757,12 +760,14 @@ class MrpProduction(models.Model):
'target': 'new',
'context': {
'default_production_id': self.id,
- 'default_product_id': self.product_id.id,
- 'default_programming_state': self.programming_state if cloud_programming_state is not None else cloud_programming_state,
- 'default_is_reprogramming': False if (cloud_programming_state in ['编程中',
- '待编程'] and self.programming_state in [
+ 'default_reprogramming_num': self.reprogramming_num,
+ 'default_programming_state': self.programming_state if cloud_programming[
+ 'programming_state'] is None else
+ cloud_programming['programming_state'],
+ 'default_is_reprogramming': False if (cloud_programming['programming_state'] in ['编程中',
+ '待编程'] and self.programming_state in [
'编程中'])
- or (cloud_programming_state in [
+ or (cloud_programming['programming_state'] in [
'已编程'] and self.programming_state in ['已编程未下发']) else True
}
}
@@ -790,11 +795,13 @@ class MrpProduction(models.Model):
if production.programming_no in program_to_production_names:
rework_workorder = production.workorder_ids.filtered(lambda m: m.state == 'rework')
if rework_workorder:
- 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(rework_workorder[0].processing_panel)
- production.write({'state': 'progress', 'programming_state': '已下发'})
+ for rework_item in rework_workorder:
+ pending_workorder = production.workorder_ids.filtered(
+ lambda m1: m1.state in [
+ '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': '已编程'})
# 从cloud获取重新编程过的最新程序
def get_new_program(self, processing_panel):
@@ -808,17 +815,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:
@@ -831,8 +838,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',
- # 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:
@@ -985,7 +992,6 @@ class MrpProduction(models.Model):
return production_values_str
-
class sf_detection_result(models.Model):
_name = 'sf.detection.result'
_description = "检测结果"
diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py
index 30d1453f..599b729c 100644
--- a/sf_manufacturing/models/mrp_workorder.py
+++ b/sf_manufacturing/models/mrp_workorder.py
@@ -19,7 +19,7 @@ from odoo.addons.sf_mrs_connect.models.ftp_operate import FtpController
class ResMrpWorkOrder(models.Model):
_inherit = 'mrp.workorder'
- _order = 'id'
+ _order = 'sequence asc'
product_tmpl_name = fields.Char('坯料产品名称', related='production_bom_id.bom_line_ids.product_id.name')
@@ -47,7 +47,18 @@ class ResMrpWorkOrder(models.Model):
('切割', '切割'), ('表面工艺', '表面工艺')
], string="工序类型")
results = fields.Char('结果')
- state = fields.Selection(selection_add=[('to be detected', "待检测"), ('rework', '返工')], tracking=True)
+ state = fields.Selection([
+ ('pending', '等待其他工单'),
+ ('waiting', '等待组件'),
+ ('ready', '就绪'),
+ ('progress', '进行中'),
+ ('to be detected', "待检测"),
+ ('done', '已完工'),
+ ('rework', '返工'),
+ ('cancel', '取消')], string='Status',
+ compute='_compute_state', store=True,
+ default='pending', copy=False, readonly=True, recursive=True, index=True, tracking=True)
+ # state = fields.Selection(selection_add=[('to be detected', "待检测"), ('rework', '返工')], tracking=True)
manual_quotation = fields.Boolean('人工编程', default=False, readonly=True)
@@ -474,6 +485,7 @@ class ResMrpWorkOrder(models.Model):
'context': {
'default_workorder_id': self.id,
'default_production_id': self.production_id.id,
+ # 'default_programming_state': self.production_id.programming_state,
'default_routing_type': self.routing_type
}}
@@ -684,8 +696,6 @@ class ResMrpWorkOrder(models.Model):
# 'target':'new'
# }
-
-
def json_workorder_str1(self, k, production, route):
workorders_values_str = [0, '', {
'product_uom_id': production.product_uom_id.id,
@@ -736,15 +746,26 @@ class ResMrpWorkOrder(models.Model):
('routing_type', '=', '装夹预调'), ('state', '=', 'done')])
if pre_workorder:
workorder.state = 'waiting'
+ if workorder.routing_type == '解除装夹' and workorder.state not in ['done', 'rework', 'cancel']:
+ cnc_workorder = self.env['mrp.workorder'].search(
+ [('production_id', '=', workorder.production_id.id),
+ ('processing_panel', '=', workorder.processing_panel),
+ ('routing_type', '=', 'CNC加工'), ('state', '=', 'done')])
+ if cnc_workorder:
+ workorder.state = 'waiting'
elif workorder.production_id.state == 'progress':
logging.info('len(re_work):%s' % len(re_work))
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('reprogramming_num:%s' % workorder.production_id.reprogramming_num)
logging.info('编程状态:%s' % workorder.production_id.programming_state)
logging.info('制造状态:%s' % workorder.production_id.state)
- if workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已下发':
+ if workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已编程' and \
+ workorder.is_rework is False and workorder.state not in [
+ 'done', 'rework',
+ 'cancel']:
if re_work:
workorder.state = 'ready'
# else:
diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml
index 2616d38f..28da8c14 100644
--- a/sf_manufacturing/views/mrp_production_addional_change.xml
+++ b/sf_manufacturing/views/mrp_production_addional_change.xml
@@ -75,20 +75,21 @@
-
+
-
+
@@ -123,7 +124,7 @@
confirm="是否确认更新程序"
attrs="{'invisible': ['|',('state', '!=', 'rework'),('programming_state', '!=', '已编程未下发')]}"/>
+ attrs="{'invisible': ['|',('state', '!=', 'rework') ,'&',('programming_state', '!=', '已编程'),('is_rework', '=', True)]}"/>
@@ -281,7 +282,7 @@
-
+
diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml
index 5fa77224..2f5aa9f6 100644
--- a/sf_manufacturing/views/mrp_workorder_view.xml
+++ b/sf_manufacturing/views/mrp_workorder_view.xml
@@ -112,6 +112,10 @@
mrp.workorder
+
+
+
-
+
diff --git a/sf_manufacturing/wizard/rework_wizard.py b/sf_manufacturing/wizard/rework_wizard.py
index 4ad7c163..c0ba453b 100644
--- a/sf_manufacturing/wizard/rework_wizard.py
+++ b/sf_manufacturing/wizard/rework_wizard.py
@@ -26,7 +26,8 @@ class ReworkWizard(models.TransientModel):
is_reprogramming = fields.Boolean(string='申请重新编程', default=False)
reprogramming_num = fields.Integer('重新编程次数', default=0)
programming_state = fields.Selection(
- [('待编程', '待编程'), ('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发')],
+ [('待编程', '待编程'), ('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'),
+ ('已下发', '已下发')],
string='编程状态')
def confirm(self):