diff --git a/jikimo_workorder_exception/controllers/main.py b/jikimo_workorder_exception/controllers/main.py index 03744ff9..cf208700 100644 --- a/jikimo_workorder_exception/controllers/main.py +++ b/jikimo_workorder_exception/controllers/main.py @@ -4,6 +4,7 @@ import json import logging from odoo.addons.sf_mrs_connect.controllers.controllers import Sf_Mrs_Connect from odoo.addons.sf_manufacturing.controllers.controllers import Manufacturing_Connect +from datetime import datetime _logger = logging.getLogger(__name__) @@ -30,6 +31,7 @@ class WorkorderExceptionConroller(http.Controller): workorder = request.env['mrp.workorder'].sudo().search([ ('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', 'CNC加工'), + ('state', '!=', 'rework') ]) if not workorder: res = {'Succeed': False, 'ErrorCode': 401, 'Error': '无效的工单'} @@ -41,7 +43,10 @@ class WorkorderExceptionConroller(http.Controller): 'exception_code': ret.get('coding'), 'exception_content': ret.get('Error', '') }) - + # 申请重新编程 + workorder.production_id.update_programming_state(trigger_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), + reprogramming_reason=ret.get('Error', '')) + workorder.production_id.write({'programming_state': '编程中', 'work_state': '编程中', 'is_rework': False}) except Exception as e: res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} _logger.info('workder_exception error:%s' % e) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index d7c6d53d..c8ea012a 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -577,16 +577,19 @@ class MrpProduction(models.Model): # 编程单更新 # 增加触发时间参数 - def update_programming_state(self, trigger_time=None): + def update_programming_state(self, trigger_time=None, reprogramming_reason=None): try: - manufacturing_type = 'rework' + manufacturing_type = None if self.is_scrap: manufacturing_type = 'scrap' elif self.tool_state == '2': manufacturing_type = 'invalid_tool_rework' + elif self.is_rework: + manufacturing_type = 'rework' res = {'programming_no': self.programming_no, 'manufacturing_type': manufacturing_type, - 'trigger_time': trigger_time} + 'trigger_time': trigger_time, + 'reprogramming_reason': reprogramming_reason} 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']) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 8d4dcaa4..ef121e1b 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -455,32 +455,32 @@ class ResMrpWorkOrder(models.Model): ("technology", "工艺"), ("customer redrawing", "客户改图")], string="原因", tracking=True) detailed_reason = fields.Text('详细原因') is_rework = fields.Boolean(string='是否返工', default=False) - rework_flag = fields.Boolean(string='返工标志', compute='_compute_rework_flag') - - @api.depends('state', 'production_line_state') - def _compute_rework_flag(self): - for record in self: - if record.state == 'done' and record.routing_type == '装夹预调': - next_workorder = record.production_id.workorder_ids.filtered( - lambda w: w.sequence == record.sequence + 1) - if next_workorder and next_workorder.routing_type == 'CNC加工' and next_workorder.state in ['ready', - 'waiting', - 'pending'] and next_workorder.production_line_state == '待上产线': - record.rework_flag = False - elif next_workorder and next_workorder.routing_type == '表面工艺' and next_workorder.state in ['ready', - 'waiting', - 'pending']: - record.rework_flag = False - else: - record.rework_flag = True - else: - record.rework_flag = True - - def button_rework(self): - for item in self: - item.state = 'progress' - for time_id in item.time_ids: - time_id.write({'date_end': None}) + # rework_flag = fields.Boolean(string='返工标志', compute='_compute_rework_flag') + # + # @api.depends('state', 'production_line_state') + # def _compute_rework_flag(self): + # for record in self: + # if record.state == 'done' and record.routing_type == '装夹预调': + # next_workorder = record.production_id.workorder_ids.filtered( + # lambda w: w.sequence == record.sequence + 1) + # if next_workorder and next_workorder.routing_type == 'CNC加工' and next_workorder.state in ['ready', + # 'waiting', + # 'pending'] and next_workorder.production_line_state == '待上产线': + # record.rework_flag = False + # elif next_workorder and next_workorder.routing_type == '表面工艺' and next_workorder.state in ['ready', + # 'waiting', + # 'pending']: + # record.rework_flag = False + # else: + # record.rework_flag = True + # else: + # record.rework_flag = True + # + # def button_rework(self): + # for item in self: + # item.state = 'progress' + # for time_id in item.time_ids: + # time_id.write({'date_end': None}) def button_change_env(self): self.is_test_env = not self.is_test_env diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 07449124..3dba032c 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -163,7 +163,7 @@ - + @@ -212,9 +212,9 @@ attrs="{'invisible': ['|', '|', '|', ('routing_type','!=','装夹预调'),('state','!=','progress'), ('is_trayed', '=', False), ('state', 'in', ('done'))]}"/>