Initial commit: EFINTEL ERP Django Port

This commit is contained in:
Nachou-u
2026-08-19 18:04:18 -04:00
parent 1cd6ff1a6f
commit eb065909bd
39 changed files with 3852 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver
from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
from .models import Expense
@receiver(post_save, sender=Expense)
def expense_saved(sender, instance, created, **kwargs):
channel_layer = get_channel_layer()
action = 'created' if created else 'updated'
expense_data = {
'id': instance.id,
'amount': str(instance.amount),
'category': instance.category.name if instance.category else None,
'project': instance.project.name if instance.project else None,
'user': instance.user.username if instance.user else None,
'date': instance.date.strftime('%Y-%m-%d'),
'description': instance.description,
}
async_to_sync(channel_layer.group_send)(
'expenses_updates',
{
'type': 'expense_update',
'action': action,
'expense': expense_data
}
)
@receiver(post_delete, sender=Expense)
def expense_deleted(sender, instance, **kwargs):
channel_layer = get_channel_layer()
async_to_sync(channel_layer.group_send)(
'expenses_updates',
{
'type': 'expense_update',
'action': 'deleted',
'expense': {'id': instance.id}
}
)