Openerp 7 基于此要求 销售订单行 剩余天数 始终计算开始日期减去今天。使用的功能字段和 on_change 函数:-
def _remaining_days(self, cr, uid, ids, field_name, arg, context=None):
res = {}
if not ids:
return {}
for val in self.browse(cr, uid, ids, context=context):
result = datetime.datetime.strptime(val.start_date, '%Y-%m-%d') - datetime.datetime.strptime(current_date, '%Y-%m-%d')
res[val.id] = result.days
return res
'remaining_days': fields.function(_remaining_days, method=True, string='Remaining days', type='integer'),
def onchange_holddays(self, cr, uid, ids, start_date, context=None):
result = {}
context = context or {}
if release_date:
current_date = time.strftime('%Y-%m-%d')
remaining = datetime.datetime.strptime(release_date, '%Y-%m-%d') - datetime.datetime.strptime(current_date, '%Y-%m-%d')
result['remaining_days'] = remaining.days
return {'value': result}
按订单行 剩余天数 值不会自动更新。保存主要销售订单记录后,仅更新剩余天数行。如何在保存记录之前在列表视图中显示剩余天数。诺