Watch
1
0
Fork
You've already forked arc
0
forked from hesabix/arc
arc/hesabixAPI/app/services/workflow/triggers/inventory_triggers.py
2026-04-14 19:34:55 +03:30

50 lines
1.7 KiB
Python
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Triggerهای مربوط به موجودی
"""
from typing import Any, Dict
from app.services.workflow.triggers.base_trigger import BaseTrigger
class InventoryLowTrigger(BaseTrigger):
"""Trigger برای موجودی کم"""
def get_metadata(self) -> Dict[str, Any]:
return {
"name": "موجودی کم",
"description": "زمانی که موجودی یک محصول کمتر از حد مشخص می‌شود",
"config_schema": {
"product_id": {
"type": "integer",
"description": "محصول (اختیاری - خالی = همه محصولات)",
"required": False,
"ui_type": "product_selector",
"ui_config": {"business_scoped": True}
},
"warehouse_id": {
"type": "integer",
"description": "انبار (اختیاری)",
"required": False,
"ui_type": "warehouse_selector",
"ui_config": {"business_scoped": True}
}
}
}
def execute(self, context: Dict[str, Any], config: Dict[str, Any]) -> Dict[str, Any]:
data = super().execute(context, config)
# فیلتر بر اساس محصول
product_id = config.get("product_id")
if product_id is not None:
if data.get("product_id") != product_id:
return {}
# فیلتر بر اساس انبار
warehouse_id = config.get("warehouse_id")
if warehouse_id is not None:
if data.get("warehouse_id") != warehouse_id:
return {}
return data