This question has been flagged
3948 Views

I have a custom model for Leave Module, and i'm using an inherintance setting the default dates in this form:

    def _default_zero(self):
        today = datetime.now()
        user_time_zone = pytz.timezone(self.env.user.partner_id.tz)
        hour_zero_for_user = user_time_zone.localize(datetime(today.year, today.month, today.day, 0, 0, 0))
        hour_zero_utc = hour_zero_for_user.astimezone(utc_time_zone)
        return datetime(year=hour_zero_utc.year, month=hour_zero_utc.month, day=hour_zero_utc.day, hour=hour_zero_utc.hour, minute=hour_zero_utc.minute, second=hour_zero_utc.second)

    def _default_final(self):
        today = datetime.now()
        user_time_zone = pytz.timezone(self.env.user.partner_id.tz)
        hour_final_for_user = user_time_zone.localize(datetime(today.year, today.month, today.day, 23, 59, 59))
        hour_final_utc = hour_final_for_user.astimezone(utc_time_zone)
        return datetime(year=hour_final_utc.year, month=hour_final_utc.month, day=hour_final_utc.day, hour=hour_final_utc.hour, minute=hour_final_utc.minute, second=hour_final_utc.second)

    date_from = fields.Datetime('Start Date', readonly=True, index=True, copy=False,
                                states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]},
                                default=_default_zero)
    date_to = fields.Datetime('End Date', readonly=True, copy=False,
                              states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]},
                                default=_default_final)

That works for forms view, (i.e. in "Leaves Summary" in create button) because show i.e 12/02/2019 00:00:00 to 12/02/2019 23:59:59 but when i try to use the calendar view in "Dashboard" or "Leaves Request" I click a day and the "modal view" show other hour 12/02/2019 07:00:00 to 12/02/2019 19:00:00.

I don't understand tthe problem because I think the inheritance should affect all views.

Avatar
Discard