Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default date in OpenERP

Tags:

openerp

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?

like image 590
Thinkwell Avatar asked Dec 09 '22 18:12

Thinkwell


1 Answers

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

like image 94
The.Clone.Master Avatar answered Mar 12 '23 20:03

The.Clone.Master