From d8a816c90e5928d3ff355f0c62ba70d0978ed7c2 Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Mon, 13 Jan 2025 16:51:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=86=99=E5=85=A5=E7=BC=96?= =?UTF-8?q?=E7=A8=8B=E8=AE=B0=E5=BD=95=E7=9A=84=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 133 +++++++++--------- .../views/mrp_production_addional_change.xml | 1 + sf_mrs_connect/controllers/controllers.py | 62 ++++++-- 3 files changed, 118 insertions(+), 78 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 56a55e67..b9d0184c 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -55,7 +55,7 @@ class MrpProduction(models.Model): production.sale_order_id = sale_order.id else: logging.warning("No sale order found for production {} with product {} (name match: {})".format( - production.id, production.product_id.name, result)) + production.id, production.product_id.name, result)) except Exception as e: logging.error("Error while fetching sale order for production {}: {}".format(production.id, str(e))) @@ -364,15 +364,16 @@ class MrpProduction(models.Model): # 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 (wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中', '已编程']) - for wo in production.workorder_ids): + or (wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中', '已编程']) + for wo in production.workorder_ids): production.state = 'rework' if any(wo.test_results == '报废' and wo.state == 'done' for wo in production.workorder_ids): production.state = 'scrap' if any(dr.test_results == '报废' and dr.handle_result == '已处理' for dr in production.detection_result_ids): production.state = 'cancel' - if production.workorder_ids and all(wo_state in ('done', 'rework', 'cancel') for wo_state in production.workorder_ids.mapped('state')): + if production.workorder_ids and all( + wo_state in ('done', 'rework', 'cancel') for wo_state in production.workorder_ids.mapped('state')): if production.state not in ['scrap', 'rework', 'cancel']: production.state = 'done' @@ -447,7 +448,7 @@ class MrpProduction(models.Model): if account.state not in ['cancel', False]: if account.name not in account_moves: account_moves.append(account.name) - if purchase.state not in ['cancel','draft', False]: + if purchase.state not in ['cancel', 'draft', False]: purchase_orders.append(purchase.name) special_design = self.technology_design_ids.filtered( lambda a: a.routing_tag == 'special' and a.is_auto is False) @@ -460,7 +461,7 @@ class MrpProduction(models.Model): if not product_production_process: if special.process_parameters_id not in process_parameters: process_parameters.append(special.process_parameters_id.display_name) - + if account_moves: raise UserError(_("请联系工厂生产经理对该(%s)账单进行取消", ", ".join(account_moves))) if purchase_orders: @@ -585,7 +586,7 @@ class MrpProduction(models.Model): for rp in reproduction: if rp.programming_no == item['programming_no']: rp.write({'programming_state': '已编程未下发' if item[ - 'programming_state'] == '已编程' else '编程中'}) + 'programming_state'] == '已编程' else '编程中'}) else: return item @@ -605,7 +606,8 @@ class MrpProduction(models.Model): elif self.tool_state == '2': manufacturing_type = 'invalid_tool_rework' res = {'programming_no': self.programming_no, - 'manufacturing_type': manufacturing_type} + 'manufacturing_type': manufacturing_type, + 'trigger_time': trigger_time} 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']) @@ -619,44 +621,44 @@ 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('无对应状态,不需更新编程记录') + + # # 增加对编程记录的更新 + # 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) @@ -974,8 +976,8 @@ class MrpProduction(models.Model): # 对工单进行逐个插入 for work_id in work_ids: order_rework_ids = rec.workorder_ids.filtered( - lambda item: (item.sequence > 0 and work_id.name == item.name - and work_id.processing_panel == item.processing_panel)) + lambda item: (item.sequence > 0 and work_id.name == item.name + and work_id.processing_panel == item.processing_panel)) order_rework_ids = sorted(order_rework_ids, key=lambda item: item.sequence, reverse=True) work_id.sequence = order_rework_ids[0].sequence + 1 # 对该工单之后的工单工序进行加一 @@ -1547,7 +1549,7 @@ class MrpProduction(models.Model): if not vals.get('procurement_group_id'): product_id = self.env['product.product'].browse(vals['product_id']) if product_id.product_tmpl_id.single_manufacturing: - if product_id.categ_id.name =='成品': + if product_id.categ_id.name == '成品': vals['procurement_group_id'] = group_id continue if product_id.id not in product_group_id.keys(): @@ -1640,7 +1642,7 @@ 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) # 申请编程 @@ -1657,27 +1659,27 @@ class MrpProduction(models.Model): # 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, - } + '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, @@ -1699,6 +1701,7 @@ class MrpProduction(models.Model): logging.info('update_programming_state error:%s' % e) raise UserError("更新编程单状态失败,请联系管理员") + # 编程记录 class sf_programming_record(models.Model): _name = 'sf.programming.record' @@ -1750,7 +1753,7 @@ class sf_detection_result(models.Model): 'views': [(self.env.ref('sf_manufacturing.sf_test_report_form').id, 'form')], 'target': 'new' } - + def write(self, vals): if vals.get('handle_result') and vals.get('handle_result') == '已处理': vals['handle_result_date'] = fields.Datetime.now() diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index 2525defd..19d2051f 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -87,6 +87,7 @@