Odoo Help

Welcome!

This community 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.

7

datetime not working in xml [Closed]

By
Sudhir Arya (SA)
on 2/5/13, 9:38 AM 6,668 views

The Question has been closed

by
Sudhir Arya (SA)
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"/>
</record>

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
8

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
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>

Krishna
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 ?

Dhaval Patel
on 1/18/14, 3:42 AM
2
Sasuke
On 2/7/13, 1:12 AM

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

0

Antonin Bourguignon (abo)

--Antonin Bourguignon (abo)--
912
| 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>
0

Nicolas Bessi

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

Hello,

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>
    </record>

`

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

Sudhir Arya (SA)
on 2/6/13, 12:33 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 2/5/13, 9:38 AM
Seen: 6668 times
Last updated: 7/22/16, 9:39 AM