add: add new invalid product model and create, list api added

This commit is contained in:
behruz-dev
2025-08-27 10:06:14 +05:00
parent 7a8efa74ff
commit 06f3b96e2b
13 changed files with 247 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
from .inventory import *
from .wherehouse import *
from .stock_movemend import *
from .stock_movemend import *
from .invalid_product import *

View File

@@ -0,0 +1,43 @@
from django.db import models
# shared
from core.apps.shared.models import BaseModel
# wherehouse
from core.apps.wherehouse.models import WhereHouse, Inventory
# projects
from core.apps.projects.models import ProjectFolder, EstimateWork
# accounts
from core.apps.accounts.models import User
class InvalidProduct(BaseModel):
STATUS = (
('BROKEN', 'singan'),
('LOST', 'yoqolgan'),
('OTHER', 'boshqa'),
)
# relationship
inventory = models.ForeignKey(Inventory, on_delete=models.CASCADE, related_name='invalid_products')
project_folder = models.ForeignKey(
ProjectFolder, on_delete=models.CASCADE, related_name='invalid_products'
)
witnesses = models.ManyToManyField(User, related_name='invalid_products')
work = models.ForeignKey(
EstimateWork, on_delete=models.SET_NULL, null=True, blank=True, related_name='invalid_products'
)
# required
amount = models.PositiveIntegerField()
status = models.CharField(max_length=20, choices=STATUS, default='other')
# optional
created_date = models.DateField(null=True, blank=True)
expiry_date = models.DateField(null=True, blank=True)
comment = models.DateField(null=True, blank=True)
file = models.FileField(null=True, blank=True, upload_to='invalid_product/files/')
def __str__(self):
return f'{self.amount} ta maxsulot yaroqsiz'
class Meta:
verbose_name = 'yaroqsiz maxsulot'
verbose_name_plural = 'yaroqsiz maxsulotlar'

View File

@@ -26,6 +26,7 @@ class Inventory(BaseModel):
Project, on_delete=models.SET_NULL, null=True, blank=True,
related_name='inventories'
)
is_invalid = models.BooleanField(default=False)
def __str__(self):
return f'{self.product} in {self.wherehouse}'