From d123ca51737c8d64b6563980582ffe764ac1c19b Mon Sep 17 00:00:00 2001 From: hujiaying Date: Fri, 6 Sep 2024 09:13:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E6=9C=89=E6=95=88?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=97=B6=E9=95=BF=E8=AE=A1=E7=AE=97=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workcenter.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sf_manufacturing/models/mrp_workcenter.py b/sf_manufacturing/models/mrp_workcenter.py index 6af8fc85..7183b755 100644 --- a/sf_manufacturing/models/mrp_workcenter.py +++ b/sf_manufacturing/models/mrp_workcenter.py @@ -133,11 +133,11 @@ class ResWorkcenter(models.Model): available_machine_number = fields.Integer(string="可用机台数量") single_machine_capacity = fields.Float(string="单台小时产能") production_line_hour_capacity = fields.Float(string="生产线小时产能", readonly=True, - _compute='_compute_production_line_hour_capacity', store=True) + compute='_compute_production_line_hour_capacity') effective_working_hours_day = fields.Float(string="日有效工作时长", default=0, readonly=True, - _compute='_compute_effective_working_hours_day', store=True) + compute='_compute_effective_working_hours_day') default_capacity = fields.Float( - '生产线日产能', default=2.0, _compute='_compute_production_line_day_capacity', store=True, readonly=True) + '生产线日产能', compute='_compute_production_line_day_capacity', readonly=True) # 计算生产线日产能 @api.depends('production_line_hour_capacity', 'effective_working_hours_day') @@ -147,11 +147,12 @@ class ResWorkcenter(models.Model): record.production_line_hour_capacity * record.effective_working_hours_day, 2) # 计算日有效工作时长 - @api.depends('attendance_ids', 'attendance_ids.hour_to', 'attendance_ids.hour_from') + @api.depends('resource_calendar_id', 'resource_calendar_id.attendance_ids', + 'resource_calendar_id.attendance_ids.hour_to', 'resource_calendar_id.attendance_ids.hour_from') def _compute_effective_working_hours_day(self): for record in self: - attendance_ids = record.resource_calendar_id.attendance_ids.filter( - lambda r: r.dayofweek == datetime.now().weekday()) + attendance_ids = [p for p in record.resource_calendar_id.attendance_ids if + p.dayofweek == self.get_current_day_of_week()] if attendance_ids: for attendance_id in attendance_ids: if attendance_id.hour_from and attendance_id.hour_to: @@ -159,6 +160,11 @@ class ResWorkcenter(models.Model): else: record.effective_working_hours_day = 0 + def get_current_day_of_week(self): + + day_num = datetime.datetime.now().weekday() + return str(day_num) + # 计算生产线小时产能 @api.depends('single_machine_capacity', 'available_machine_number') def _compute_production_line_hour_capacity(self):