From 73b7ff7d1b8c293ccf9729ddf1ac74186912d22d Mon Sep 17 00:00:00 2001 From: hujiaying Date: Sun, 29 Sep 2024 10:33:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A1=E5=88=92=E6=8E=92?= =?UTF-8?q?=E7=A8=8B=E9=80=89=E6=8B=A9=E6=97=A5=E6=9C=9F=E6=9C=89=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=87=8F=EF=BC=8C=E4=B8=8D=E8=83=BD=E6=8E=92=E7=A8=8B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workcenter.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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