fix: add_from_planitems bug

This commit is contained in:
caoqianming 2023-10-11 10:29:01 +08:00
parent c6f9b749c7
commit aff046db88
1 changed files with 6 additions and 5 deletions

View File

@ -63,6 +63,7 @@ class PuPlanViewSet(CustomModelViewSet):
puplan.save()
return Response()
class PuPlanItemViewSet(CustomModelViewSet):
"""
list: 采购计划明细
@ -163,18 +164,18 @@ class PuOrderItemViewSet(CustomModelViewSet):
if item.pu_order and item.pu_order.state != PuOrder.PUORDER_CREATE:
raise ParseError('存在计划明细已指定进行中的采购订单')
puorderitem, is_created = PuOrderItem.objects.get_or_create(
pu_order = puorder, material=item.material,
defaults={'pu_order': puorder, 'material': item.material, 'count': item.need_count}
pu_order=puorder, material=item.material,
defaults={'pu_order': puorder,
'material': item.material, 'count': item.need_count}
)
if not is_created:
puorderitem.count = puorderitem.count + item.need_count
puorderitem.save()
if puorder.delivery_date is None:
puorder.delivery_date = item.need_date
elif item.need_date < puorder.delivery_data:
elif item.need_date < puorder.delivery_date:
puorder.delivery_date = item.need_date
puorder.save()
item.pu_order = puorder
item.save()
return Response()