Эх сурвалжийг харах

feat: Extract ticket logic into a separate lib

This commit extracts constants and data structures related to ticket types and statuses into a separate file `lib/tickets.py`.
blezz-tech 1 сар өмнө
parent
commit
75b5d6c67f
2 өөрчлөгдсөн 77 нэмэгдсэн , 71 устгасан
  1. 72 0
      lib/tickets.py
  2. 5 71
      models/ticket.py

+ 72 - 0
lib/tickets.py

@@ -0,0 +1,72 @@
+
+class Ticket:
+    TICKET_TYPES = (
+        (1, "ST_REQUEST", [
+            [111, 121, 149, 159],
+            [110, 121, 149, 159],
+            [121, 131, 149, 159],
+            [131, 141, 149],
+            [141, 151, 110],
+            [149, 151, 110],
+            [159],
+            [151]
+        ]),
+        (2, "SERVICE_REQUEST", [
+            [210, 211, 251],
+            [211, 212, 220, 238, 249],
+            [212, 221, 229, 238, 249],
+            [221, 222, 238, 249],
+            [220, 211, 238, 249],
+            [229, 211, 251],
+            [222, 231, 238, 249],
+            [231, 241, 238, 249],
+            [238, 231, 239, 211, 212, 221, 220, 222, 249],
+            [239, 231, 239, 211, 212, 221, 220, 222, 249],
+            [241, 251],
+            [249, 251],
+            [251]
+        ]),
+        (3, "ACCESS_REQUEST", [
+            [320, 321, 359],
+            [321, 359],
+            [359]
+        ]),
+        (4, "NEG_REQUEST", [
+            [420, 421, 459],
+            [421, 459],
+            [459]
+        ])
+    )
+
+    TICKET_STATUSES_NAMES = {
+        111: "NEW",
+        110: "REOPENED",
+        121: "ASSIGNED",
+        131: "IN PROCESS",
+        149: "WONTFIX",
+        141: "DONE",
+        159: "DUPLICATE",
+        151: "CLOSED",
+        210: "TEMPLATE",
+        211: "BOOKED",
+        212: "ASSIGNED",
+        221: "ACCEPTED",
+        220: "PENDING",
+        229: "DECLINED",
+        222: "PRE-START",
+        231: "PROCESS",
+        238: "PRE-FORCEMAJEUER",
+        239: "FORCEMAJEUER",
+        241: "DONE",
+        249: "CANCELLED",
+        251: "CLOSED",
+        320: "PENDING",
+        321: "ACCEPTED",
+        359: "DECLINED",
+        420: "PENDING",
+        421: "ACCEPTED",
+        459: "DECLINED"
+    }
+
+    TICKET_TYPES_CHOICES = tuple((item[0], item[1]) for item in TICKET_TYPES)
+    LIFE_CYCLE_DICT = dict((item[0], item[2]) for item in TICKET_TYPES)

+ 5 - 71
models/ticket.py

@@ -3,79 +3,13 @@ from django.db import models, transaction
 from django.urls import reverse
 
 from tickets.models.ticket_list import TicketList
-
+from tickets.lib.tickets import Ticket as T
 
 class Ticket(models.Model):
-    TICKET_TYPES = (
-        (1, "ST_REQUEST", [
-            [111, 121, 149, 159],
-            [110, 121, 149, 159],
-            [121, 131, 149, 159],
-            [131, 141, 149],
-            [141, 151, 110],
-            [149, 151, 110],
-            [159],
-            [151]
-        ]),
-        (2, "SERVICE_REQUEST", [
-            [210, 211, 251],
-            [211, 212, 220, 238, 249],
-            [212, 221, 229, 238, 249],
-            [221, 222, 238, 249],
-            [220, 211, 238, 249],
-            [229, 211, 251],
-            [222, 231, 238, 249],
-            [231, 241, 238, 249],
-            [238, 231, 239, 211, 212, 221, 220, 222, 249],
-            [239, 231, 239, 211, 212, 221, 220, 222, 249],
-            [241, 251],
-            [249, 251],
-            [251]
-        ]),
-        (3, "ACCESS_REQUEST", [
-            [320, 321, 359],
-            [321, 359],
-            [359]
-        ]),
-        (4, "NEG_REQUEST", [
-            [420, 421, 459],
-            [421, 459],
-            [459]
-        ])
-    )
-
-    TICKET_STATUSES_NAMES = {
-        111: "NEW",
-        110: "REOPENED",
-        121: "ASSIGNED",
-        131: "IN PROCESS",
-        149: "WONTFIX",
-        141: "DONE",
-        159: "DUPLICATE",
-        151: "CLOSED",
-        210: "TEMPLATE",
-        211: "BOOKED",
-        212: "ASSIGNED",
-        221: "ACCEPTED",
-        220: "PENDING",
-        229: "DECLINED",
-        222: "PRE-START",
-        231: "PROCESS",
-        238: "PRE-FORCEMAJEUER",
-        239: "FORCEMAJEUER",
-        241: "DONE",
-        249: "CANCELLED",
-        251: "CLOSED",
-        320: "PENDING",
-        321: "ACCEPTED",
-        359: "DECLINED",
-        420: "PENDING",
-        421: "ACCEPTED",
-        459: "DECLINED"
-    }
-
-    TICKET_TYPES_CHOICES = tuple((item[0], item[1]) for item in TICKET_TYPES)
-    LIFE_CYCLE_DICT = dict((item[0], item[2]) for item in TICKET_TYPES)
+    TICKET_TYPES = T.TICKET_TYPES
+    TICKET_STATUSES_NAMES = T.TICKET_STATUSES_NAMES
+    TICKET_TYPES_CHOICES = T.TICKET_TYPES_CHOICES
+    LIFE_CYCLE_DICT = T.LIFE_CYCLE_DICT
 
     title = models.CharField(max_length=128)
     ticket_list = models.ForeignKey(TicketList, on_delete=models.CASCADE)