休假持续时间Odoo 11的get_work_days_count方法

时间:2019-03-11 09:38:12

标签: python-3.x odoo duration odoo-11

我正在为Odoo11进行请假管理。而且我被困在隔离的休假期限可用的某一点(4个部分),但我对价值的要求应显示为半天假或全天假。例如。持续时间在(4,4.25,4.5,4.75,5)中可用,而我需要(4,4.5,5)。那么,有人可以帮助我解决这个问题吗?我发现这个问题与下面的odoo python代码有关。

def _get_number_of_days(self, date_from, date_to, employee_id):
    """ Returns a float equals to the timedelta between two dates given as string."""
    from_dt = fields.Datetime.from_string(date_from)
    to_dt = fields.Datetime.from_string(date_to)
    if employee_id:
        employee = self.env['hr.employee'].browse(employee_id)
        return employee.get_work_days_count(from_dt, to_dt)
    time_delta = to_dt - from_dt
    return math.ceil(time_delta.days + float(time_delta.seconds) / 86400)

@api.onchange('date_from')
def _onchange_date_from(self):
    """ If there are no date set for date_to, automatically set one 8 hours later than
        the date_from. Also update the number_of_days.
    """
    date_from = self.date_from
    date_to = self.date_to
    # No date_to set so far: automatically compute one 8 hours later
    if date_from and not date_to:
        date_to_with_delta = fields.Datetime.from_string(date_from) + timedelta(hours=HOURS_PER_DAY)
        self.date_to = str(date_to_with_delta)
    # Compute and update the number of days
    if (date_to and date_from) and (date_from <= date_to):
        self.number_of_days_temp = self._get_number_of_days(date_from, date_to, self.employee_id.id)
    else:
        self.number_of_days_temp = 0

@api.onchange('date_to')
def _onchange_date_to(self):
    """ Update the number_of_days. """
    date_from = self.date_from
    date_to = self.date_to
    # Compute and update the number of days
    if (date_to and date_from) and (date_from <= date_to):
        self.number_of_days_temp = self._get_number_of_days(date_from, date_to, self.employee_id.id)
    else:
        self.number_of_days_temp = 0

还附有要求屏幕截图 PFA enter image description here

enter image description here

谢谢。

0 个答案:

没有答案