I am new to OpenERP and Python and I am trying to set a default date in a create form which has to be 28 days after when the user is using the create form.
The last thing I've tried is this :
from datetime import datetime
from datetime import date
from datetime import timedelta
from dateutil.relativedelta import relativedelta
from openerp.osv import fields, osv
class sale_order_dates(osv.osv):
_inherit = 'sale.order'
_columns = {
'requested_date': fields.date('Requested Date', help="Date requested by the customer for the sale."),
}
_defaults = {
'requested_date': date.today() + timedelta(days=28),
}
sale_order_dates()
But then if I open the create form I get this error :
"The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application."
It is probably because I can't make operations in _defaults but then I don't know what to do, I've tried to make the operation in a function but I am not very comfortable with functions yet. Do you have any ideas of how I could do it please ? Thanks in advance
Edit : This is the error message on the computer terminal
2015-04-30 19:50:40,217 8666 ERROR Armand werkzeug: Error on request:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 180, in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 168, in execute
application_iter = app(environ, start_response)
File "/home/odoo/server/7.0/openerp/service/wsgi_server.py", line 417, in application
return application_unproxied(environ, start_response)
File "/home/odoo/server/7.0/openerp/service/wsgi_server.py", line 403, in application_unproxied
result = handler(environ, start_response)
File "/home/odoo/web/7.0/addons/web/http.py", line 528, in __call__
return self.dispatch(environ, start_response)
File "/home/odoo/web/7.0/addons/web/http.py", line 487, in __call__
return self.app(environ, start_wrapped)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 591, in __call__
return self.app(environ, start_response)
File "/home/odoo/web/7.0/addons/web/http.py", line 487, in __call__
return self.app(environ, start_wrapped)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 591, in __call__
return self.app(environ, start_response)
File "/home/odoo/web/7.0/addons/web/http.py", line 553, in dispatch
result = handler(request)
File "/home/odoo/web/7.0/addons/web/http.py", line 618, in <lambda>
return lambda request: JsonRequest(request).dispatch(method)
File "/home/odoo/web/7.0/addons/web/http.py", line 251, in dispatch
body = simplejson.dumps(response)
File "/usr/local/lib/python2.7/dist-packages/simplejson/__init__.py", line 370, in dumps
return _default_encoder.encode(obj)
File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 271, in encode
chunks = list(chunks)
File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 632, in _iterencode
for chunk in _iterencode_dict(o, _current_indent_level):
File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 591, in _iterencode_dict
for chunk in chunks:
File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 591, in _iterencode_dict
for chunk in chunks:
File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 642, in _iterencode
o = _default(o)
File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 246, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: datetime.date(2015, 5, 28) is not JSON serializable
So it looks like it is the operation in _defaults that is incorrect, maybe the two fields aren't compatible with each other too, but I don't know what I should use.