From 27ee1167b5a9aaa5ead7dfa9d0372136a22f65a9 Mon Sep 17 00:00:00 2001 From: MoriatyC <119889525@qq.com> Date: Thu, 18 Jan 2018 18:19:10 +0800 Subject: [PATCH] fix field null bug (#291) * fix field null bug * simplyfy --- Process/models/quota.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Process/models/quota.py b/Process/models/quota.py index e5fa57f..17aac99 100644 --- a/Process/models/quota.py +++ b/Process/models/quota.py @@ -83,7 +83,8 @@ def createProcurementMaterial(self): procurement_material.category = \ item.process_material.material.category procurement_material.count = item.process_material.count - procurement_material.weight = item.process_material.weight + procurement_material.weight = \ + item.process_material.piece_weight or 0 procurement_material_list.append(procurement_material) else: for sub_order in work_order.subworkorder_set.all(): @@ -92,10 +93,16 @@ def createProcurementMaterial(self): procurement_material = ProcurementMaterial() procurement_material.sub_order = sub_order procurement_material.inventory_type = self.category - procurement_material.material_number = item.material.uid - procurement_material.category = item.material.category - procurement_material.count = item.count - procurement_material.weight = item.weight + if self.category != QUOTA_LIST_CATEGORY_AUXILIARY: + procurement_material.material_number = \ + item.material.uid + procurement_material.category = item.material.category + if self.category == QUOTA_LIST_CATEGORY_PRINCIPAL: + procurement_material.count = item.count + procurement_material.weight = item.weight + else: + procurement_material.weight = item.quota or 0 + procurement_material.count = 0 procurement_material_list.append(procurement_material) ProcurementMaterial.objects.bulk_create(procurement_material_list)