I'm working at creating a module for OpenERP 7 to set Today's Date as default value when creating a new Partner. I've installed the module, restarted the Openerp service and defaults aren't changed a bit. (I'd included a "goofball" field and bogus default data for the website field to make sure it's not a python lambda code problem. It wasn't...) Here's my code in partner.py:
from osv import osv, fields
import datetime
class res_partner(osv.osv):
_inherit = 'res.partner'
_columns = {"goofball":fields.char('goofball', size=15)}
_defaults = {
'website': 'www.veppsight.com',
'date': lambda *a: datetime.date.today().strftime('%Y-%m-%d'),
}
The default data isn't entered for the website & date fields and the "goofball" field isn't create in the database which I verified in psql. What am I doing wrong?
Since V6.1 there is a new function to deal with today's date, called context_today.
You can check background on this at the following link... http://openerp-expert-framework.71550.n3.nabble.com/Bug-925361-Re-6-1-date-values-that-are-initialized-as-defaults-may-appear-as-quot-off-by-one-day-quoe-td3741270.html
Based on that, you can just use...
_ defaults = {
'date1': fields.date.context_today,
}
Regards, -Mario
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With