From f6a9c97e7f7ef8dc50b9127df4070225aedcc867 Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Wed, 11 Sep 2024 08:51:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=A7=E9=87=8F=E9=83=A8?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/controllers/controllers.py | 29 +++++++++++-------- sf_plan/models/custom_plan.py | 25 ++++++++++++++-- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 6e661f46..6f692bde 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -301,21 +301,21 @@ class Sf_Dashboard_Connect(http.Controller): try: plan_obj = request.env['sf.production.plan'].sudo() + production_obj = request.env['mrp.production'].sudo() line_list = ast.literal_eval(kw['line_list']) print('line_list: %s' % line_list) for line in line_list: - plan_data = plan_obj.search([('production_line_id.name', '=', line)]) - # 工单总量 - plan_data_total_counts = plan_obj.search_count([('production_line_id.name', '=', line)]) + + # 工单计划量 + plan_data_total_counts = production_obj.search_count( + [('production_line_id.name', '=', line), ('state', 'not in', ['cancel']), + ('active', '=', True)]) # 工单完成量 plan_data_finish_counts = plan_obj.search_count( [('production_line_id.name', '=', line), ('state', 'in', ['finished'])]) - # 工单计划量 - plan_data_plan_counts = plan_obj.search_count( - [('production_line_id.name', '=', line), ('state', 'not in', ['finished'])]) - # # 工单不良累计 - # plan_data_fault_counts = plan_obj.search_count( - # [('production_line_id.name', '=', line), ('production_id.detection_result_ids.state', 'in', ['返工', '报废'])]) + # # 工单计划量 + # plan_data_plan_counts = plan_obj.search_count( + # [('production_line_id.name', '=', line), ('state', 'not in', ['finished'])]) # 查找符合条件的生产计划记录 plan_data = plan_obj.search([ @@ -327,8 +327,13 @@ class Sf_Dashboard_Connect(http.Controller): result.test_results in ['返工', '报废'] for result in p.production_id.detection_result_ids )) + # 查找制造订单取消与归档的数量 + cancel_order_count = production_obj.search_count( + [('production_line_id.name', '=', line), ('state', 'in', ['cancel']), + ('active', '=', False)]) + # 计算符合条件的记录数量 - plan_data_fault_counts = len(faulty_plans) + plan_data_fault_counts = len(faulty_plans) + cancel_order_count # 工单返工数量 @@ -340,13 +345,13 @@ class Sf_Dashboard_Connect(http.Controller): (plan_data_finish_counts / plan_data_total_counts if plan_data_total_counts > 0 else 0), 3) # 工单进度偏差 - plan_data_progress_deviation = plan_data_finish_counts - plan_data_plan_counts + plan_data_progress_deviation = plan_data_total_counts - plan_data_finish_counts - plan_data_fault_counts if plan_data: data = { 'plan_data_total_counts': plan_data_total_counts, 'plan_data_finish_counts': plan_data_finish_counts, - 'plan_data_plan_counts': plan_data_plan_counts, + 'plan_data_plan_counts': plan_data_total_counts, 'plan_data_fault_counts': plan_data_fault_counts, 'finishe_rate': finishe_rate, 'plan_data_progress_deviation': plan_data_progress_deviation, diff --git a/sf_plan/models/custom_plan.py b/sf_plan/models/custom_plan.py index c4043d33..b3bd6ff6 100644 --- a/sf_plan/models/custom_plan.py +++ b/sf_plan/models/custom_plan.py @@ -18,7 +18,8 @@ class sf_production_plan(models.Model): ('draft', '待排程'), ('done', '已排程'), ('processing', '加工中'), - ('finished', '已完成') + ('finished', '已完成'), + ('cancel', '已取消') ], string='状态', tracking=True) state_order = fields.Integer(compute='_compute_state_order', store=True) @@ -37,7 +38,7 @@ class sf_production_plan(models.Model): _order = 'state_order asc, write_date desc' name = fields.Char(string='制造订单') - # active = fields.Boolean(string='已归档', default=True) + active = fields.Boolean(string='已归档', default=True) # selected = fields.Boolean(default=False) # order_number = fields.Char(string='订单号') order_deadline = fields.Datetime(string='订单交期') @@ -385,3 +386,23 @@ class machine_work_schedule(models.Model): _description = '机台作业计划' name = fields.Char(string='机台名') + + +class MrpProductionInheritForPlan(models.Model): + _inherit = 'mrp.production' + + def button_cancel(self): + # 调用父类的取消操作 + res = super(MrpProductionInheritForPlan, self).button_cancel() + # 更新 sf.production.plan 模型的 state 为 'cancel' + self.env['sf.production.plan'].search([('production_id', '=', self.id)]).write({'state': 'cancel'}) + return res + + def toggle_active(self): + # 调用父类方法切换 active 状态 + res = super(MrpProductionInheritForPlan, self).toggle_active() + self.env['sf.production.plan'].search( + [('production_id', '=', self.id), '|', ('active', '=', False), ('active', '=', True)]).write( + {'active': self.active}) + + return res