第一步:引用时间处理方法包:
from datetime import datetime from dateutil.relativedelta import relativedelta
第二步:增加“工龄”字段:
workAge = fields.Integer(u'工龄', compute='set_work_age')
第三步:创建方法:
# 计算工龄 def set_work_age(self): for rec in self: if rec.workDate: time = relativedelta(dt1=datetime.today(), dt2=rec.workDate).years rec.workAge = time + 1
注:rec.workDate 为"参加工作时间"字段