上海-就这样(1683223795) 13:53:39hr.holidays.py 中. def onchange_date_from(self, cr, uid, ids, date_to, date_from): result = {} if date_to and date_from: diff_day = self._get_number_of_days(date_from, date_to) result['value'] = { 'number_of_days_temp': round(diff_day)+1 } return result result['value'] = { 'number_of_days_temp': 0, } return result其中 if date_to and date_from:这句话是什么用意..因我在使用时...不加这行..都有 exception 说 date_to 及 date_from 是 bool 的 datatype. strptime 只能接受 string .但 date_to 及 date_from 是从 字段中预设值就有的.(日期格式)..带入这 onchange_date_from 中.所以有点搞不太懂这用意...但没有这判断式一定会错..附上 def _get_number_of_days(self, date_from, date_to): """Returns a float equals to the timedelta between two dates given as string.""" DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT) to_dt = datetime.datetime.strptime(date_to, DATETIME_FORMAT) timedelta = to_dt - from_dt diff_day = timedelta.days + float(timedelta.seconds) / 86400 return diff_day重庆-mrshelly(49812643) 13:54:47那句是判断你倒底有没有选择日期.如果 起止日期都有选择时, 才执行 if 里面的内容.上海-Jeff(85822082) 13:57:02python中所有数据类型的空值都可以视为逻辑假非空值作为逻辑真openerp里这种判断方式很多很多