Openerp 7 based on this requirement Sale order lines Remaining days Calculate Start Date minus Today at all times. Functional Field and on_change function used:-
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}
In order lines Remaining days Values not updated automatically. once save the main sale order record then only lines Remaining days value updated. How to shows the remaining days values in list view before saving the record.
Functional field will have value only after you save the record.
Using on_change functional field output values able to shows in form view. But in tree view on_change field output values not shown in function field?..
Based on the requirement "Remaining days Calculate Start Date minus Today at all times" is it possible to any other way to shows remaining days in lines before saving the record. Because our client to see the output before saving the record.