112👍
✅
It seems like self.VAT
is of decimal.Decimal
type and self.amount
is a float
, a thing that you can’t do.
Try decimal.Decimal(self.amount) * self.VAT
instead.
21👍
Your issue is, as the error says, that you’re trying to multiply a Decimal
by a float
The simplest solution is to rewrite any reference to amount
declaring it as a Decimal object:
self.amount = decimal.Decimal(float(amount))
and in initialize
:
self.amount = decimal.Decimal('0.0')
Another option would be to declare Decimals in your final line:
return (decimal.Decimal(float(self.amount)) * self.VAT).quantize(decimal.Decimal(float(self.amount)), rounding=decimal.ROUND_UP)
…but that seems messier.
- [Django]-Warning: Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'
- [Django]-Django: How to manage development and production settings?
- [Django]-How to write django test meant to fail?
2👍
I was getting this error on this line of code:
row_value = float(row['hours']) * 0.2
and changed it to this:
row_value = float(row['hours']) * float(0.2)
which worked fine.
- [Django]-Error: "dictionary update sequence element #0 has length 1; 2 is required" on Django 1.4
- [Django]-Django – How to make a variable available to all templates?
- [Django]-Django: Group by date (day, month, year)
Source:stackexchange.com