Files
ihrm/horilla_automations/models.py
Horilla 2fee7c18bb [IMP] Remove inter module dependency (#274)
This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made:

1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase.
2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation.
3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules.

These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code.

**NOTE**
For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations.

- `python3 manage.py makemigrations`
- `python3 manage.py migrate base`
- `python3 manage.py migrate`





* [IMP] ASSET: Asset module dependency removal from other Horilla apps

* [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps

* [IMP] BASE: Base module dependency removal from other Horilla apps

* [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps

* [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps

* [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps

* [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps

* [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps

* [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps

* [IMP] LEAVE: Leave module dependency removal from other Horilla apps

* [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps

* [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps

* [IMP] PMS: PMS module dependency removal from other Horilla apps

* [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps

* [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps

* [IMP] HORILLA: Dependency removal updates

* [IMP] TEMPLATES: Dependency removal updates

* [IMP] STATIC: Dependency removal updates

* [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps

* [ADD] HORILLA: methods.py

* [UPDT] HORILLA: Settings.py

* [FIX] EMPLOYEE: About tab issue

* Update horilla_settings.py

* Remove dummy db init password
2024-08-05 14:22:44 +05:30

111 lines
3.5 KiB
Python

from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _trans
from base.models import HorillaMailTemplate
from horilla.models import HorillaModel
from horilla_views.cbv_methods import render_template
MODEL_CHOICES = []
CONDITIONS = [
("equal", _trans("Equal (==)")),
("notequal", _trans("Not Equal (!=)")),
("lt", _trans("Less Than (<)")),
("gt", _trans("Greater Than (>)")),
("le", _trans("Less Than or Equal To (<=)")),
("ge", _trans("Greater Than or Equal To (>=)")),
("icontains", _trans("Contains")),
]
class MailAutomation(HorillaModel):
"""
MailAutoMation
"""
choices = [
("on_create", "On Create"),
("on_update", "On Update"),
("on_delete", "On Delete"),
]
title = models.CharField(max_length=50, unique=True)
method_title = models.CharField(max_length=50, editable=False)
model = models.CharField(max_length=100, choices=MODEL_CHOICES, null=False)
mail_to = models.TextField(verbose_name="Mail to")
mail_details = models.CharField(
max_length=250,
help_text="Fill mail template details(reciever/instance, `self` will be the person who trigger the automation)",
)
mail_detail_choice = models.TextField(default="", editable=False)
trigger = models.CharField(max_length=10, choices=choices)
# udpate the on_update logic to if and only if when
# changes in the previous and current value
mail_template = models.ForeignKey(HorillaMailTemplate, on_delete=models.CASCADE)
template_attachments = models.ManyToManyField(
HorillaMailTemplate,
related_name="template_attachment",
blank=True,
)
condition_html = models.TextField(null=True, editable=False)
condition_querystring = models.TextField(null=True, editable=False)
condition = models.TextField()
def save(self, *args, **kwargs):
if not self.pk:
self.method_title = self.title.replace(" ", "_").lower()
return super().save(*args, **kwargs)
def __str__(self) -> str:
return self.title
def get_avatar(self):
"""
Method will retun the api to the avatar or path to the profile image
"""
url = f"https://ui-avatars.com/api/?name={self.title}&background=random"
return url
def get_mail_to_display(self):
"""
method that returns the display value for `mail_to`
field
"""
mail_to = eval(self.mail_to)
mappings = []
for mapping in mail_to:
mapping = mapping.split("__")
display = ""
for split in mapping:
split = split.replace("_id", "").replace("_", " ")
split = split.capitalize()
display = display + f"{split} >"
display = display[:-1]
mappings.append(display)
return render_template(
"horilla_automations/mail_to.html", {"instance": self, "mappings": mappings}
)
def detailed_url(self):
return reverse("automation-detailed-view", kwargs={"pk": self.pk})
def conditions(self):
return render_template(
"horilla_automations/conditions.html", {"instance": self}
)
def delete_url(self):
return reverse("delete-automation", kwargs={"pk": self.pk})
def edit_url(self):
"""
Edit url
"""
return reverse("update-automation", kwargs={"pk": self.pk})
def trigger_display(self):
""""""
return self.get_trigger_display()