Odoo Help


datetime not working in xml [Closed]

Sudhir Arya (ERP Harbor Consulting Services)
on 2/5/13, 9:38 AM 9,138 views

The Question has been closed

Sudhir Arya (ERP Harbor Consulting Services)
on 10/28/2013 03:31:11

I am using OpenERP-7.0 and Ubuntu-10.04.

Following code is working fine in 6.0 & 6.1 but it's giving error in 7.0

Here is my code:

<record model="ir.actions.act_window" id="action_leave_not_accounted">
    <field name="name">Leaves to be Accounted</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">hr.holidays</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="domain">[('date_from','&gt;=',(datetime.date.today()-relativedelta(weeks=1)).strftime('%Y-%m-%d'))]</field>
    <field name="view_id" ref="hr_holidays.view_holiday_simple"/>

I am facing following error:

7.0/server/openerp/tools/safe_eval.py", line 241, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in <module> NameError: name 'datetime' is not defined

I tried DateTime also, but it's not working.

Can anyone please help me?

Thanks in advance.

In a XML file, you have to use html entities to express inequality symbols &lt; and &gt; in a domain: respectively &amp;lt; and &amp;gt;.

Antonin Bourguignon (abo)
on 2/5/13, 11:23 AM

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
On 2/7/13, 3:16 AM

I found solution and it worked for me:

<field name="domain">[('date_from', '&lt;', (context_today()-datetime.timedelta(weeks=1)).strftime('%Y-%m-%d'))]</field>

Hello Sudhir..I had used your code but its giving error like context_today is not defined..My code is <field name="domain">[('date', '=', context_today().strftime('%Y-%m-%d'))]</field>

on 11/28/13, 8:08 AM

Hello, I am getting same issue "NameError: name 'context_today' is not defined." I dont get it why even it might work well at your side. Can help me ?

Denero Team
on 1/18/14, 3:42 AM
On 2/7/13, 1:12 AM

You can try __import__('datetime') instead of datetime.date.today()


Antonin Bourguignon (abo)

--Antonin Bourguignon (abo)--

| 0 0 0
--Antonin Bourguignon (abo)--
Murder simulators enthusiast. http://gaming.stackexchange.com/users/15726/anto
Antonin Bourguignon (abo)
On 2/5/13, 11:04 AM

In a XML file, you have to use html entities to express inequality symbols < and > in a domain: respectively &lt; and &gt;.

Also a proper syntax for datetime can be found in a few places with a simple grep, for instance in stock/board_warehouse_view.xml:

<field name="domain">[('type','=','in'),('day','&lt;=', time.strftime('%Y-%m-%d')),('day','&gt;',(context_today()-datetime.timedelta(days=15)).strftime('%Y-%m-%d'))]</field>

Nicolas Bessi

--Nicolas Bessi--

| 5 7 8
Lausanne, Switzerland
--Nicolas Bessi--
Nicolas Bessi
On 2/5/13, 11:12 AM


It won't work, the domain is not aware of datetime.

In V7.0 you have to use the code directive of action: `<record id="ir_actions_server_timsheet_sheet" model="ir.actions.server">

        <field name="sequence" eval="5"/>
        <field name="state">code</field>
        <field name="type">ir.actions.server</field>
        <field name="model_id" ref="model_hr_timesheet_current_open"/>
        <field name="code">action = pool.get('hr.timesheet.current.open').open_timesheet(cr, uid, None, context)</field>
        <field name="condition">True</field>
        <field name="name">My Timesheet</field>


Thank you for you answer. But can you please explain how can I achieve my requirement?

Sudhir Arya (ERP Harbor Consulting Services)
on 2/6/13, 12:33 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 2/5/13, 9:38 AM
Seen: 9138 times
Last updated: 9/30/17, 6:21 AM