update hatching
This commit is contained in:
26
app/views.py
26
app/views.py
@@ -806,7 +806,7 @@ class HatchingsViewSet(viewsets.ModelViewSet):
|
|||||||
'MenuUserAccess', 'LogTableName', 'LogTableAlias', 'PageTitle',
|
'MenuUserAccess', 'LogTableName', 'LogTableAlias', 'PageTitle',
|
||||||
'PartIdCode', 'UnitTypeName'
|
'PartIdCode', 'UnitTypeName'
|
||||||
]
|
]
|
||||||
good_sum = request.data.get('GoodSum', [])
|
good_sum = request.data.get('GoodSum', {})
|
||||||
if int(good_sum.get('loadingSum',0)) > 0:
|
if int(good_sum.get('loadingSum',0)) > 0:
|
||||||
for key in same_keys:
|
for key in same_keys:
|
||||||
if key in request.data and request.data[key] is not None:
|
if key in request.data and request.data[key] is not None:
|
||||||
@@ -875,8 +875,17 @@ class HatchingsViewSet(viewsets.ModelViewSet):
|
|||||||
setattr(hatching, key, value)
|
setattr(hatching, key, value)
|
||||||
if hatching.poultry is None:
|
if hatching.poultry is None:
|
||||||
hatching.poultry=poultry
|
hatching.poultry=poultry
|
||||||
hatching.GoodSum = good_sums['goodSum']
|
good_sums = request.data.get('GoodSum', {})
|
||||||
hatching.loadingSum = good_sums['loadingSum']
|
if isinstance(good_sums, dict):
|
||||||
|
hatching.GoodSum = good_sums.get('goodSum', 0)
|
||||||
|
hatching.loadingSum = good_sums.get('loadingSum', 0)
|
||||||
|
elif isinstance(good_sums, list) and len(good_sums) > 0:
|
||||||
|
item = good_sums[0]
|
||||||
|
if isinstance(item, dict):
|
||||||
|
hatching.GoodSum = item.get('goodSum', 0)
|
||||||
|
hatching.loadingSum = item.get('loadingSum', 0)
|
||||||
|
|
||||||
|
hatching.save()
|
||||||
hatching.save()
|
hatching.save()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -886,8 +895,15 @@ class HatchingsViewSet(viewsets.ModelViewSet):
|
|||||||
request.data['Period'] = period
|
request.data['Period'] = period
|
||||||
hatching = Hatching.objects.create(**request.data)
|
hatching = Hatching.objects.create(**request.data)
|
||||||
hatching.ArchiveDate = hatching.Date + datetime.timedelta(days=76)
|
hatching.ArchiveDate = hatching.Date + datetime.timedelta(days=76)
|
||||||
hatching.GoodSum = good_sums['goodSum']
|
good_sums = request.data.get('GoodSum', {})
|
||||||
hatching.loadingSum = good_sums['loadingSum']
|
if isinstance(good_sums, dict):
|
||||||
|
hatching.GoodSum = good_sums.get('goodSum', 0)
|
||||||
|
hatching.loadingSum = good_sums.get('loadingSum', 0)
|
||||||
|
elif isinstance(good_sums, list) and len(good_sums) > 0:
|
||||||
|
item = good_sums[0]
|
||||||
|
if isinstance(item, dict):
|
||||||
|
hatching.GoodSum = item.get('goodSum', 0)
|
||||||
|
hatching.loadingSum = item.get('loadingSum', 0)
|
||||||
|
|
||||||
if poultry:
|
if poultry:
|
||||||
hatching.poultry = poultry
|
hatching.poultry = poultry
|
||||||
|
|||||||
Reference in New Issue
Block a user