celery & attributes list by product

This commit is contained in:
2025-07-19 10:41:03 +03:30
parent a6b29ad28d
commit dc1e79c684
7 changed files with 97 additions and 8 deletions

View File

@@ -0,0 +1,12 @@
from celery import shared_task
from apps.product.models import SaleUnit
@shared_task(bind=True)
def task_func(self):
print("sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss")
sale_unit = SaleUnit.objects.get(id=1)
print(sale_unit.unit)
sale_unit.trash = True
sale_unit.save()
return 'Done'

View File

@@ -28,12 +28,12 @@ class BaseModel(models.Model):
abstract = True
def save(self, *args, **kwargs):
user = get_current_user() # get user object
self.modified_by = user
if not self.creator_info:
self.created_by = user
self.creator_info = user.first_name + ' ' + user.last_name
self.modifier_info = user.first_name + ' ' + user.last_name
# user = get_current_user() # get user object
# self.modified_by = user
# if not self.creator_info:
# self.created_by = user
# self.creator_info = user.first_name + ' ' + user.last_name
# self.modifier_info = user.first_name + ' ' + user.last_name
super(BaseModel, self).save(*args, **kwargs)

View File

@@ -42,6 +42,7 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
if quota.is_closed:
raise QuotaClosedException()
# check if assigned organization is in quota limitation
if assigned_organization not in quota.limit_by_organizations.all():
raise QuotaLimitByOrganizationException()

View File

@@ -118,11 +118,26 @@ class ProductViewSet(viewsets.ModelViewSet):
class AttributeViewSet(viewsets.ModelViewSet):
""" attributes of reference product """ #
queryset = product_models.Attribute.objects.all()
queryset = product_models.Attribute.objects.select_related('product').all()
serializer_class = product_serializers.AttributeSerializer
filter_backends = [filters.SearchFilter]
search_fields = ['name']
@action(
methods=['get'],
detail=True,
url_path='by_product',
url_name='by_product',
name='by_product'
)
def get_attributes_by_product(self, request, pk=None):
""" get attributes by product with global ones """
attributes = self.queryset.filter(Q(is_global=True) | Q(product__id=pk))
serializer = self.serializer_class(attributes, many=True)
return Response(serializer.data)
@action(
methods=['put'],
detail=True,