how to compare two dates in openerp

Asked by maroua

i need to compare two dates in openerp i have an erreur in this code please help me to solve this problem

code:
 _columns = {
'date_service':fields.date('Date de mise en service', required=True, readonly=True, states={'draft':[('readonly',False)]}),
'date_cession':fields.date('Date de Cession', required=True, readonly=True, states={'draft':[('readonly',False)]}),
'is_delayed': fields.function(_is_delayed, method = True, type = 'boolean'),

  }

 def _is_delayed (self, cr, uid, ids,date_service,date_cession,arg,context=None):
        res = {}
        for m in self.browse (cr, uid,ids,context):
            if m.date_cession < m.date_service:
                res[m.id] = True
            else:
                res[m.id] = False
        return res

and in xml
<field name="date_cession" string="Date de Cession" domain filter ="[('is_delayed','=',True)]" />

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) said :
#1

It would be helpful if you could tell people the exact error you are experiencing, and information such as the openerp version you are using.

At least, you code is lacking a search function for the is_delayed field. Maybe a store=True parameter on the column definition would be enough.

Revision history for this message
maroua (belknenimaroua) said :
#2

hello
i work with openerp 7 and windows
I tried to put store=true:
'is_delayed': fields.function(_is_delayed, method = True, type = 'boolean', store=True),
 but I have the same error
erreur :
XmlHttpRequestError Not Found
No handler found.

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) said :
#3

please post the full stack trace (it should be available in the server logs)

Revision history for this message
maroua (belknenimaroua) said :
#4

2013-03-20 15:05:47,407 5184 INFO ? openerp: OpenERP version 7.0-20130303-002143
2013-03-20 15:05:47,407 5184 INFO ? openerp: addons paths: C:\Program Files (x86)\OpenERP 7.0-20130303-002143\Server\server\openerp\addons
2013-03-20 15:05:47,407 5184 INFO ? openerp: database hostname: localhost
2013-03-20 15:05:47,407 5184 INFO ? openerp: database port: 5432
2013-03-20 15:05:47,407 5184 INFO ? openerp: database user: openpg
2013-03-20 15:05:48,286 5184 CRITICAL ? openerp.modules.module: Couldn't load module web
2013-03-20 15:05:48,286 5184 CRITICAL ? openerp.modules.module: unexpected indent (l10n_tn_immo.py, line 33)
2013-03-20 15:05:48,286 5184 ERROR ? openerp.service: Failed to load server-wide module `web`.
The `web` module is provided by the addons found in the `openerp-web` project.
Maybe you forgot to add those addons in your addons_path configuration.
Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 7.0-20130303-002143\Server\server\.\openerp\service\__init__.py", line 59, in load_server_wide_modules
  File "C:\Program Files (x86)\OpenERP 7.0-20130303-002143\Server\server\.\openerp\modules\module.py", line 415, in load_openerp_module
  File "C:\Program Files (x86)\OpenERP 7.0-20130303-002143\Server\server\openerp\addons\web\http.py", line 601, in wsgi_postload
  File "C:\Program Files (x86)\OpenERP 7.0-20130303-002143\Server\server\openerp\addons\web\http.py", line 491, in __init__
  File "C:\Program Files (x86)\OpenERP 7.0-20130303-002143\Server\server\openerp\addons\web\http.py", line 554, in load_addons
  File "C:\Program Files (x86)\OpenERP 7.0-20130303-002143\Server\server\.\openerp\modules\module.py", line 133, in load_module
  File "C:\Program Files (x86)\OpenERP 7.0-20130303-002143\Server\server\openerp\addons\l10n_tn_immo\__init__.py", line 2, in <module>
  File "C:\Program Files (x86)\OpenERP 7.0-20130303-002143\Server\server\openerp\addons\l10n_tn_immo\l10n_tn_immo.py", line 33
     def _is_delayed (self, cr, uid, ids,date_service,date_cession,arg,context=None):
    ^
 IndentationError: unexpected indent
2013-03-20 15:05:48,299 5184 INFO ? openerp: OpenERP server is running, waiting for connections...
2013-03-20 15:05:48,332 5184 INFO ? openerp.service.wsgi_server: HTTP service (werkzeug) running on 0.0.0.0:8069
2013-03-20 15:05:52,647 5184 INFO ? werkzeug: 127.0.0.1 - - [20/Mar/2013 15:05:52] "POST /web/action/load HTTP/1.1" 404 -
2013-03-20 15:05:55,664 5184 INFO ? werkzeug: 127.0.0.1 - - [20/Mar/2013 15:05:55] "POST /web/action/load HTTP/1.1" 404 -

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) said :
#5

as you can see there is a syntax error in l10n_tn_immo\l10n_tn_immo.py line 33 preventing normal startup of your instance and especially the web client. Fix the error and things should improve.

Can you help with this problem?

Provide an answer of your own, or ask maroua for more information if necessary.

To post a message you must log in.