add new apis

This commit is contained in:
behruz-dev
2025-08-14 13:40:34 +05:00
parent 66aab361ef
commit f2226b94c0
7 changed files with 70 additions and 1752 deletions

View File

@@ -0,0 +1,40 @@
# Generated by Django 5.2.4 on 2025-08-14 13:29
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('projects', '0015_estimateproduct_estimate_work'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AddField(
model_name='estimatework',
name='employee',
field=models.ManyToManyField(blank=True, related_name='estimate_work', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='estimatework',
name='end_date',
field=models.DateField(blank=True, null=True),
),
migrations.AddField(
model_name='estimatework',
name='percentage',
field=models.PositiveSmallIntegerField(blank=True, db_default=0, null=True),
),
migrations.AddField(
model_name='estimatework',
name='start_date',
field=models.DateField(blank=True, null=True),
),
migrations.AddField(
model_name='estimatework',
name='status',
field=models.CharField(choices=[('OPEN', 'ochiq'), ('IN_PROGRESS', 'bajarilmoqda'), ('DONE', 'bajarildi')], default='ochiq', max_length=20),
),
]

View File

@@ -4,6 +4,7 @@ from django.utils.translation import gettext_lazy as _
from core.apps.shared.models import BaseModel
from core.apps.projects.models import Project
from core.apps.products.models import Unity, Product
from core.apps.accounts.models import User
class ProjectEstimate(BaseModel):
@@ -19,6 +20,12 @@ class ProjectEstimate(BaseModel):
class EstimateWork(BaseModel):
STATUS = (
('OPEN', 'ochiq'),
('IN_PROGRESS', 'bajarilmoqda'),
('DONE', 'bajarildi'),
)
number = models.PositiveIntegerField(default=1)
name = models.CharField(max_length=200)
quantity = models.PositiveIntegerField(default=1)
@@ -29,9 +36,15 @@ class EstimateWork(BaseModel):
estimate = models.ForeignKey(
ProjectEstimate, on_delete=models.CASCADE, related_name='estimate_works'
)
date = models.DateField(null=True, blank=True)
date = models.DateField(null=True, blank=True)
total_price = models.PositiveBigIntegerField(default=0)
status = models.CharField(choices=STATUS, max_length=20, default='ochiq')
start_date = models.DateField(null=True, blank=True)
end_date = models.DateField(null=True, blank=True)
employee = models.ManyToManyField(User, related_name='estimate_work', blank=True)
percentage = models.PositiveSmallIntegerField(db_default=0, null=True, blank=True)
def __str__(self):
return f"{self.number}.{self.name}"

View File

@@ -66,16 +66,21 @@ class EstimateWorkUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = EstimateWork
fields = [
'name', 'quantity', 'price', 'unity', 'date', 'total_price',
'name', 'quantity', 'price', 'unity', 'date', 'total_price', 'employee', 'status',
'start_date', 'end_date'
]
def update(self, instance, validated_data):
employee_ids = validated_data.pop('employee', [])
instance.name = validated_data.get('name', instance.name)
instance.quantity = validated_data.get('quantity', instance.quantity)
instance.price = validated_data.get('price', instance.price)
instance.unity = validated_data.get('unity', instance.unity)
instance.date = validated_data.get('date', instance.date)
instance.total_price = validated_data.get('total_price', instance.total_price)
instance.status = validated_data.get('status', instance.status)
instance.start_date = validated_data.get('start_date', instance.start_date)
instance.end_date = validated_data.get('end_date', instance.end_date)
instance.employee.set(employee_ids)
instance.save()
return instance
return instance