forked from hesabix/arc
71 lines
2.5 KiB
Python
Executable file
71 lines
2.5 KiB
Python
Executable file
"""
|
||
Triggerهای مربوط به اشخاص
|
||
"""
|
||
|
||
from typing import Any, Dict
|
||
from app.services.workflow.triggers.base_trigger import BaseTrigger
|
||
|
||
|
||
class PersonCreatedTrigger(BaseTrigger):
|
||
"""Trigger برای ایجاد شخص"""
|
||
|
||
def get_metadata(self) -> Dict[str, Any]:
|
||
return {
|
||
"name": "ایجاد شخص",
|
||
"description": "زمانی که یک شخص (مشتری/تامینکننده) ایجاد میشود",
|
||
"config_schema": {
|
||
"person_type": {
|
||
"type": "string",
|
||
"description": "نوع شخص",
|
||
"enum": ["customer", "supplier", "employee", "other"],
|
||
"ui_config": {
|
||
"labels": {
|
||
"customer": "مشتری",
|
||
"supplier": "تامینکننده",
|
||
"employee": "کارمند",
|
||
"other": "سایر"
|
||
}
|
||
},
|
||
"required": False
|
||
}
|
||
}
|
||
}
|
||
|
||
def execute(self, context: Dict[str, Any], config: Dict[str, Any]) -> Dict[str, Any]:
|
||
data = super().execute(context, config)
|
||
|
||
# فیلتر بر اساس نوع شخص
|
||
person_type = config.get("person_type")
|
||
if person_type:
|
||
person_types = data.get("person_types", [])
|
||
if person_type not in person_types:
|
||
return {}
|
||
|
||
return data
|
||
|
||
|
||
class PersonUpdatedTrigger(PersonCreatedTrigger):
|
||
"""بهروزرسانی اطلاعات شخص"""
|
||
|
||
def get_metadata(self) -> Dict[str, Any]:
|
||
return {
|
||
"name": "ویرایش شخص",
|
||
"description": "زمانی که اطلاعات یک شخص ویرایش میشود",
|
||
"config_schema": {
|
||
"person_type": {
|
||
"type": "string",
|
||
"description": "نوع شخص",
|
||
"enum": ["customer", "supplier", "employee", "other"],
|
||
"ui_config": {
|
||
"labels": {
|
||
"customer": "مشتری",
|
||
"supplier": "تامینکننده",
|
||
"employee": "کارمند",
|
||
"other": "سایر"
|
||
}
|
||
},
|
||
"required": False
|
||
}
|
||
}
|
||
}
|
||
|