fix bug of transaction, when is success do not manage inventory again
This commit is contained in:
@@ -23,6 +23,7 @@ from apps.product.models import (
|
||||
)
|
||||
from apps.warehouse import models as warehouse_models
|
||||
from apps.livestock.models import LiveStockType
|
||||
from django.db.models.signals import post_save
|
||||
from apps.core.models import SystemConfig
|
||||
from django.db.transaction import atomic
|
||||
from apps.warehouse.exceptions import (
|
||||
@@ -143,7 +144,7 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
||||
# --- Case 1: success => only update items
|
||||
if transaction.transaction_status == 'success':
|
||||
for item_data in items_data:
|
||||
warehouse_models.InventoryQuotaSaleItem.objects.filter(
|
||||
qs = warehouse_models.InventoryQuotaSaleItem.objects.filter(
|
||||
Q(transaction=transaction) & (
|
||||
Q(free_product_id=item_data.get('free_product', None)) |
|
||||
Q(gov_product_id=item_data.get('gov_product', None))
|
||||
@@ -163,7 +164,7 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
||||
'transaction_date',
|
||||
]:
|
||||
if field in validated_data:
|
||||
setattr(transaction, field, validated_data)
|
||||
setattr(transaction, field, validated_data[field])
|
||||
|
||||
transaction.save(update_fields=[
|
||||
'transaction_status',
|
||||
@@ -178,12 +179,19 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
||||
|
||||
# items can change
|
||||
for item_data in items_data:
|
||||
warehouse_models.InventoryQuotaSaleItem.objects.filter(
|
||||
items = warehouse_models.InventoryQuotaSaleItem.objects.filter(
|
||||
Q(transaction=transaction) & (
|
||||
Q(free_product_id=item_data.get('free_product', None)) |
|
||||
Q(gov_product_id=item_data.get('gov_product', None))
|
||||
)
|
||||
).update(**item_data)
|
||||
)
|
||||
items.update(**item_data)
|
||||
|
||||
# if transaction status updated as success, call signal for inventory management
|
||||
if validated_data['transaction_status'] == 'success':
|
||||
for sale_item in items:
|
||||
sale_item.inventory_calculation = True
|
||||
sale_item.save()
|
||||
|
||||
return transaction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user