mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 21:45:41 +00:00
refactor: Update project settings, URL configurations, client views, and remove requirements.txt.
This commit is contained in:
23
gestaoRaul/clients/serializers.py
Normal file
23
gestaoRaul/clients/serializers.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Client
|
||||
from comandas.models import Comanda, ProductComanda
|
||||
from payments.models import Payments, somar
|
||||
from decimal import Decimal
|
||||
|
||||
class ClientSerializer(serializers.ModelSerializer):
|
||||
debt = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Client
|
||||
fields = ['id', 'name', 'created_at', 'active', 'contact', 'debt']
|
||||
|
||||
def get_debt(self, obj):
|
||||
comandas = Comanda.objects.filter(client=obj, status='FIADO')
|
||||
total_debt = Decimal(0)
|
||||
|
||||
for comanda in comandas:
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda)
|
||||
valores = somar(consumo, comanda)
|
||||
total_debt += valores['totalSemTaxa']
|
||||
|
||||
return total_debt
|
||||
Reference in New Issue
Block a user