Skip to Content
Menu
This question has been flagged
1868 Views

I add default fuction in my start_datetime and date_deadline fields and that is working fine in form view , but when I create from gantt view, default value is not display. start_datetime field hour is always displayed 00:00:00 and date_dateline field's hour is always displayed with 23:59:59. How can I fixed it.My screenshot is here https://ibb.co/z8DD7NM

def _default_start_date(self):
        tz = pytz.timezone(self.env.user.tz)
        dt = fields.Datetime.now()
        newdatetime = dt.replace(hour=9, minute=00,second=00)
        logging.info("final date++++++++++++++++")
        logging.info(newdatetime)
        aware_d = tz.localize(newdatetime,is_dst=None)
        utc_d =aware_d.astimezone(pytz.utc)
        # local_datetime = pytz.utc.localize(newdatetime).astimezone(destination_tz).replace(tzinfo=None)
        logging.info("Time zone_+++++++++++++++")
        logging.info(tz)
        logging.info(utc_d)
        final_time = utc_d.strftime('%Y-%m-%d %H:%M:%S')
        return final_time
    def _default_end_date(self):
        tz = pytz.timezone(self.env.user.tz)
        dt = fields.Datetime.now()
        newdatetime = dt.replace(hour=18, minute=00,second=00)
        logging.info("final date++++++++++++++++")
        logging.info(newdatetime)
        aware_d = tz.localize(newdatetime,is_dst=None)
        utc_d =aware_d.astimezone(pytz.utc)
        # local_datetime = pytz.utc.localize(newdatetime).astimezone(destination_tz).replace(tzinfo=None)
        logging.info("Time zone_+++++++++++++++")
        logging.info(tz)
        logging.info(utc_d)
        final_time = utc_d.strftime('%Y-%m-%d %H:%M:%S')
        return final_time
    start_date = fields.Datetime(string="Starting Date",default=_default_start_date)
    date_deadline = fields.Datetime(string='Deadline', index=True, copy=False, tracking=True,default=_default_end_date)



Avatar
Discard
Related Posts Replies Views Activity
1
May 22
4563
1
Aug 21
4700
0
Apr 24
180
3
May 18
6567
1
Feb 23
3725