Setting a default date in OpenERP

I am working on creating an OpenERP 7 module to set Today Date as the default value when creating a new Partner. I installed the module, restarted the Openerp service, and the default values ​​are not changed a bit. (I would include the “goofball” field and dummy default data for the site field to make sure this is not a python lambda code problem. It wasn’t ...) Here is 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'), } 

By default, no data is entered for the site and date fields, and the "goofball" field is not created in the database, which I checked in psql. What am I doing wrong?

+4
source share
5 answers

Since V6.1 there is a new function to handle today's date called context_today.

You can check the 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 this, you can just use ...

 _ defaults = { 'date1': fields.date.context_today, } 

Regards, -Mario

+10
source

Import time and In default settings

 _defaults = { 'website': 'www.veppsight.com', 'date': lambda *a: time.strftime('%Y-%m-%d'), } 
+2
source

Use the following code:

 from osv import osv, fields import time class res_partner(osv.osv): _inherit = 'res.partner' _columns = {"goofball":fields.char('goofball', size=15)} _defaults = { 'website': 'www.veppsight.com', 'date1': time.strftime('%Y-%m-%d'), } 

AND I AM THE POSSIBLE SPINE NAME DATE SOMETHING SOMETHING. AS DATE - DT in POSTGRESQL

thanks

+1
source
 _defaults = { 'date': lambda self,cr,uid,context={}: context.get('date', fields.date.context_today(self,cr,uid,context=context)), 

or

 'date': lambda self, cr, uid, context={}: context.get('date', time.strftime("%Y-%m-%d %H:%M:%S")), 

or

 'date' : fields.date.context_today, } 

Lambda is a string or anonymous function in python.

+1
source

How about this:

  from osv import osv, fields
 import time

 class res_partner (osv.osv):
     _inherit = 'res.partner'

     _columns = {"goofball": fields.char ('goofball', size = 15)}

     _defaults = {
         'website': 'www.veppsight.com',
         'date1': lambda * a: time.strftime ('% Y-% m-% d'),
     }


 res_partner ()
0
source

All Articles