change: change logic in order/tasks/ file

This commit is contained in:
behruz-dev
2025-08-27 10:45:48 +05:00
parent 86eb2f7575
commit 0e12d06136

View File

@@ -1,17 +1,23 @@
from celery import shared_task
from django.db.models import F
from core.apps.wherehouse.models.inventory import Inventory
@shared_task
def create_inventory(wherehouse, quantity, product, unity, price, project_folder, project, unity_price):
Inventory.objects.create(
wherehouse_id=wherehouse,
quantity=quantity,
inventory, created = Inventory.objects.get_or_create(
product_id=product,
wherehouse_id=wherehouse,
unity_id=unity,
price=price,
project_folder_id=project_folder,
project_id=project,
unit_price=unity_price
defaults=dict(
quantity=quantity,
price=price,
project_folder_id=project_folder,
project_id=project,
unit_price=unity_price
)
)
if not created:
inventory.quantity = F('quantity') + quantity
inventory.save(update_fields=["quantity"])