0
In my Model have this method below:
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():
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']))
More while saving the system appears error:
Does anyone know any solution to this.
The message says you cannot convert a
None
to a decimal value, probably in your ifif Decimal(valortotal['valortotal']) < valor_nota():
thevalortotal['valortotal']
is returningNone
.– Sidon
But strange that I have a similar method that is right in the template: def total value(self): sum = Sale.objects.filter(id=self.id). Aggregate(total value=Sum(F('item__product__value') * F('item__qtde'), output_field=Floatfield()) Return sum['total value']
– jallisson jallis oliveira band
Because in this method there is no invalid return, put a line before the if so:
valor_total = valortotal['valortotal'] if valortotal['valortotal'] is not None else 0
and change your if to:if Decimal(valor_total) < valor_nota():
and see what happens.– Sidon