fix bug of transaction, when is success do not manage inventory again
This commit is contained in:
@@ -130,6 +130,12 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
|||||||
"serial": device.serial,
|
"serial": device.serial,
|
||||||
"provider": organization.name,
|
"provider": organization.name,
|
||||||
"provider_tell": organization.phone,
|
"provider_tell": organization.phone,
|
||||||
|
"main_company": {
|
||||||
|
"name": main_company.name,
|
||||||
|
"phone": main_company.phone,
|
||||||
|
"shaba": main_company.bank_information.all().first().sheba, # noqa
|
||||||
|
"amount": 400
|
||||||
|
}
|
||||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -147,6 +153,12 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
|||||||
"password": "****",
|
"password": "****",
|
||||||
"provider": organization.name,
|
"provider": organization.name,
|
||||||
"provider_tell": organization.phone,
|
"provider_tell": organization.phone,
|
||||||
|
"main_company": {
|
||||||
|
"name": main_company.name,
|
||||||
|
"phone": main_company.phone,
|
||||||
|
"shaba": main_company.bank_information.all().first().sheba, # noqa
|
||||||
|
"amount": 400
|
||||||
|
}
|
||||||
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-09-30 06:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('warehouse', '0035_inventoryquotasaletransaction_pos_date_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='inventoryquotasaleitem',
|
||||||
|
name='inventory_calculation',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -179,6 +179,7 @@ class InventoryQuotaSaleItem(BaseModel):
|
|||||||
is_pre_sale = models.BooleanField(default=False)
|
is_pre_sale = models.BooleanField(default=False)
|
||||||
additional = models.JSONField(default=dict)
|
additional = models.JSONField(default=dict)
|
||||||
livestock_statistic = models.JSONField(default=dict)
|
livestock_statistic = models.JSONField(default=dict)
|
||||||
|
inventory_calculation = models.BooleanField(default=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def product(self):
|
def product(self):
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from apps.product.models import (
|
|||||||
)
|
)
|
||||||
from apps.warehouse import models as warehouse_models
|
from apps.warehouse import models as warehouse_models
|
||||||
from apps.livestock.models import LiveStockType
|
from apps.livestock.models import LiveStockType
|
||||||
|
from django.db.models.signals import post_save
|
||||||
from apps.core.models import SystemConfig
|
from apps.core.models import SystemConfig
|
||||||
from django.db.transaction import atomic
|
from django.db.transaction import atomic
|
||||||
from apps.warehouse.exceptions import (
|
from apps.warehouse.exceptions import (
|
||||||
@@ -143,7 +144,7 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
|||||||
# --- Case 1: success => only update items
|
# --- Case 1: success => only update items
|
||||||
if transaction.transaction_status == 'success':
|
if transaction.transaction_status == 'success':
|
||||||
for item_data in items_data:
|
for item_data in items_data:
|
||||||
warehouse_models.InventoryQuotaSaleItem.objects.filter(
|
qs = warehouse_models.InventoryQuotaSaleItem.objects.filter(
|
||||||
Q(transaction=transaction) & (
|
Q(transaction=transaction) & (
|
||||||
Q(free_product_id=item_data.get('free_product', None)) |
|
Q(free_product_id=item_data.get('free_product', None)) |
|
||||||
Q(gov_product_id=item_data.get('gov_product', None))
|
Q(gov_product_id=item_data.get('gov_product', None))
|
||||||
@@ -163,7 +164,7 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
|||||||
'transaction_date',
|
'transaction_date',
|
||||||
]:
|
]:
|
||||||
if field in validated_data:
|
if field in validated_data:
|
||||||
setattr(transaction, field, validated_data)
|
setattr(transaction, field, validated_data[field])
|
||||||
|
|
||||||
transaction.save(update_fields=[
|
transaction.save(update_fields=[
|
||||||
'transaction_status',
|
'transaction_status',
|
||||||
@@ -178,12 +179,19 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
# items can change
|
# items can change
|
||||||
for item_data in items_data:
|
for item_data in items_data:
|
||||||
warehouse_models.InventoryQuotaSaleItem.objects.filter(
|
items = warehouse_models.InventoryQuotaSaleItem.objects.filter(
|
||||||
Q(transaction=transaction) & (
|
Q(transaction=transaction) & (
|
||||||
Q(free_product_id=item_data.get('free_product', None)) |
|
Q(free_product_id=item_data.get('free_product', None)) |
|
||||||
Q(gov_product_id=item_data.get('gov_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
|
return transaction
|
||||||
|
|
||||||
|
|||||||
@@ -60,8 +60,10 @@ def update_distribution_warehouse_entry(sender, instance, **kwargs):
|
|||||||
@receiver(post_delete, sender=InventoryQuotaSaleItem)
|
@receiver(post_delete, sender=InventoryQuotaSaleItem)
|
||||||
def update_distribution_warehouse_sold_and_balance(sender, instance: InventoryQuotaSaleItem, **kwargs):
|
def update_distribution_warehouse_sold_and_balance(sender, instance: InventoryQuotaSaleItem, **kwargs):
|
||||||
if instance.quota_distribution and not instance.quota_distribution.pre_sale:
|
if instance.quota_distribution and not instance.quota_distribution.pre_sale:
|
||||||
warehouse_sold_and_balance(
|
# if transaction status is success and warehouse management Done once, inventory_calculation set to true
|
||||||
quota_distribution=instance.quota_distribution,
|
if instance.transaction.transaction_status == 'success' and instance.inventory_calculation is False:
|
||||||
)
|
warehouse_sold_and_balance(
|
||||||
|
quota_distribution=instance.quota_distribution,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print("quota distribution is null - warehouse app signals")
|
print("quota distribution is null - warehouse app signals")
|
||||||
|
|||||||
Reference in New Issue
Block a user