#Define the end date field. The end date is determined by the start date plus the duration. To set the end date, you need to calculate the duration yourself.
end_date = fields.Date(string="End Date", store=True,
compute='_get_end_date', inverse='_set_end_date')
#Response function for the "get end date" event: calculate the end date
@api.depends('start_date', 'duration')
def _get_end_date(self):
for r in self:
if not (r.start_date and r.duration):
r.end_date = r.start_date
continue
start = fields.Datetime.from_string(r.start_date)
duration = timedelta(days=r.duration, seconds=-1)
r.end_date = start + duration
#Response function for the "set end date" event: calculate and set the duration
def _set_end_date(self):
for r in self:
if not (r.start_date and r.end_date):
continue
start_date = fields.Datetime.from_string(r.start_date)
end_date = fields.Datetime.from_string(r.end_date)
r.duration = (end_date - start_date).days + 1Odoo14中的逆計算inverse方法屬性值用法——由compute字段的值逆向修改其依賴值
Odoo14inverse方法屬性值用法
網誌: 開發實施
登入 發表評論
