0
I implemented a validation with two methods
def clean(self, *args, **kwargs):
#valortotal = Venda.objects.filter(id=self.id).aggregate(valortotal=Sum(F('item__produto__valor') * F('item_qtde'), output_field=FloatField()))
#valor_nota = self.valor_nota
#if Decimal(valortotal['valortotal']) < valor_nota():
if self.valortotal < self.valor_nota:
raise forms.ValidationError("O valor do Tipo de Pagamento (dinheiro + cartão) não pode ser maior que o valor total da nota.")
#raise forms.ValidationError(Decimal(valortotal['valortotal']))
and Django returned the following error
Below the methods that return values
def valortotal(self):
soma = Venda.objects.filter(id=self.id).aggregate(valortotal=Sum(F('item__produto__valor') * F('item__qtde'), output_field=FloatField()))
return soma['valortotal']
def valor_nota(self, force_insert=False, force_update=False):
valor_nota = self.valor_dinheiro + self.valor_cartao
return valor_nota
The Item Class
class Item(models.Model):
produto = models.ForeignKey(Produto, on_delete=models.CASCADE, default=None)
qtde = models.PositiveIntegerField(null=True, blank=False)
venda = models.ForeignKey(Venda, on_delete=models.CASCADE, default=None)

when doing: if self.total value() < self.value_note(): it returned this error '<' not supported between instances of 'Nonetype' and 'decimal. Decimal'
– jallisson jallis oliveira band
I edited the question by adding the total value() and note value method
– jallisson jallis oliveira band
This is the last error msg you report is the same as your other question, one of the two values of the comparison is
None, comment the if and the commandprint( self.valortotal() is None , self.valor_nota() is None)And you’ll see that aTrueon the way out.– Sidon