--------------
修订时间12:21 2017-05-16 星期二--------------* 在model中 from datetime import datetime, timedelta import time from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT 上面要引入的包 DEFAULT_SERVER_DATE_FORMAT = "%Y-%m-%d" DEFAULT_SERVER_TIME_FORMAT = "%H:%M:%S" DEFAULT_SERVER_DATETIME_FORMAT = "%s %s" % ( DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_TIME_FORMAT) -------- #没有设定日期,就引入系统当天的日期 if not date_order: date_order = time.strftime(DEFAULT_SERVER_DATE_FORMAT) #设定当前日期(字段) ---定义字段时默认值 V7 from openerp.osv import fields _columns = { 'date_order': fields.datetime('Date'), } _defaults = { 'date_order': fields.datetime.now, }V8
from openerp import fields date_order = fields.Datetime('Date',default=lambda self: fields.Datetime.now()) 一定不能直接写 default=fields.Datetime.now() ,否则时间会停留,不是当前时间了 ---函数操作时 V7 from datetime import datetime, timedeltaif not date_order:
date_order = time.strftime(DEFAULT_SERVER_DATE_FORMAT) V8 if not date_order: date_order = fields.Date.today() 当天对应字段类型Date or date_order = fields.Datetime.now() 当前时间对应字段类型Datetime 若要带当前客户时区 date_order = fields.Date.context_today(self) or date_order = fields.Datetime.context_timestamp(self) 更详细参看/openerp/fields.py 和/openerp/osv/fields.py * 在视图中