diff --git a/sf_manufacturing/models/mrp_workcenter.py b/sf_manufacturing/models/mrp_workcenter.py index 34185d4e..27fdb37c 100644 --- a/sf_manufacturing/models/mrp_workcenter.py +++ b/sf_manufacturing/models/mrp_workcenter.py @@ -231,13 +231,13 @@ class ResWorkcenter(models.Model): default_capacity = round( self.production_line_hour_capacity * date_planned_working_hours, 2) _logger.info('排程日期:%s,计划数量:%s,日产能:%s,日工时:%s' % ( - date_planned, sum_qty, default_capacity, date_planned_working_hours)) + date_planned, sum_qty, default_capacity, date_planned_working_hours)) if sum_qty >= default_capacity: return False return True # 处理排程是否超过小时产能 - def deal_available_single_machine_capacity(self, date_planned): + def deal_available_single_machine_capacity(self, date_planned, count): date_planned_start = date_planned.strftime('%Y-%m-%d %H:00:00') date_planned_end = date_planned + timedelta(hours=1) @@ -249,7 +249,11 @@ class ResWorkcenter(models.Model): if plan_ids: sum_qty = sum([p.product_qty for p in plan_ids]) - if sum_qty >= self.production_line_hour_capacity: + production_line_hour_capacity = self.production_line_hour_capacity + if sum_qty >= production_line_hour_capacity: + message = '当前计划开始时间不能预约排程,超过生产线小时产能(%d件)%d件' % ( + production_line_hour_capacity, count) + raise UserError(message) return False return True diff --git a/sf_plan/models/custom_plan.py b/sf_plan/models/custom_plan.py index fb8176fe..60587dec 100644 --- a/sf_plan/models/custom_plan.py +++ b/sf_plan/models/custom_plan.py @@ -75,7 +75,7 @@ class sf_production_plan(models.Model): if self.date_planned_start: self.date_planned_finished = self.date_planned_start + timedelta(hours=1) - #处理计划状态非待排程,计划结束时间为空的数据处理 + # 处理计划状态非待排程,计划结束时间为空的数据处理 def deal_no_date_planned_finished(self): plans = self.env['sf.production.plan'].search( [('date_planned_finished', '=', False), ('state', 'in', ['processing', 'done', 'finished'])]) @@ -90,6 +90,7 @@ class sf_production_plan(models.Model): for item in plans: if item.date_planned_start: item.order_deadline = item.date_planned_start + timedelta(days=7) + @api.model def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None): @@ -218,7 +219,7 @@ class sf_production_plan(models.Model): return num - def do_production_schedule(self): + def do_production_schedule(self, count=1): """ 排程方法 """ @@ -226,7 +227,7 @@ class sf_production_plan(models.Model): if not record.production_line_id: raise ValidationError("未选择生产线") else: - is_schedule = self.deal_processing_schedule(record.date_planned_start) + is_schedule = self.deal_processing_schedule(record.date_planned_start, count) if not is_schedule: raise ValidationError("排程失败") workorder_id_list = record.production_id.workorder_ids.ids @@ -281,7 +282,7 @@ class sf_production_plan(models.Model): } # 处理是否可排程 - def deal_processing_schedule(self, date_planned_start): + def deal_processing_schedule(self, date_planned_start, count): for record in self: workcenter_ids = record.production_line_id.mrp_workcenter_ids if not workcenter_ids: @@ -296,7 +297,7 @@ class sf_production_plan(models.Model): raise UserError('当前计划开始时间不能预约排程,请在工作时间内排程') if not production_lines.deal_available_default_capacity(date_planned_start): # 判断生产线是否可排程 raise UserError('当前计划开始时间不能预约排程,生产线今日没有可排程的资源') - if not production_lines.deal_available_single_machine_capacity(date_planned_start): # 判断生产线是否可排程 + if not production_lines.deal_available_single_machine_capacity(date_planned_start, count): # 判断生产线是否可排程 raise UserError('当前计划开始时间不能预约排程,生产线该时间段没有可排程的资源') return True diff --git a/sf_plan/wizard/action_plan_some.py b/sf_plan/wizard/action_plan_some.py index 52b9a249..23545516 100644 --- a/sf_plan/wizard/action_plan_some.py +++ b/sf_plan/wizard/action_plan_some.py @@ -33,7 +33,9 @@ class Action_Plan_All_Wizard(models.TransientModel): # 使用传递过来的计划ID temp_plan_ids = self.plan_ids # 在这里添加您的逻辑来处理这些ID + count = len(temp_plan_ids) + 1 for plan in temp_plan_ids: + count = count - 1 # 处理每个计划 # 比如更新计划状态、分配资源等 # 示例:plan.state = 'scheduled' @@ -42,7 +44,7 @@ class Action_Plan_All_Wizard(models.TransientModel): plan_obj = self.env['sf.production.plan'].browse(plan.id) plan_obj.production_line_id = self.production_line_id.id plan.date_planned_start = self.date_planned_start - plan_obj.do_production_schedule() + plan_obj.do_production_schedule(count) # plan_obj.state = 'done' print('处理计划:', plan.id, '完成')