Home Ask Login Register

Developers Planet

Your answer is one click away!

AKHIL MATHEW February 2016

How to get current time in datetime format in XML file of odoo?

My code is as follows....

My Model is ...

class Today_Status(models.Model):
    _name = 'today.status'

    current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    starttime = fields.Many2one(comodel_name='book.meeting')

My XML file is as follows...

<record model="ir.actions.act_window" id="dashboard-menu">
    <field name="name">DashBoard</field>
    <field name="res_model">today.status</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="domain">[("start_time", ">=", "current_time")]</field>
    <field name="view_id" ref="dash-view"/>

I want to get current time in XML or i want to use the variable current_time specified in model in the XML file. How is it possible?


DaSaDiYa ChaiTAnYa February 2016

Just need to set the below domain and then check your module after upgrading your module.

[('date','>=', ((context_today()).strftime('%%Y-%%m-%%d'))+' '+'00:00:00'),('date','<=', ((context_today()).strftime('%%Y-%%m-%%d'))+' '+'23:59:59')]

Also add a new datetime field as date in your model.

I hope my answer may helpful for you :)

Post Status

Asked in February 2016
Viewed 3,633 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life