Fakultas Ilmu Komputer UI

Commit e6246013 authored by Ilma Ainur Rohma's avatar Ilma Ainur Rohma
Browse files

[REFACTOR] menambahkan list donasi barang pada program

parent 0289117c
Pipeline #77148 passed with stages
in 2 minutes and 23 seconds
......@@ -425,6 +425,7 @@ class TransactionSerializer(serializers.ModelSerializer):
class ProgramSerializer(serializers.ModelSerializer):
total_donation_amount = serializers.SerializerMethodField('get_total_donation_amount')
goods_donation = serializers.SerializerMethodField('get_list_goods_donation')
class Meta:
fields = [
......@@ -441,6 +442,7 @@ class ProgramSerializer(serializers.ModelSerializer):
'poster_image',
'link',
'total_donation_amount',
'goods_donation',
]
model = models.Program
read_only_fields = ['id', 'code']
......@@ -453,6 +455,16 @@ class ProgramSerializer(serializers.ModelSerializer):
)
)
return str(total_donation_amount)
def get_list_goods_donation(self, obj):
lst = obj.program_donations.filter(
donation_status='002',
donation_type='GDS'
)
lst_ret = []
for goods_donation in lst:
dct = {'id' : goods_donation.id, 'desc' : goods_donation.goods_description, 'quantity' : goods_donation.goods_quantity}
lst_ret.append(dct)
return lst_ret
def validate(self, attrs):
instance = self.instance
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment