diff --git a/sf_manufacturing/models/mrp_workcenter.py b/sf_manufacturing/models/mrp_workcenter.py index 017f89b8..81a252fb 100644 --- a/sf_manufacturing/models/mrp_workcenter.py +++ b/sf_manufacturing/models/mrp_workcenter.py @@ -163,6 +163,19 @@ class ResWorkcenter(models.Model): else: record.effective_working_hours_day = 0 + # 计算传入时间日有效工作时长 + def _compute_effective_working_hours_day1(self, date): + effective_working_hours_day = 0 + for record in self: + attendance_ids = [p for p in record.resource_calendar_id.attendance_ids if + p.dayofweek == self.get_current_day_of_week(date)] + if attendance_ids: + for attendance_id in attendance_ids: + if attendance_id.hour_from and attendance_id.hour_to: + effective_working_hours_day += attendance_id.hour_to - attendance_id.hour_from + + return effective_working_hours_day + # 获取传入时间是星期几 def get_current_day_of_week(self, datetime): day_num = datetime.weekday() @@ -211,7 +224,8 @@ class ResWorkcenter(models.Model): ('state', 'not in', ['draft', 'cancel'])]) if plan_ids: sum_qty = sum([p.product_qty for p in plan_ids]) - if sum_qty >= self.default_capacity: + date_planned_working_hours = self._compute_effective_working_hours_day1(date_planned) + if sum_qty >= date_planned_working_hours: return False return True