I have a model with the name ‘exam_section.ta_da_bill’ which has the following property
@property
def recovery(self):
res = 0
ta_da_lines = self.exam.exam_type.ta_da
employee_grade_pay = float(self.employee.grade_pay.name)
for line in ta_da_lines:
if self.employee.employee_group == line.group:
for grade_pay in line.grade_pays:
if employee_grade_pay >= float(grade_pay.name):
hotel_entitlement = line.hotel_charges
food_entitlement = line.food_charges
days_hotel = self.hotel_food.no_of_nights_stayed
days_food = self.hotel_food.no_of_days_food
total_hotel = days_hotel * hotel_entitlement
total_food = days_food * food_entitlement
hotel_amount = self.total_hotel_amount
food_amount = self.total_food_amount
recovery_hotel = total_hotel - hotel_amount \
if total_hotel > hotel_amount else 0
recovery_food = total_food - food_amount \
if total_food > food_amount else 0
res = recovery_food + recovery_hotel
return res
I have a report which uses this property. But when I try to print the report, it gives out the following error
I have tried updating the database again and again. I even dropped the table and reupdated the database but to no avail. If I remove the @property decorator, the final report shows recovery as an object of type function. I have written another property in the same model which works perfectly
@property
def total_hotel_amount(self):
res = 0
if self.hotel_food:
for record in self.hotel_food:
if record.type_ in ['hotel']:
res += record.amount
return res
This comes up with no errors but the recovery property I wrote does not work at all. I am tired of updating my database again and again. Is there another way to make the recovery property work without me actually having to delete data and try again?
Help is much appreciated