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 celery import shared_task
from django.db.models import F
from core.apps.wherehouse.models.inventory import Inventory from core.apps.wherehouse.models.inventory import Inventory
@shared_task @shared_task
def create_inventory(wherehouse, quantity, product, unity, price, project_folder, project, unity_price): def create_inventory(wherehouse, quantity, product, unity, price, project_folder, project, unity_price):
Inventory.objects.create( inventory, created = Inventory.objects.get_or_create(
wherehouse_id=wherehouse,
quantity=quantity,
product_id=product, product_id=product,
wherehouse_id=wherehouse,
unity_id=unity, unity_id=unity,
price=price, defaults=dict(
project_folder_id=project_folder, quantity=quantity,
project_id=project, price=price,
unit_price=unity_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"])