Reputation: 4306
i am substracting one date from another and from the result again substracting the 8 hours. After that i am converting the result in to decimal. But at the time of saving the object i am getting error
Cannot convert datetime.timedelta(0, 21600) to Decimal
Code:
fm.extra_hours = (fm.trip_closing_date - fm.trip_starting_date) - timedelta(hours=8)
#fm.extra_hours = time - timedelta(hours=8)
st = fm.extra_hours
print type(st)
print st.days
seconds = st.total_seconds()
hours = int(seconds // 3600)
print hours
print type(hours)
ext_hrs = float (hours)
print ext_hrs
print type(ext_hrs)
if st.days < 0:
st = 0
else:
y="xyz"
if Ek>=1:
fm.extra_kilometers = Ek
fm.extra_charge = ((((fm.vehical_type.per_extra_km_charge))*((fm.extra_kilometers)))+(((fm.vehical_type.per_extra_hour_charge))*(Decimal(ext_hrs))))
fm.pure_amount = ((((fm.total_kilometer))*((fm.vehical_type.per_extra_km_charge)))+(((fm.vehical_type.per_extra_hour_charge))*(Decimal(ext_hrs))))
fm.service_tax = (((fm.pure_amount)+(fm.driver_allownce_charge))*Decimal(4.944))/Decimal(100)
fm.grand_total = ((fm.pure_amount)+(fm.driver_allownce_charge)+(fm.service_tax))
fm.amount_payeble_now = (fm.grand_total)-(fm.less_adavance)
fm.save()
i dont know what wrong i am doing? please help me for this.
full trace
TypeError at /home/save_local_invoice/
Cannot convert datetime.timedelta(0, 21600) to Decimal
Request Method: POST
Request URL: http://localhost:8000/home/save_local_invoice/
Django Version: 1.7
Exception Type: TypeError
Exception Value:
Cannot convert datetime.timedelta(0, 21600) to Decimal
Exception Location: C:\Python27\lib\decimal.py in __new__, line 658
Python Executable: C:\Python27\python.exe
Python Version: 2.7.8
Python Path:
['C:\\Users\\MAGOWA\\Desktop\\magowa',
'C:\\Users\\MAGOWA\\Desktop\\magowa',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages']
Server time: Sat, 25 Apr 2015 10:26:33 +0530
error on this line fm.save()
Upvotes: 0
Views: 1225
Reputation: 5443
It seems you're trying to save a timedelta object as a Decimal. This is not possible without stating how the Decimal should interpret the object. I guess you will want to do something like fm.my_decimal_field = my_time_delta_object.total_seconds()
.
Upvotes: 1