add some fields to transaction & sale item
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-09-21 08:56
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('warehouse', '0029_inventoryquotasaletransaction_free_sale_state_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
old_name='pre_sale',
|
||||||
|
new_name='pre_sale_state',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='inventoryquotasaleitem',
|
||||||
|
name='is_pre_sale',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -114,7 +114,7 @@ class InventoryQuotaSaleTransaction(BaseModel):
|
|||||||
terminal = models.CharField(max_length=50, null=True)
|
terminal = models.CharField(max_length=50, null=True)
|
||||||
payer_cart = models.CharField(max_length=50, null=True)
|
payer_cart = models.CharField(max_length=50, null=True)
|
||||||
free_sale_state = models.BooleanField(default=False)
|
free_sale_state = models.BooleanField(default=False)
|
||||||
pre_sale = models.BooleanField(default=False)
|
pre_sale_state = models.BooleanField(default=False)
|
||||||
additional = models.JSONField(default=dict)
|
additional = models.JSONField(default=dict)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -152,6 +152,7 @@ class InventoryQuotaSaleItem(BaseModel):
|
|||||||
unit_price = models.PositiveBigIntegerField(default=0)
|
unit_price = models.PositiveBigIntegerField(default=0)
|
||||||
total_price = models.PositiveBigIntegerField(default=0)
|
total_price = models.PositiveBigIntegerField(default=0)
|
||||||
is_extra = models.BooleanField(default=False)
|
is_extra = models.BooleanField(default=False)
|
||||||
|
is_pre_sale = models.BooleanField(default=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'Item {self.product} - {self.weight} Kg - {self.total_price}'
|
return f'Item {self.product} - {self.weight} Kg - {self.total_price}'
|
||||||
|
|||||||
@@ -128,8 +128,8 @@ class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet, DynamicSearchM
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class QuotaPreSaleItemViewSet(viewsets.ModelViewSet):
|
class QuotaPreSaleItemViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDeviceMixin):
|
||||||
queryset = warehouse_models.QuotaPreSaleItem.objects.all().select_related(
|
queryset = warehouse_models.QuotaPreSaleItem.objects.all().select_related(
|
||||||
'organization', 'transaction', 'sale_item'
|
'organization', 'transaction', 'sale_item'
|
||||||
)
|
)
|
||||||
serializer_class = warehouse_serializers
|
serializer_class = warehouse_serializers.QuotaPreSaleItemSerializer
|
||||||
|
|||||||
@@ -208,3 +208,7 @@ class QuotaPreSaleItemSerializer(serializers.ModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = warehouse_models.QuotaPreSaleItem
|
model = warehouse_models.QuotaPreSaleItem
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
with atomic():
|
||||||
|
pass
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ router = DefaultRouter()
|
|||||||
|
|
||||||
router.register(r'inventory_entry', api.InventoryEntryViewSet, basename='inventory_entry')
|
router.register(r'inventory_entry', api.InventoryEntryViewSet, basename='inventory_entry')
|
||||||
router.register(r'transaction', api.InventoryQuotaSaleTransactionViewSet, basename='transaction')
|
router.register(r'transaction', api.InventoryQuotaSaleTransactionViewSet, basename='transaction')
|
||||||
|
router.register(r'pre_sale', api.QuotaPreSaleItemViewSet, basename='pre_sale')
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('v1/', include(router.urls))
|
path('v1/', include(router.urls))
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ from apps.warehouse.models import (
|
|||||||
InventoryEntry,
|
InventoryEntry,
|
||||||
InventoryQuotaSaleTransaction,
|
InventoryQuotaSaleTransaction,
|
||||||
InventoryQuotaSaleItem,
|
InventoryQuotaSaleItem,
|
||||||
ExtraSale
|
ExtraSale,
|
||||||
|
QuotaPreSaleItem
|
||||||
)
|
)
|
||||||
from apps.product.models import QuotaDistribution
|
from apps.product.models import QuotaDistribution
|
||||||
from apps.core.models import SystemConfig
|
from apps.core.models import SystemConfig
|
||||||
@@ -87,7 +88,34 @@ def create_extra_sale(
|
|||||||
sale_item.quota_distribution.warehouse_balance = 0
|
sale_item.quota_distribution.warehouse_balance = 0
|
||||||
sale_item.quota_distribution.save()
|
sale_item.quota_distribution.save()
|
||||||
|
|
||||||
|
# set transaction as free sale
|
||||||
|
transaction.free_sale_state = True
|
||||||
|
transaction.save()
|
||||||
|
|
||||||
|
# set sale item as extra sale
|
||||||
|
sale_item.is_extra = True
|
||||||
|
sale_item.save()
|
||||||
|
|
||||||
return extra_sale
|
return extra_sale
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def create_pre_sale(
|
||||||
|
transaction: InventoryQuotaSaleTransaction,
|
||||||
|
sale_item: InventoryQuotaSaleItem
|
||||||
|
) -> typing.Any:
|
||||||
|
"""
|
||||||
|
:param transaction
|
||||||
|
:param sale_item
|
||||||
|
Create pre_sale for distributions
|
||||||
|
"""
|
||||||
|
|
||||||
|
if sale_item.quota_distribution.pre_sale:
|
||||||
|
# create pre sale
|
||||||
|
pre_sale = QuotaPreSaleItem.objects.create(
|
||||||
|
transaction=transaction,
|
||||||
|
sale_item=sale_item,
|
||||||
|
distribution=sale_item.quota_distribution,
|
||||||
|
weight=sale_item.weight
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user