修改日有效工作时长计算规则
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user