Throws error AttributeError: 'sale.order' object has no attribute 'dateofDischarge'
Defined base fields :
'dateofAdmission':fields.datetime('DoA', required=False),
'dateofDischarge':fields.datetime('DoD', required=False),
'dinh':fields.function(_days_in_hospital, method=True, type='char', size=32, string='DIH')
And the defined function
def _days_in_hospital(self, cr, uid,ids, vals, args, context=None):
self.DIH = ""
if (self.dateofDischarge and self.dateofAdmission):
self.DIH = (datetime.strptime(self.dateofDischarge, DEFAULT_SERVER_DATETIME_FORMAT)-datetime.strptime(self.dateofAdmission, DEFAULT_SERVER_DATETIME_FORMAT)).days
Hi Ramansh, Cant trace out what is the error in your code. which is the field DIH ? is it dinh ?
Anyway you just try with this code,
dateofAdmission = fields.Datetime('DoA')
dateofDischarge = fields.Datetime('DoD')
dinh = fields.Char(string='DIH', size=32, compute='days_in_hospital')
@api.multi
@api.depends('dateofAdmission', 'dateofDischarge')
def days_in_hospital(self):
if self.dateofDischarge and self.dateofAdmission:
self.dinh = (datetime.strptime(self.dateofDischarge, DEFAULT_SERVER_DATETIME_FORMAT)-datetime.strptime(self.dateofAdmission, DEFAULT_SERVER_DATETIME_FORMAT)).days
Is @api.depends('dateofAdmission', 'dateofDischarge') available in openERP 7?
If not is there a way to achieve it? As I cannot add on_change since mine is inherited view