AKHIL MATHEW AKHIL MATHEW - 10 months ago 120
Python Question

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?

Answer Source

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','&lt;=', ((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 :)