Skip to content

Commit 4072d40

Browse files
dcoder13BhargavzzabhiJeetP10dotniikoSomgester
authored
Deploy/gad 2 (FusionIIIT#1781)
* Added API folder in iwdModuleV2 * Added endpoints in API folder in iwdModuleV2 * Added additional endpoints in API folder in iwdModuleV2 * fix[api] : fetchdesignation, requestview * fix : view file endpoint * minor updates while updating the issue-work-order table (#4) * minor changes (#5) * minor changes * minor changes * approve/reject and view file * fix: work order * Minor changes in addBudget and editBudget endpoints (#6) * fix : serializer * modified views related to audit document view (#7) * Added API folder in iwdModuleV2 * modified views related to audit document view * fixed apis * fix: serializer overriding requestCreatedBdBy value * fix: serializer overriding requestCreatedBdBy value * fix api * chore: made handlers consistent * major fixes * fix: handle dean process request file attachment upload * fix : forward file * Basic proposal system implemented (#8) * Basic proposal system implemented * Added a separate Items model and updated ProposalSerializer * Updated BE * Removed migrations * Minor changes * Update models.py * Update models.py --------- Co-authored-by: Divyansh Bisht <[email protected]> * fix : migrations * chore : aded proposal endpoint * get_proposal * fixed create_proposal function * Updated handle_update_requests and create_proposal endpoints * Minor cleanup * Updated handle_update_requests and create_proposal endpoints (#11) * Updated handle_update_requests and create_proposal endpoints * Minor cleanup * fix: request_id fetch (#12) * Added get_items endpoint * fixed all proposal related apis * fix: migrations * fix: DB cleaning * fix: request status api * fix : migrations mismatch * fix: migrations issue * fix : request fetch error * fix : request error * Updated approval process (FusionIIIT#14) * active proposal and code optimization * fix: serializer issue * Updated request rejection and updation process (FusionIIIT#15) * major bug fixes --------- Co-authored-by: Bhargavzz <[email protected]> Co-authored-by: Abhijeet <[email protected]> Co-authored-by: dotniiko <[email protected]> Co-authored-by: Dhruv Ratmele <[email protected]> Co-authored-by: Abhijeet Patil <[email protected]> Co-authored-by: Bhargavzz <[email protected]> Co-authored-by: Himanshu <[email protected]> Co-authored-by: Somgester <[email protected]>
1 parent 23513c4 commit 4072d40

File tree

5 files changed

+276
-138
lines changed

5 files changed

+276
-138
lines changed

FusionIIIT/applications/iwdModuleV2/api/serializers.py

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from applications.iwdModuleV2.models import *
44
from applications.ps1.models import *
55
from decimal import Decimal
6+
import json
67
class WorkOrderFormSerializer(serializers.ModelSerializer):
78
class Meta:
89
model = WorkOrder
@@ -145,70 +146,31 @@ class Meta:
145146
# model = LetterOfIntentDetails
146147
# fields = '__all__'
147148

148-
class ItemSerializer(serializers.ModelSerializer):
149+
class ItemsSerializer(serializers.ModelSerializer):
149150
class Meta:
150151
model = Item
151-
fields = ['id', 'name', 'description', 'unit', 'price_per_unit', 'quantity', 'docs', 'total_price']
152+
fields = ['name', 'description', 'unit', 'price_per_unit', 'quantity', 'docs', 'total_price', 'id']
153+
154+
152155
class CreateProposalSerializer(serializers.ModelSerializer):
153-
items = ItemSerializer(many=True)
156+
items = ItemsSerializer(many=True, write_only=True) # Keep the many=True option
157+
154158
class Meta:
155159
model = Proposal
156160
fields = '__all__'
157161

158162
def create(self, validated_data):
159-
items_data = validated_data.pop('items', [])
160-
proposal = Proposal.objects.create(**validated_data)
163+
# Pop the 'items' from the validated data
164+
items_data = validated_data.pop('items', [])
161165

162-
total_budget = Decimal(0)
163-
items = []
164-
165-
for item_data in items_data:
166-
try:
167-
quantity = item_data['quantity']
168-
price_per_unit = item_data['price_per_unit']
169-
total_price = quantity * price_per_unit
170-
total_budget += total_price
171-
items.append(Item(proposal=proposal, total_price=total_price, **item_data))
172-
173-
except (ValueError, TypeError) as e:
174-
print(f"Error processing item: {item_data}, Error: {e}")
175-
continue
176-
177-
if items:
178-
Item.objects.bulk_create(items)
166+
# Create the proposal instance with the validated data
167+
proposal = Proposal.objects.create(**validated_data)
179168

180-
proposal.proposal_budget = total_budget
181169
proposal.save()
182170

183171
return proposal
184172

185173
class ProposalSerializer(serializers.ModelSerializer):
186-
187174
class Meta:
188175
model = Proposal
189-
fields = '__all__'
190-
191-
def create(self, validated_data):
192-
items = ItemSerializer(many=True)
193-
items_data = validated_data.pop('items', [])
194-
proposal = Proposal.objects.create(**validated_data)
195-
196-
total_budget = Decimal(0)
197-
items = []
198-
199-
for item_data in items_data:
200-
try:
201-
quantity = item_data['quantity']
202-
price_per_unit = item_data['price_per_unit']
203-
total_price = quantity * price_per_unit
204-
total_budget += total_price
205-
items.append(Item(proposal=proposal, total_price=total_price, **item_data))
206-
except (ValueError, TypeError) as e:
207-
print(f"Error processing item: {item_data}, Error: {e}")
208-
if items:
209-
Item.objects.bulk_create(items)
210-
211-
proposal.proposal_budget = total_budget
212-
proposal.save()
213-
214-
return proposal
176+
fields = '__all__'

0 commit comments

Comments
 (0)