diff --git a/sf_manufacturing/__manifest__.py b/sf_manufacturing/__manifest__.py index cffc789a..c6f40b37 100644 --- a/sf_manufacturing/__manifest__.py +++ b/sf_manufacturing/__manifest__.py @@ -26,6 +26,7 @@ 'wizard/production_technology_wizard_views.xml', 'wizard/production_technology_re_adjust_wizard_views.xml', 'wizard/mrp_workorder_batch_replan_wizard_views.xml', + 'wizard/sf_programming_reason_views.xml', 'views/mrp_views_menus.xml', 'views/agv_scheduling_views.xml', 'views/stock_lot_views.xml', diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index dd2bacc1..9a6465d2 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -596,7 +596,8 @@ class MrpProduction(models.Model): logging.info('cron_get_programming_state error:%s' % e) # 编程单更新 - def update_programming_state(self): + # 增加触发时间参数 + def update_programming_state(self, trigger_time=None): try: manufacturing_type = 'rework' if self.is_scrap: @@ -618,6 +619,45 @@ 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('无对应状态,不需更新编程记录') + except Exception as e: logging.info('update_programming_state error:%s' % e) raise UserError("更新编程单状态失败,请联系管理员") @@ -1586,6 +1626,81 @@ 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) + + # 申请编程 + def action_apply_programming(self): + """ + 检查前置条件:制造订单【状态】=“待排程、待加工”,制造订单的【编程状态】=“已编程”。 + """ + print('申请编程') + if len(self) > 1: + raise UserError('仅支持选择单个制造订单进行编程申请,请重新选择') + # problem_productions = [] + # for production in self: + # if production.state not in ['待排程', '待加工'] or production.programming_state != '已编程': + # 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, + } + + # 编程记录 + programming_record_ids = fields.One2many('sf.programming.record', 'production_id') + + # 编程单更新 + def re_programming_update_programming_state(self): + try: + res = {'programming_no': self.programming_no, + 'manufacturing_type': ''} + 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']) + url = '/api/intelligent_programming/reset_state_again' + config_url = configsettings['sf_url'] + url + ret = requests.post(config_url, json=res, data=None, headers=config_header) + ret = ret.json() + result = json.loads(ret['result']) + logging.info('update_programming_state-ret:%s' % result) + if result['status'] == 1: + self.write({'is_rework': True}) + else: + raise UserError(ret['message']) + except Exception as e: + logging.info('update_programming_state error:%s' % e) + raise UserError("更新编程单状态失败,请联系管理员") + +# 编程记录 +class sf_programming_record(models.Model): + _name = 'sf.programming.record' + _description = "编程记录" + + production_id = fields.Many2one('mrp.production') + # 编号、编程原因、编程方式、当前编程次数、目标制造单号、申请时间、下发时间 + number = fields.Char('编号') + reason = fields.Text('重新编程原因') + programming_method = fields.Selection([ + ('auto', '自动'), + ('manual operation', '人工')], string="编程方式") + current_programming_count = fields.Integer('当前编程次数') + target_production_id = fields.Char('目标制造单号') + apply_time = fields.Datetime('申请时间') + send_time = fields.Datetime('下发时间') class sf_detection_result(models.Model): diff --git a/sf_manufacturing/security/ir.model.access.csv b/sf_manufacturing/security/ir.model.access.csv index 4626e3ca..e8c1882f 100644 --- a/sf_manufacturing/security/ir.model.access.csv +++ b/sf_manufacturing/security/ir.model.access.csv @@ -188,5 +188,7 @@ access_mrp_workorder_batch_replan_wizard_group_plan_dispatch,mrp_workorder_batch access_mrp_workorder_group_purchase_director,mrp_workorder,model_mrp_workorder,sf_base.group_purchase_director,1,1,0,0 access_mrp_workorder_group_purchase,mrp_workorder,model_mrp_workorder,sf_base.group_purchase,1,1,0,0 +access_sf_programming_reason,sf_programming_reason,model_sf_programming_reason,base.group_user,1,1,1,0 +access_sf_programming_record,sf_programming_record,model_sf_programming_record,base.group_user,1,1,1,0 access_sf_work_individuation_page,sf_work_individuation_page,model_sf_work_individuation_page,sf_base.group_sf_mrp_user,1,1,1,0 -access_sf_work_individuation_page_group_plan_dispatch,sf_work_individuation_page_group_plan_dispatch,model_sf_work_individuation_page,sf_base.group_plan_dispatch,1,1,0,0 \ No newline at end of file +access_sf_work_individuation_page_group_plan_dispatch,sf_work_individuation_page_group_plan_dispatch,model_sf_work_individuation_page,sf_base.group_plan_dispatch,1,1,0,0 diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index 9b3eded9..2525defd 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -7,6 +7,10 @@ mrp.production + +