openerp - Extend year range in odoo -
by default, odoo (openerp 8.0) fields.date combobox show year selection in range of +/-10 years current year. how extend it?
just follow way try end
from openerp.osv import fields, osv openerp import tools dateutil.relativedelta import relativedelta import datetime class myclass_nextyear(osv.model): _name='myclass.nextyear' def str_to_datetime(strdate): return datetime.datetime.strptime(strdate, tools.default_server_date_format) def compute_next_year_date(self, strdate): oneyear = datetime.timedelta(days=365) curdate = str_to_datetime(strdate) return datetime.datetime.strftime(curdate + oneyear, tools.default_server_date_format) _columns = { 'start_date': fields.date('contract start date', help='date when coverage of contract begins'), 'expiration_date': fields.date('contract expiration date', help='date when coverage of contract expirates (by default, 1 year after begin date)'), } _defaults = { 'start_date': fields.date.context_today, 'expiration_date': lambda self, cr, uid, ctx: self.compute_next_year_date(fields.date.context_today(self, cr, uid, context=ctx)), }
above start date comes current date default , expiration date comes function field compute_next_year_date function
i hope should helpful ..! :)
Comments
Post a Comment