You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.7 KiB
Python
62 lines
2.7 KiB
Python
from django.db import models
|
|
from billing.models import *
|
|
from django.utils import timezone
|
|
# Create your models here.
|
|
|
|
class Ticket(models.Model):
|
|
REGARDING_CHOICES = (
|
|
('General/Account/Billing', 'General/Account/Billing'),
|
|
('Project/Product', 'Project/Product'),
|
|
)
|
|
STATUS_CHOICES = (
|
|
('Open', 'Open'),
|
|
('Working On', 'Working On'),
|
|
('Closed', 'Closed'),
|
|
)
|
|
ticket_number = models.CharField(max_length=400, blank=True)
|
|
title = models.CharField(max_length=400)
|
|
description = models.TextField(null=True, blank=True)
|
|
status = models.CharField(max_length=50, choices=STATUS_CHOICES, null=True)
|
|
regarding = models.CharField(max_length=50, choices=REGARDING_CHOICES, null=True)
|
|
project = models.ForeignKey(Project, on_delete=models.SET_NULL, blank=True, null=True)
|
|
product = models.ForeignKey(Item, on_delete=models.SET_NULL, blank=True, null=True)
|
|
department = models.ForeignKey(Department, on_delete=models.SET_NULL,null=True, blank=True)
|
|
opened_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
|
opened_date = models.DateTimeField()
|
|
customer = models.ForeignKey(CustomerProfile, on_delete=models.SET_NULL, null=True)
|
|
def save(self, *args, **kwargs):
|
|
if not self.ticket_number:
|
|
last_ticket = Ticket.objects.filter(opened_date__year=timezone.now().year).order_by('-ticket_number').first()
|
|
if last_ticket and last_ticket.ticket_number:
|
|
last_ticket_number = int(last_ticket.ticket_number[-4:])
|
|
new_ticket_number = last_ticket_number + 1
|
|
else:
|
|
new_ticket_number = 1
|
|
|
|
|
|
current_year_last_two_digits = str(timezone.now().year)[-2:]
|
|
self.ticket_number = f"{current_year_last_two_digits}{new_ticket_number:04}"
|
|
|
|
super().save(*args, **kwargs)
|
|
|
|
class TicketUpdate(models.Model):
|
|
ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE)
|
|
description = models.TextField(null=True, blank=True)
|
|
added_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
|
date_added = models.DateTimeField()
|
|
|
|
|
|
class TicketAttachment(models.Model):
|
|
ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE)
|
|
ticket_update = models.ForeignKey(TicketUpdate, on_delete=models.CASCADE, null=True, blank=True)
|
|
file = models.FileField()
|
|
|
|
|
|
class TicketReaction(models.Model):
|
|
REACTION_CHOICES = (
|
|
('Happy', 'Happy'),
|
|
('Indifferent', 'Indifferent'),
|
|
('Sad', 'Sad'),
|
|
)
|
|
reaction = models.CharField(max_length=50, choices=REACTION_CHOICES, null=True)
|
|
ticket_update = models.ForeignKey(TicketUpdate, on_delete=models.CASCADE) |