diff --git a/organizational_area/models.py b/organizational_area/models.py index 559fac39..de77e27a 100644 --- a/organizational_area/models.py +++ b/organizational_area/models.py @@ -230,19 +230,20 @@ class Meta: verbose_name = _("Organizational Structure Office Employee") verbose_name_plural = _("Organizational Structure Office Employees") - @classmethod - def get_default_operator_or_manager(cls, office): + @staticmethod + def get_default_operator_or_manager(office): """ Returns an use randomly. Try to get an office employee if exists. Else returns one of managers. """ - office_employees = cls.objects.filter(office=office, - employee__is_active=True).order_by('?') + osoe = OrganizationalStructureOfficeEmployee + office_employees = osoe.objects.filter(office=office, + employee__is_active=True).order_by('?') if not office_employees: - office_employees = cls.objects.filter(office__name=settings.DEFAULT_ORGANIZATIONAL_STRUCTURE_OFFICE, - office__organizational_structure=office.organizational_structure, - employee__is_active=True).order_by('?') + office_employees = osoe.objects.filter(office__name=settings.DEFAULT_ORGANIZATIONAL_STRUCTURE_OFFICE, + office__organizational_structure=office.organizational_structure, + employee__is_active=True).order_by('?') random_office_operator = office_employees.first() return random_office_operator.employee diff --git a/uni_ticket/models.py b/uni_ticket/models.py index 44fff315..3709664e 100644 --- a/uni_ticket/models.py +++ b/uni_ticket/models.py @@ -943,6 +943,16 @@ class Meta: verbose_name = _("Domande/Risposte Ticket") verbose_name_plural = _("Domande/Risposte Ticket") + @staticmethod + def get_unread_messages_count(tickets, by_operator=False): + unread_messages = TicketReply.objects.filter(ticket__in=tickets, + read_date=None) + # show messages sent by operator + if by_operator: + return unread_messages.exclude(structure=None).count() + # show messages sent by user + return unread_messages.filter(structure=None).count() + def get_folder(self): """ Returns ticket attachments folder path @@ -973,11 +983,11 @@ class Meta: verbose_name = _("Dipendenza Ticket") verbose_name_plural = _("Dipendenze Ticket") - @classmethod - def main_is_already_used(cls, ticket): + @staticmethod + def main_is_already_used(ticket): """ """ - relations = cls.objects.filter(subordinate_ticket=ticket) + relations = Ticket2Ticket.objects.filter(subordinate_ticket=ticket) if not relations: return False for relation in relations: main = relation.main_ticket @@ -1230,10 +1240,11 @@ def disable_other_configurations(self): other.is_active = False other.save(update_fields = ['is_active', 'modified']) - @classmethod - def get_active_protocol_configuration(cls, organizational_structure): - conf = cls.objects.filter(organizational_structure=organizational_structure, - is_active=True).first() + @staticmethod + def get_active_protocol_configuration(organizational_structure): + oswsap = OrganizationalStructureWSArchiPro + conf = oswsap.objects.filter(organizational_structure=organizational_structure, + is_active=True).first() return conf if conf else False def __str__(self): diff --git a/uni_ticket/views/manager.py b/uni_ticket/views/manager.py index e6e7fdc5..e2d90844 100644 --- a/uni_ticket/views/manager.py +++ b/uni_ticket/views/manager.py @@ -79,20 +79,16 @@ def dashboard(request, structure_slug, structure): cm = TicketCategory categories = cm.objects.filter(organizational_structure=structure) - messages = 0 - for ticket in tickets: - # if not ticket.is_followed_in_structure(structure=structure): - # continue - messages += ticket.get_messages_count()[1] - - d = {'ticket_messages': messages, - 'categories': categories, + messages = TicketReply.get_unread_messages_count(tickets=tickets) + + d = {'categories': categories, 'offices': offices, 'structure': structure, 'sub_title': sub_title, 'ticket_aperti': opened, 'ticket_assegnati_a_me': my_opened, 'ticket_chiusi': chiusi, + 'ticket_messages': messages, 'ticket_non_gestiti': unassigned, 'title': title,} return render(request, template, d) diff --git a/uni_ticket/views/operator.py b/uni_ticket/views/operator.py index dc003c63..38fba11b 100644 --- a/uni_ticket/views/operator.py +++ b/uni_ticket/views/operator.py @@ -55,19 +55,16 @@ def dashboard(request, structure_slug, structure, office_employee): unassigned += 1 # chiusi = tickets.filter(is_closed=True) chiusi = tickets.filter(is_closed=True).count() - messages = 0 - for ticket in tickets: - # if not ticket.is_followed_by_one_of_offices(offices): - # continue - messages += ticket.get_messages_count()[1] - d = {'ticket_messages': messages, - 'offices': offices, + messages = TicketReply.get_unread_messages_count(tickets=tickets) + + d = {'offices': offices, 'structure': structure, 'sub_title': sub_title, 'title': title, 'ticket_aperti': opened, 'ticket_assegnati_a_me': my_opened, 'ticket_chiusi': chiusi, + 'ticket_messages': messages, 'ticket_non_gestiti': unassigned,} return render(request, template, d) diff --git a/uni_ticket/views/user.py b/uni_ticket/views/user.py index 60056b4e..e7a52cba 100644 --- a/uni_ticket/views/user.py +++ b/uni_ticket/views/user.py @@ -636,15 +636,14 @@ def dashboard(request): # chiusi = tickets.filter(is_closed=True) chiusi = tickets.filter(is_closed=True).count() - messages = 0 - for ticket in tickets: - messages += ticket.get_messages_count(by_operator=True)[1] + messages = TicketReply.get_unread_messages_count(tickets=tickets, + by_operator=True) - d = {'ticket_messages': messages, - 'priority_levels': settings.PRIORITY_LEVELS, + d = {'priority_levels': settings.PRIORITY_LEVELS, 'sub_title': sub_title, 'ticket_aperti': opened, 'ticket_chiusi': chiusi, + 'ticket_messages': messages, 'ticket_non_gestiti': unassigned, 'title': title,}