been searching and i cant find a proper solutions I have issue calculating Vat amount from 2 values in Django models.
first the VAT model is like this
class Vat(models.Model):
vat_name = models.CharField(max_length=200)
vat_value = models.IntegerField()
def __str__(self):
return str(self.vat_value)
then I have the Statement model as below
class Statement(models.Model):
sales_invoice = models.IntegerField(blank=True, null=True)
vat_value = models.ForeignKey(Vat, on_delete=models.CASCADE, blank=True, null=True)
amount_in = models.DecimalField(max_digits=7, decimal_places=2, blank=True, null=True)
def vat_amt_in(self):
if self.amount_in and self.vat_value :
vat_amt_in = (self.vat_value/100)*self.amount_in
else:
return None
so after this I get the Error
unsupported operand type(s) for /: 'Vat' and 'int'
anyone can help with this for me to get the correct vat amount
like if vat_value = 21 and amount_in =50 then vat_amt_in =10,50
CodePudding user response:
Your error comes from self.vat_value/100
, where the first argument is type Vat, not something divisible by an integer. You probably wanted self.vat_value.vat_value/100
(if IntegerField() is divisible by an integer).