-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathmodels.py
321 lines (265 loc) · 11.2 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.translation import gettext_lazy as _
class Product(models.Model):
CATEGORY_CHOICES = (
("tiny", "tiny"),
("small", "small"),
("medium", "medium"),
("big", "big"),
)
slug = models.CharField(max_length=200, verbose_name=_("Slug"))
name = models.CharField(max_length=200, verbose_name=_("Name"))
sku = models.CharField(max_length=200, default="", blank=True)
category = models.CharField(max_length=10, choices=CATEGORY_CHOICES)
notes = models.TextField()
class Meta:
verbose_name = _("Product")
verbose_name_plural = _("Products")
class ProductCustomID(models.Model):
CATEGORY_CHOICES = (
("tiny", "tiny"),
("small", "small"),
("medium", "medium"),
("big", "big"),
)
hash = models.AutoField(primary_key=True)
slug = models.CharField(max_length=200, verbose_name=_("Slug"))
name = models.CharField(max_length=200, verbose_name=_("Name"))
sku = models.CharField(max_length=200, default="", blank=True)
category = models.CharField(max_length=10, choices=CATEGORY_CHOICES)
notes = models.TextField()
class Meta:
verbose_name = _("Product")
verbose_name_plural = _("Products")
class Agent(models.Model):
name = models.CharField(max_length=200, verbose_name=_("Name"))
class Contact(models.Model):
address = models.CharField(max_length=200, verbose_name=_("Name"))
po_box = models.CharField(
max_length=200, verbose_name=_("po_box"), null=True, blank=True
)
agent = models.ForeignKey(Agent, on_delete=models.CASCADE)
class Client(models.Model):
class SexChoices(models.TextChoices):
FEMALE = "FEMALE", _("Female")
MALE = "MALE", _("Male")
OTHER = "OTHER", _("Other")
slug = models.CharField(max_length=200, verbose_name=_("Client Slug"))
name = models.CharField(max_length=200, verbose_name=_("Name"), unique=True)
email = models.EmailField(blank=True)
notes = models.TextField()
contact = models.ForeignKey(Contact, on_delete=models.CASCADE, null=True)
sex = models.CharField(max_length=10, choices=SexChoices.choices, default="OTHER")
class Meta:
verbose_name = _("Client")
verbose_name_plural = _("Clients")
class SimpleSales(models.Model):
slug = models.SlugField()
doc_date = models.DateTimeField(_("date"), db_index=True)
client = models.ForeignKey(Client, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.DecimalField(
_("quantity"), max_digits=19, decimal_places=2, default=0
)
price = models.DecimalField(_("price"), max_digits=19, decimal_places=2, default=0)
value = models.DecimalField(_("value"), max_digits=19, decimal_places=2, default=0)
created_at = models.DateTimeField(null=True, verbose_name=_("Created at"))
flag = models.CharField(max_length=50, default="sales")
content_type = models.ForeignKey(
ContentType, on_delete=models.DO_NOTHING, null=True
)
object_id = models.PositiveIntegerField(null=True)
content_object = GenericForeignKey("content_type", "object_id")
def save(
self, force_insert=False, force_update=False, using=None, update_fields=None
):
self.value = self.quantity * self.price
super().save(force_insert, force_update, using, update_fields)
class Meta:
verbose_name = _("Sale")
verbose_name_plural = _("Sales")
ordering = ["-created_at"]
class SimpleSales2(models.Model):
slug = models.SlugField()
doc_date = models.DateTimeField(_("date"), db_index=True)
client = models.ForeignKey(Client, on_delete=models.CASCADE, to_field="name")
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.DecimalField(
_("quantity"), max_digits=19, decimal_places=2, default=0
)
price = models.DecimalField(_("price"), max_digits=19, decimal_places=2, default=0)
value = models.DecimalField(_("value"), max_digits=19, decimal_places=2, default=0)
created_at = models.DateTimeField(null=True, verbose_name=_("Created at"))
flag = models.CharField(max_length=50, default="sales")
content_type = models.ForeignKey(
ContentType, on_delete=models.DO_NOTHING, null=True
)
object_id = models.PositiveIntegerField(null=True)
content_object = GenericForeignKey("content_type", "object_id")
def save(
self, force_insert=False, force_update=False, using=None, update_fields=None
):
self.value = self.quantity * self.price
super().save(force_insert, force_update, using, update_fields)
class Meta:
verbose_name = _("Sale")
verbose_name_plural = _("Sales")
ordering = ["-created_at"]
class SalesProductWithCustomID(models.Model):
slug = models.SlugField()
doc_date = models.DateTimeField(_("date"), db_index=True)
client = models.ForeignKey(Client, on_delete=models.CASCADE)
product = models.ForeignKey(ProductCustomID, on_delete=models.CASCADE)
quantity = models.DecimalField(
_("quantity"), max_digits=19, decimal_places=2, default=0
)
price = models.DecimalField(_("price"), max_digits=19, decimal_places=2, default=0)
value = models.DecimalField(_("value"), max_digits=19, decimal_places=2, default=0)
created_at = models.DateTimeField(null=True, verbose_name=_("Created at"))
flag = models.CharField(max_length=50, default="sales")
content_type = models.ForeignKey(
ContentType, on_delete=models.DO_NOTHING, null=True
)
object_id = models.PositiveIntegerField(null=True)
content_object = GenericForeignKey("content_type", "object_id")
def save(
self, force_insert=False, force_update=False, using=None, update_fields=None
):
self.value = self.quantity * self.price
super().save(force_insert, force_update, using, update_fields)
class Meta:
verbose_name = _("Sale")
verbose_name_plural = _("Sales")
ordering = ["-created_at"]
class SalesWithFlag(models.Model):
slug = models.SlugField()
doc_date = models.DateTimeField(_("date"), db_index=True)
client = models.ForeignKey(Client, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.DecimalField(
_("quantity"), max_digits=19, decimal_places=2, default=0
)
price = models.DecimalField(_("price"), max_digits=19, decimal_places=2, default=0)
value = models.DecimalField(_("value"), max_digits=19, decimal_places=2, default=0)
created_at = models.DateTimeField(null=True, verbose_name=_("Created at"))
flag = models.CharField(max_length=50, default="sales")
def save(
self, force_insert=False, force_update=False, using=None, update_fields=None
):
self.value = self.quantity * self.price
super().save(force_insert, force_update, using, update_fields)
class Meta:
verbose_name = _("Sale")
verbose_name_plural = _("Sales")
ordering = ["-created_at"]
class UserJoined(models.Model):
username = models.CharField(max_length=255)
date_joined = models.DateField()
class TaxCode(models.Model):
name = models.CharField(max_length=255)
tax = models.DecimalField(_("tax"), max_digits=19, decimal_places=2, default=0)
class ComplexSales(models.Model):
tax = models.ManyToManyField(TaxCode)
slug = models.SlugField()
doc_date = models.DateTimeField(_("date"), db_index=True)
client = models.ForeignKey(Client, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.DecimalField(
_("quantity"), max_digits=19, decimal_places=2, default=0
)
price = models.DecimalField(_("price"), max_digits=19, decimal_places=2, default=0)
value = models.DecimalField(_("value"), max_digits=19, decimal_places=2, default=0)
created_at = models.DateTimeField(null=True, verbose_name=_("Created at"))
flag = models.CharField(max_length=50, default="sales")
content_type = models.ForeignKey(
ContentType, on_delete=models.DO_NOTHING, null=True
)
object_id = models.PositiveIntegerField(null=True)
content_object = GenericForeignKey("content_type", "object_id")
def save(
self, force_insert=False, force_update=False, using=None, update_fields=None
):
self.value = self.quantity * self.price
super().save(force_insert, force_update, using, update_fields)
class Meta:
verbose_name = _("VAT Sale")
verbose_name_plural = _("VAT Sales")
ordering = ["-created_at"]
#
# class Invoice(BaseMovementInfo):
# client = models.ForeignKey(Client, on_delete=models.CASCADE)
#
# @classmethod
# def get_doc_type(cls):
# return 'sales'
#
#
# class InvoiceLine(QuanValueMovementItem):
# invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE)
#
# product = models.ForeignKey(Product, on_delete=models.CASCADE)
# client = models.ForeignKey(Client, on_delete=models.CASCADE)
#
# @classmethod
# def get_doc_type(cls):
# return 'sales'
#
#
# class Journal(BaseMovementInfo):
# data = models.CharField(max_length=100, null=True, blank=True)
#
# @classmethod
# def get_doc_type(cls):
# return 'journal-sales'
#
#
# class JournalItem(BaseMovementItemInfo):
# journal = models.ForeignKey(Journal, on_delete=models.CASCADE)
# client = models.ForeignKey(Client, on_delete=models.CASCADE)
# data = models.CharField(max_length=100, null=True, blank=True)
#
# @classmethod
# def get_doc_type(cls):
# return 'journal-sales'
#
#
# class JournalWithCriteria(Journal):
# class Meta:
# proxy = True
#
# Vanilla models
class Order(models.Model):
date_placed = models.DateTimeField(auto_created=True)
client = models.ForeignKey(Client, null=True, on_delete=models.CASCADE)
class OrderLine(models.Model):
date_placed = models.DateTimeField(auto_created=True)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
order = models.ForeignKey(Order, on_delete=models.CASCADE)
quantity = models.PositiveIntegerField(default=0)
client = models.ForeignKey(Client, null=True, on_delete=models.CASCADE)
class Architect(models.Model):
"""A lookup table for CX Enterprise Architects, used mostly for reporting purposes. Associated with Initiatives and Features."""
id = models.AutoField(primary_key=True)
name = models.CharField(
max_length=60,
verbose_name="Lead Architect",
null=False,
unique=True,
blank=False,
db_index=True,
)
class Initiative(models.Model):
id = models.AutoField(primary_key=True)
# cx_pem = models.ForeignKey(ProjectEngineeringManager, on_delete=models.DO_NOTHING,
# verbose_name="CX PEM:", null=True,
# blank=True)
architect = models.ForeignKey(
Architect,
on_delete=models.DO_NOTHING,
verbose_name="CX Architect:",
null=True,
blank=True,
to_field="name",
)