Fakultas Ilmu Komputer UI

Commit 87f9fe34 authored by Ilma Ainur Rohma's avatar Ilma Ainur Rohma
Browse files

Merge branch 'ilmarohma/16/donasi-barang-program' into 'dev'

PBI-11: Menambahkan data donasi barang pada program

Closes #16

See merge request !14
parents 82f5cf36 e6246013
Pipeline #81811 passed with stages
in 2 minutes and 24 seconds
......@@ -440,6 +440,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 = [
......@@ -456,6 +457,7 @@ class ProgramSerializer(serializers.ModelSerializer):
'poster_image',
'link',
'total_donation_amount',
'goods_donation',
]
model = models.Program
read_only_fields = ['id', 'code']
......@@ -468,6 +470,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