fix - soft delete in quota binary tree & CO level of show organizations
This commit is contained in:
@@ -11,6 +11,7 @@ from apps.authorization.models import UserRelations
|
||||
from apps.core.models import BaseModel
|
||||
from apps.herd.models import Rancher
|
||||
from apps.livestock.models import LiveStockType
|
||||
from apps.product.services.distribution_child import get_all_distribution_child
|
||||
|
||||
|
||||
class LivestockGroup(models.TextChoices):
|
||||
@@ -441,12 +442,19 @@ class Quota(BaseModel):
|
||||
return self.quota_weight - distributed_weight
|
||||
|
||||
def is_in_valid_time(self):
|
||||
""" check if quota allowed time for distribute, sale, etc is expired """
|
||||
""" check if quota allowed time for distribute, sale and... is expired """
|
||||
now = datetime.now()
|
||||
persian_date = jdatetime.datetime.fromgregorian(datetime=now)
|
||||
|
||||
return persian_date.month in self.sale_license
|
||||
|
||||
def soft_delete(self):
|
||||
self.trash = True
|
||||
self.save(update_fields=['trash'])
|
||||
|
||||
for dist in self.distributions_assigned.all():
|
||||
dist.soft_delete()
|
||||
|
||||
def save(self, calculate_final_price=None, *args, **kwargs):
|
||||
if not self.quota_id:
|
||||
self.quota_id = self.generate_quota_id()
|
||||
@@ -737,6 +745,17 @@ class QuotaDistribution(BaseModel):
|
||||
def __str__(self):
|
||||
return f"{self.distribution_id}-"
|
||||
|
||||
def soft_delete(self):
|
||||
self.trash = True
|
||||
self.save(update_fields=['trash'])
|
||||
|
||||
childs = get_all_distribution_child(self) # noqa
|
||||
for child in childs:
|
||||
child.soft_delete()
|
||||
|
||||
for entry in self.inventory_entry.all():
|
||||
entry.soft_delete()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.distribution_id:
|
||||
self.distribution_id = self.generate_distribution_id()
|
||||
|
||||
Reference in New Issue
Block a user