orders: add new fields to order model
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -267,3 +267,5 @@ poetry.toml
|
||||
pyrightconfig.json
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/python,django
|
||||
|
||||
.zed/
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from core.apps.accounts.models.permission import Permission, PermissionToTab, PermissionToAction
|
||||
from core.apps.accounts.models.permission import (
|
||||
Permission,
|
||||
PermissionToTab,
|
||||
PermissionToAction,
|
||||
)
|
||||
|
||||
|
||||
@admin.register(Permission)
|
||||
class PermissionAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'code']
|
||||
filter_horizontal = ['permission_tab']
|
||||
list_display = ["name", "code"]
|
||||
filter_horizontal = ["permission_tab"]
|
||||
|
||||
|
||||
@admin.register(PermissionToTab)
|
||||
class PermissionToTabAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'code']
|
||||
filter_horizontal = ['permission_to_actions']
|
||||
list_display = ["name", "code"]
|
||||
filter_horizontal = ["permission_to_actions"]
|
||||
|
||||
|
||||
@admin.register(PermissionToAction)
|
||||
class PermissionToActionAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'code']
|
||||
list_display = ["name", "code"]
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# Generated by Django 5.2.4 on 2025-11-10 15:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('orders', '0034_alter_offer_price_alter_order_amount_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='completion_percentage',
|
||||
field=models.FloatField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='received_count',
|
||||
field=models.PositiveBigIntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='received_date',
|
||||
field=models.DateField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
@@ -49,6 +49,10 @@ class Order(BaseModel):
|
||||
amount = models.DecimalField(max_digits=15, decimal_places=2, default=0.00)
|
||||
qqs = models.PositiveBigIntegerField(null=True, blank=True)
|
||||
|
||||
received_count = models.PositiveBigIntegerField(default=0)
|
||||
received_date = models.DateField(null=True, blank=True)
|
||||
completion_percentage = models.FloatField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.product} {self.unity} quantity order"
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class OrderListSerializer(serializers.ModelSerializer):
|
||||
fields = [
|
||||
'id', 'product', 'unity', 'quantity', 'project', 'project_folder',
|
||||
'wherehouse', 'date', 'status', 'employee', 'counterparty', 'unit_amount', 'currency',
|
||||
'total_price', 'qqs_price', 'amount', 'qqs'
|
||||
'total_price', 'qqs_price', 'amount', 'qqs', 'received_count', 'received_date', 'completion_percentage'
|
||||
]
|
||||
|
||||
def get_employee(self, obj):
|
||||
|
||||
@@ -517,3 +517,13 @@ class PartyExpenceCreateSerializer(serializers.ModelSerializer):
|
||||
payment_type.save()
|
||||
|
||||
return expence
|
||||
|
||||
|
||||
class ReceivePartySerializer(serializers.Serializer):
|
||||
order_id = serializers.UUIDField()
|
||||
product_quantity = serializers.IntegerField()
|
||||
product_receive_date = serializers.DateField()
|
||||
|
||||
|
||||
class ReceiveMultipleOrderSerializer(serializers.Serializer):
|
||||
product = ReceivePartySerializer(many=True)
|
||||
@@ -5,7 +5,9 @@ from core.apps.wherehouse.models.inventory import Inventory
|
||||
|
||||
|
||||
@shared_task
|
||||
def create_inventory(wherehouse, quantity, product, unity, price, project_folder, project, unity_price):
|
||||
def create_inventory(
|
||||
wherehouse, quantity, product, unity, price, project_folder, project, unity_price
|
||||
):
|
||||
inventory, created = Inventory.objects.get_or_create(
|
||||
product_id=product,
|
||||
wherehouse_id=wherehouse,
|
||||
@@ -15,7 +17,7 @@ def create_inventory(wherehouse, quantity, product, unity, price, project_folder
|
||||
price=price,
|
||||
project_folder_id=project_folder,
|
||||
project_id=project,
|
||||
unit_price=unity_price
|
||||
unit_price=unity_price,
|
||||
)
|
||||
)
|
||||
if not created:
|
||||
|
||||
@@ -141,16 +141,26 @@ class OrderDeleteToPartyApiView(generics.GenericAPIView):
|
||||
|
||||
|
||||
class PartyChangeStatusToIsMadeApiView(generics.GenericAPIView):
|
||||
serializer_class = None
|
||||
serializer_class = serializers.ReceiveMultipleOrderSerializer
|
||||
queryset = Party.objects.all()
|
||||
permission_classes = [HasRolePermission]
|
||||
pagination_class = None
|
||||
|
||||
def get(self, request, party_id):
|
||||
def post(self, request, party_id):
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
if not serializer.is_valid(raise_exception=True):
|
||||
return Response({"success": False, "message": serializer.errors}, status=400)
|
||||
party = get_object_or_404(Party, id=party_id)
|
||||
party.status = 'PARTY_IS_MADE'
|
||||
party.save()
|
||||
data = serializer.validated_data
|
||||
for item in data['product']:
|
||||
order_id = item['order_id']
|
||||
product_quantity = item['product_quantity']
|
||||
product_receive_date = item['product_receive_date']
|
||||
for order in party.orders.all():
|
||||
if order.id == order_id:
|
||||
completion_percentage = (product_quantity / order.quantity) * 100
|
||||
create_inventory.delay(
|
||||
order.wherehouse.id,
|
||||
order.quantity,
|
||||
@@ -161,6 +171,9 @@ class PartyChangeStatusToIsMadeApiView(generics.GenericAPIView):
|
||||
order.project.id if order.project else None,
|
||||
order.unit_amount,
|
||||
)
|
||||
order.received_count += product_quantity
|
||||
order.received_date = product_receive_date
|
||||
order.comletion_percentage = completion_percentage
|
||||
return Response(
|
||||
{'success': True, 'message': 'party updated'},
|
||||
status=200
|
||||
|
||||
Reference in New Issue
Block a user