some changes in inventory serializer - creted date & distribution data
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-07-28 13:45
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pos_device', '0008_device_device_identity_deviceassignment'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='device',
|
||||||
|
name='is_activated',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='DeviceActivationCode',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('create_date', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('modify_date', models.DateTimeField(auto_now=True)),
|
||||||
|
('creator_info', models.CharField(max_length=100, null=True)),
|
||||||
|
('modifier_info', models.CharField(max_length=100, null=True)),
|
||||||
|
('trash', models.BooleanField(default=False)),
|
||||||
|
('code', models.CharField(max_length=10, null=True, unique=True)),
|
||||||
|
('expires_at', models.DateTimeField(default=datetime.datetime(2025, 7, 28, 17, 15, 1, 601936))),
|
||||||
|
('is_used', models.BooleanField(default=False)),
|
||||||
|
('company', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='code', to='pos_device.providercompany')),
|
||||||
|
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_createddby', to=settings.AUTH_USER_MODEL)),
|
||||||
|
('device', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='code', to='pos_device.device')),
|
||||||
|
('modified_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_modifiedby', to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-07-28 13:45
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('authentication', '0027_remove_organizationstats_total_buyers_and_more'),
|
||||||
|
('product', '0055_alter_quota_limit_by_organizations'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='productstats',
|
||||||
|
name='organization',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='product_stats', to='authentication.organization'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='productstats',
|
||||||
|
name='product',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='stats', to='product.product'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -135,12 +135,18 @@ class Product(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class ProductStats(BaseModel):
|
class ProductStats(BaseModel):
|
||||||
product = models.OneToOneField(
|
product = models.ForeignKey(
|
||||||
Product,
|
Product,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='stats',
|
related_name='stats',
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
|
organization = models.ForeignKey(
|
||||||
|
Organization,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='product_stats',
|
||||||
|
null=True
|
||||||
|
)
|
||||||
quotas_number = models.PositiveBigIntegerField(default=0)
|
quotas_number = models.PositiveBigIntegerField(default=0)
|
||||||
active_quotas_weight = models.PositiveBigIntegerField(default=0)
|
active_quotas_weight = models.PositiveBigIntegerField(default=0)
|
||||||
closed_quotas_weight = models.PositiveBigIntegerField(default=0)
|
closed_quotas_weight = models.PositiveBigIntegerField(default=0)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
from django.db.models.signals import post_save, post_delete
|
from django.db.models.signals import post_save, post_delete
|
||||||
|
from common.helpers import get_organization_by_user
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from .models import (
|
from .models import (
|
||||||
QuotaDistribution,
|
QuotaDistribution,
|
||||||
@@ -13,6 +14,7 @@ from apps.warehouse.models import (
|
|||||||
InventoryEntry
|
InventoryEntry
|
||||||
)
|
)
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from crum import get_current_user
|
||||||
|
|
||||||
|
|
||||||
def recalculate_remaining_amount(quota):
|
def recalculate_remaining_amount(quota):
|
||||||
@@ -34,10 +36,12 @@ def update_quota_remaining(sender, instance, **kwargs):
|
|||||||
def update_product_stats(instance: Product):
|
def update_product_stats(instance: Product):
|
||||||
""" update all stats of product """
|
""" update all stats of product """
|
||||||
|
|
||||||
if hasattr(instance, 'stats'):
|
organization = get_organization_by_user(get_current_user())
|
||||||
stat = instance.stats
|
|
||||||
|
if ProductStats.objects.filter(organization=organization, product=instance):
|
||||||
|
stat = instance.stats.get(organization=organization, product=instance)
|
||||||
else:
|
else:
|
||||||
stat = ProductStats.objects.create(product=instance)
|
stat = ProductStats.objects.create(product=instance, organization=organization)
|
||||||
|
|
||||||
# number of quotas
|
# number of quotas
|
||||||
quotas_count = instance.quotas.filter(is_closed=False).count() # noqa
|
quotas_count = instance.quotas.filter(is_closed=False).count() # noqa
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
|||||||
model = warehouse_models.InventoryEntry
|
model = warehouse_models.InventoryEntry
|
||||||
fields = [
|
fields = [
|
||||||
"id",
|
"id",
|
||||||
|
"create_date",
|
||||||
|
"modify_date",
|
||||||
"distribution",
|
"distribution",
|
||||||
"weight",
|
"weight",
|
||||||
"lading_number",
|
"lading_number",
|
||||||
@@ -22,17 +24,6 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
|||||||
"notes",
|
"notes",
|
||||||
]
|
]
|
||||||
|
|
||||||
def create(self, validated_data):
|
|
||||||
""" Custom create & set organization """
|
|
||||||
|
|
||||||
distribution = validated_data['distribution']
|
|
||||||
organization = distribution.assigned_organization
|
|
||||||
|
|
||||||
return warehouse_models.InventoryEntry.objects.create(
|
|
||||||
organization=organization,
|
|
||||||
**validated_data
|
|
||||||
)
|
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
"""
|
"""
|
||||||
check if inventory entries weight is not more than
|
check if inventory entries weight is not more than
|
||||||
@@ -58,6 +49,8 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
|||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
representation = super().to_representation(instance)
|
representation = super().to_representation(instance)
|
||||||
representation['document'] = instance.document
|
representation['document'] = instance.document
|
||||||
|
if instance.distribution:
|
||||||
|
representation['distribution'] = instance.distribution.distribution_id
|
||||||
|
|
||||||
return representation
|
return representation
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user