Fakultas Ilmu Komputer UI

models.py 22.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import decimal
import uuid

from django.contrib.auth import models as auth_models
from django.contrib.postgres import fields
from django.core import validators
from django.db import models as db_models
from django.utils.translation import gettext_lazy as _
from phonenumber_field import modelfields
from solo import models as solo_models

from api import constants, utils


class User(auth_models.AbstractUser):
inez nabila's avatar
inez nabila committed
16
    REQUIRED_FIELDS = ['phone_number']
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
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    first_name = None
    last_name = None
    full_name = db_models.CharField(max_length=200, verbose_name=_('full name'))
    phone_number = modelfields.PhoneNumberField(unique=True, verbose_name=_('phone number'))
    address = db_models.CharField(max_length=200, verbose_name=_('address'))
    neighborhood = db_models.CharField(
        max_length=3,
        validators=[validators.int_list_validator(sep=''), validators.MinLengthValidator(3)],
        verbose_name=_('neighborhood')
    )
    hamlet = db_models.CharField(
        max_length=3,
        validators=[validators.int_list_validator(sep=''), validators.MinLengthValidator(3)],
        verbose_name=_('hamlet')
    )
    urban_village = db_models.CharField(max_length=100, verbose_name=_('urban village'))
    sub_district = db_models.CharField(max_length=100, verbose_name=_('sub-district'))
    profile_picture = db_models.ImageField(
        blank=True,
        null=True,
        upload_to=utils.get_upload_file_path,
        verbose_name=_('profile picture')
    )
    otp = db_models.CharField(blank=True, max_length=6, null=True, verbose_name=_('OTP'))

    class Meta:
        ordering = ['username', 'id']
        verbose_name = _('user')
        verbose_name_plural = _('users')

    def __str__(self):
        return self.username


WILLIAM GATES's avatar
WILLIAM GATES committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class BankAccountTransferDestination(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    bank_name = db_models.CharField(max_length=100, verbose_name=_('bank name'))
    bank_account_number = db_models.CharField(max_length=100, verbose_name=_('bank account number'))
    bank_account_name = db_models.CharField(max_length=200, verbose_name=_('bank account name'))

    class Meta:
        ordering = ['bank_name', 'id']
        unique_together = ['bank_name', 'bank_account_number']
        verbose_name = _('bank account transfer destination')
        verbose_name_plural = _('bank account transfer destinations')

    def __str__(self):
        return '{} - {}'.format(self.bank_name, self.bank_account_number)


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
class Category(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    name = fields.CICharField(max_length=50, unique=True, verbose_name=_('name'))
    image = db_models.ImageField(
        blank=True,
        null=True,
        upload_to=utils.get_upload_file_path,
        verbose_name=_('image')
    )

    class Meta:
        ordering = ['name', 'id']
        verbose_name = _('category')
        verbose_name_plural = _('categories')

    def __str__(self):
        return self.name


class Subcategory(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    name = fields.CICharField(max_length=50, unique=True, verbose_name=_('name'))
    category = db_models.ForeignKey(
        'api.Category',
        on_delete=db_models.CASCADE,
        related_name='subcategories',
        verbose_name=_('category')
    )
    image = db_models.ImageField(
        blank=True,
        null=True,
        upload_to=utils.get_upload_file_path,
        verbose_name=_('image')
    )

    class Meta:
        ordering = ['category', 'name', 'id']
        verbose_name = _('subcategory')
        verbose_name_plural = _('subcategories')

    def __str__(self):
        return self.name


class Product(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    code = db_models.CharField(
        default=utils.generate_code,
        max_length=6,
        unique=True,
        verbose_name=_('code')
    )
    name = db_models.CharField(max_length=200, verbose_name=_('name'))
    subcategory = db_models.ForeignKey(
        'api.Subcategory',
        on_delete=db_models.PROTECT,
        related_name='products',
        verbose_name=_('subcategory')
    )
    description = db_models.TextField(verbose_name=_('description'))
    price = db_models.DecimalField(
        decimal_places=2,
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
        verbose_name=_('price')
    )
    stock = db_models.PositiveIntegerField(blank=True, null=True, verbose_name=_('stock'))
Rayhan Muzakki's avatar
Rayhan Muzakki committed
136
   
137
138
    modal = db_models.DecimalField(
        decimal_places=2,
139
        default=decimal.Decimal('0'),
140
141
142
143
144
145
146
147
148
149
150
151
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
        verbose_name=_('modal')
    )
    profit= db_models.DecimalField(
        blank=True,
        null=True,
        decimal_places=2,
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
        verbose_name=_('profit')
    )
152
153
154
155
156
157
    image = db_models.ImageField(
        blank=True,
        null=True,
        upload_to=utils.get_upload_file_path,
        verbose_name=_('image')
    )
158
159
160
161
162
163
164
165
166
    total_profit= db_models.DecimalField(
        blank=True,
        null=True,
        default=decimal.Decimal('0'),
        decimal_places=2,
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
        verbose_name=_('total profit')
    )
Azhar Difa Arnanda's avatar
Dev    
Azhar Difa Arnanda committed
167
    unit = db_models.CharField(default='buah', max_length=200, verbose_name=_('unit'))
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
    class Meta:
        ordering = ['subcategory', 'name', 'code', 'id']
        verbose_name = _('product')
        verbose_name_plural = _('products')

    def __str__(self):
        return self.code


class ShoppingCart(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    user = db_models.OneToOneField('api.User', on_delete=db_models.CASCADE, verbose_name=_('user'))

    class Meta:
        ordering = ['user', 'id']
        verbose_name = _('shopping cart')
        verbose_name_plural = _('shopping carts')

    def __str__(self):
        return self.user.username


class CartItem(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    shopping_cart = db_models.ForeignKey(
        'api.ShoppingCart',
        on_delete=db_models.CASCADE,
        related_name='cart_items',
        verbose_name=_('shopping cart')
    )
    product = db_models.ForeignKey(
        'api.Product',
        on_delete=db_models.CASCADE,
        related_name='cart_items',
        verbose_name=_('product')
    )
    quantity = db_models.PositiveIntegerField(default=0, verbose_name=_('quantity'))

    class Meta:
        ordering = ['shopping_cart', 'product', 'id']
        unique_together = ['shopping_cart', 'product']
        verbose_name = _('cart item')
        verbose_name_plural = _('cart items')

    def __str__(self):
        return self.product.code


class Transaction(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    transaction_number = db_models.CharField(
        default=utils.generate_transaction_number,
        max_length=8,
        unique=True,
        verbose_name=_('transaction number')
    )
    user = db_models.ForeignKey(
        'api.User',
        null=True,
        on_delete=db_models.SET_NULL,
        related_name='transactions',
        verbose_name=_('user')
    )
    user_full_name = db_models.CharField(max_length=200, verbose_name=_('user full name'))
    user_phone_number = modelfields.PhoneNumberField(verbose_name=_('user phone number'))
    shipping_address = db_models.CharField(max_length=200, verbose_name=_('shipping address'))
    shipping_neighborhood = db_models.CharField(
        max_length=3,
        validators=[validators.int_list_validator(sep=''), validators.MinLengthValidator(3)],
        verbose_name=_('shipping neighborhood')
    )
    shipping_hamlet = db_models.CharField(
        max_length=3,
        validators=[validators.int_list_validator(sep=''), validators.MinLengthValidator(3)],
        verbose_name=_('shipping hamlet')
    )
    shipping_urban_village = db_models.CharField(
        max_length=100,
        verbose_name=_('shipping urban village')
    )
    shipping_sub_district = db_models.CharField(
        max_length=100,
        verbose_name=_('shipping sub-district')
    )
    shipping_costs = db_models.DecimalField(
WILLIAM GATES's avatar
WILLIAM GATES committed
253
        blank=True,
254
255
        decimal_places=2,
        max_digits=12,
WILLIAM GATES's avatar
WILLIAM GATES committed
256
        null=True,
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
        validators=[validators.MinValueValidator(decimal.Decimal('0'))],
        verbose_name=_('shipping costs')
    )
    payment_method = db_models.CharField(
        choices=constants.PAYMENT_METHOD_CHOICES,
        max_length=3,
        verbose_name=_('payment method')
    )
    donation = db_models.DecimalField(
        decimal_places=2,
        default=decimal.Decimal('0'),
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0'))],
        verbose_name=_('donation')
    )
    transaction_status = db_models.CharField(
        choices=constants.TRANSACTION_STATUS_CHOICES,
        max_length=3,
        verbose_name=_('transaction status')
    )
    proof_of_payment = db_models.ImageField(
        blank=True,
        null=True,
        upload_to=utils.get_upload_file_path,
        verbose_name=_('proof of payment')
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
283
284
285
286
287
288
    user_bank_name = db_models.CharField(
        blank=True,
        max_length=100,
        null=True,
        verbose_name=_('user bank name')
    )
289
290
291
292
293
294
    user_bank_account_name = db_models.CharField(
        blank=True,
        max_length=200,
        null=True,
        verbose_name=_('user bank account name')
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
295
296
297
298
299
300
301
302
    bank_account_transfer_destination = db_models.ForeignKey(
        'api.BankAccountTransferDestination',
        null=True,
        on_delete=db_models.SET_NULL,
        related_name='transactions',
        verbose_name=_('bank account transfer destination')
    )
    transfer_destination_bank_name = db_models.CharField(
303
304
305
        blank=True,
        max_length=100,
        null=True,
WILLIAM GATES's avatar
WILLIAM GATES committed
306
307
308
309
310
311
312
313
314
315
316
317
318
        verbose_name=_('transfer destination bank name')
    )
    transfer_destination_bank_account_name = db_models.CharField(
        blank=True,
        max_length=200,
        null=True,
        verbose_name=_('transfer destination bank account name')
    )
    transfer_destination_bank_account_number = db_models.CharField(
        blank=True,
        max_length=100,
        null=True,
        verbose_name=_('transfer destination bank account number')
319
320
321
322
323
324
325
326
    )
    created_at = db_models.DateTimeField(
        auto_now_add=True,
        db_index=True,
        verbose_name=_('created at')
    )
    updated_at = db_models.DateTimeField(auto_now=True, db_index=True, verbose_name=_('updated at'))

327
    batch = db_models.ForeignKey(
inez nabila's avatar
inez nabila committed
328
329
330
331
332
333
        'api.Batch',
        null=True,
        blank=True,
        on_delete=db_models.CASCADE,
        related_name='transaction',
        verbose_name=_('batch')
334
        )
335
336

    batch_name = db_models.CharField(max_length=200, verbose_name=_('batch name'))
337
338
339
340
341

    end_date = db_models.DateField(
        null=True,
        verbose_name=_('end date')
    )
inez nabila's avatar
inez nabila committed
342
 
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
    class Meta:
        ordering = ['-updated_at', '-created_at', 'transaction_number', 'id']
        verbose_name = _('transaction')
        verbose_name_plural = _('transactions')

    def __str__(self):
        return self.transaction_number


class TransactionItem(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    transaction = db_models.ForeignKey(
        'api.Transaction',
        on_delete=db_models.CASCADE,
        related_name='transaction_items',
        verbose_name=_('transaction')
    )
    product = db_models.ForeignKey(
        'api.Product',
        null=True,
        on_delete=db_models.SET_NULL,
        related_name='transaction_items',
        verbose_name=_('product')
    )
    product_name = db_models.CharField(max_length=200, verbose_name=_('product name'))
    product_price = db_models.DecimalField(
        decimal_places=2,
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
        verbose_name=_('product price')
    )
Rayhan Muzakki's avatar
Rayhan Muzakki committed
374
    
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
    quantity = db_models.PositiveIntegerField(verbose_name=_('quantity'))

    class Meta:
        ordering = ['transaction', 'product', 'id']
        verbose_name = _('transaction item')
        verbose_name_plural = _('transaction items')

    def __str__(self):
        return self.product_name


class Program(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    code = db_models.CharField(
        default=utils.generate_code,
        max_length=6,
        unique=True,
        verbose_name=_('code')
    )
    name = db_models.CharField(max_length=200, verbose_name=_('name'))
    description = db_models.TextField(verbose_name=_('description'))
    start_date_time = db_models.DateTimeField(
        blank=True,
        db_index=True,
        null=True,
        verbose_name=_('start date and time')
    )
    end_date_time = db_models.DateTimeField(
        blank=True,
        null=True,
        verbose_name=_('end date and time')
    )
    location = db_models.CharField(
        blank=True,
        max_length=200,
        null=True,
        verbose_name=_('location')
    )
    speaker = db_models.CharField(blank=True, max_length=200, null=True, verbose_name=_('speaker'))
WILLIAM GATES's avatar
WILLIAM GATES committed
414
415
416
417
418
419
420
421
    open_donation = db_models.BooleanField(default=True, verbose_name=_('open for donation'))
    program_minutes = db_models.FileField(
        blank=True,
        null=True,
        upload_to=utils.get_upload_file_path,
        validators=[validators.FileExtensionValidator(allowed_extensions=['pdf'])],
        verbose_name=_('program minutes')
    )
422
423
424
425
426
427
    poster_image = db_models.ImageField(
        blank=True,
        null=True,
        upload_to=utils.get_upload_file_path,
        verbose_name=_('poster image')
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
428
    link = db_models.URLField(blank=True, null=True, verbose_name=_('link'))
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446

    class Meta:
        ordering = ['-start_date_time', '-end_date_time', 'name', 'code', 'id']
        verbose_name = _('program')
        verbose_name_plural = _('programs')

    def __str__(self):
        return self.code


class ProgramDonation(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    donation_number = db_models.CharField(
        default=utils.generate_donation_number,
        max_length=6,
        unique=True,
        verbose_name=_('donation number')
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
447
448
    program = db_models.ForeignKey(
        'api.Program',
449
450
451
        null=True,
        on_delete=db_models.SET_NULL,
        related_name='program_donations',
WILLIAM GATES's avatar
WILLIAM GATES committed
452
        verbose_name=_('program')
453
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
454
455
    user = db_models.ForeignKey(
        'api.User',
456
457
458
        null=True,
        on_delete=db_models.SET_NULL,
        related_name='program_donations',
WILLIAM GATES's avatar
WILLIAM GATES committed
459
        verbose_name=_('user')
460
461
462
463
464
    )
    user_full_name = db_models.CharField(max_length=200, verbose_name=_('user full name'))
    user_phone_number = modelfields.PhoneNumberField(verbose_name=_('user phone number'))
    program_name = db_models.CharField(max_length=200, verbose_name=_('program name'))
    amount = db_models.DecimalField(
465
466
        blank=True,
        null=True,
467
468
469
470
471
472
473
474
475
476
477
        decimal_places=2,
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
        verbose_name=_('amount')
    )
    donation_status = db_models.CharField(
        choices=constants.DONATION_STATUS_CHOICES,
        default='001',
        max_length=3,
        verbose_name=_('donation status')
    )
478
479
480
481
482
483
    donation_type = db_models.CharField(
        choices=constants.DONATION_TYPE_CHOICES,
        default='CSH',
        max_length=3,
        verbose_name=_('donation type')
    )
484
    proof_of_bank_transfer = db_models.ImageField(
485
486
        blank=True,
        null=True,
487
488
489
        upload_to=utils.get_upload_file_path,
        verbose_name=_('proof of bank transfer')
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
490
491
492
    user_bank_name = db_models.CharField(
        blank=True,
        null=True,
493
        max_length=100,
WILLIAM GATES's avatar
WILLIAM GATES committed
494
495
        verbose_name=_('user bank name')
    )
496
    user_bank_account_name = db_models.CharField(
497
498
        blank=True,
        null=True,
499
500
501
        max_length=200,
        verbose_name=_('user bank account name')
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
502
503
    bank_account_transfer_destination = db_models.ForeignKey(
        'api.BankAccountTransferDestination',
504
        blank=True,
WILLIAM GATES's avatar
WILLIAM GATES committed
505
506
507
508
509
510
511
512
        null=True,
        on_delete=db_models.SET_NULL,
        related_name='program_donations',
        verbose_name=_('bank account transfer destination')
    )
    transfer_destination_bank_name = db_models.CharField(
        blank=True,
        null=True,
513
        max_length=100,
WILLIAM GATES's avatar
WILLIAM GATES committed
514
515
516
517
518
        verbose_name=_('transfer destination bank name')
    )
    transfer_destination_bank_account_name = db_models.CharField(
        blank=True,
        null=True,
519
        max_length=200,
WILLIAM GATES's avatar
WILLIAM GATES committed
520
521
522
523
524
        verbose_name=_('transfer destination bank account name')
    )
    transfer_destination_bank_account_number = db_models.CharField(
        blank=True,
        null=True,
525
        max_length=100,
WILLIAM GATES's avatar
WILLIAM GATES committed
526
        verbose_name=_('transfer destination bank account number')
527
    )
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
    goods_quantity = db_models.DecimalField(
        blank=True,
        null=True,
        decimal_places=0,
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('1'))],
        verbose_name=_('goods quantity')
    )
    goods_description = db_models.CharField(
        blank=True,
        null=True,
        max_length=200,
        verbose_name=_('goods description')
    )
    delivery_method = db_models.CharField(
        choices=constants.DONATION_GOODS_DELIVERY_METHOD_CHOICES,
        blank=True,
        null=True,
        max_length=3,
        verbose_name=_('goods delivery method')
    )
    delivery_address = db_models.CharField(
        blank=True,
        null=True,
        max_length=200,
        verbose_name=_('goods delivery address')
    )
555
556
557
558
559
560
561
562
    created_at = db_models.DateTimeField(
        auto_now_add=True,
        db_index=True,
        verbose_name=_('created at')
    )
    updated_at = db_models.DateTimeField(auto_now=True, db_index=True, verbose_name=_('updated at'))

    class Meta:
WILLIAM GATES's avatar
WILLIAM GATES committed
563
        ordering = ['-updated_at', '-created_at', 'program', 'donation_number', 'id']
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
        verbose_name = _('program donation')
        verbose_name_plural = _('program donations')

    def __str__(self):
        return self.donation_number


class AppConfig(solo_models.SingletonModel):
    send_sms = db_models.BooleanField(default=False, verbose_name=_('send SMS'))

    class Meta:
        verbose_name = _('application configuration')
        verbose_name_plural = _('application configurations')

    def __str__(self):
        return 'Application Configuration'


WILLIAM GATES's avatar
WILLIAM GATES committed
582
583
class HelpContactConfig(solo_models.SingletonModel):
    email = db_models.EmailField(verbose_name=_('email'))
584
585

    class Meta:
WILLIAM GATES's avatar
WILLIAM GATES committed
586
587
        verbose_name = _('help contact configuration')
        verbose_name_plural = _('help contact configurations')
588
589

    def __str__(self):
WILLIAM GATES's avatar
WILLIAM GATES committed
590
        return 'Help Contact Configuration'
591

592

593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
class ShipmentConfig(solo_models.SingletonModel):
    hamlet = db_models.CharField(
        max_length=3,
        validators=[validators.int_list_validator(sep=''), validators.MinLengthValidator(3)],
        verbose_name=_('hamlet')
    )
    urban_village = db_models.CharField(
        max_length=100,
        verbose_name=_('urban village')
    )
    sub_district = db_models.CharField(
        max_length=100,
        verbose_name=_('sub-district')
    )
    same_hamlet_costs = db_models.DecimalField(
        decimal_places=2,
        default=decimal.Decimal('0'),
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0'))],
        verbose_name=_(
            'shipping costs if the hamlet, urban village, and sub-district are the same as seller'
        )
    )
    same_urban_village_different_hamlet_costs = db_models.DecimalField(
        decimal_places=2,
        default=decimal.Decimal('0'),
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0'))],
        verbose_name=_(
            'shipping costs if the urban village and sub-district are the same as seller'
        )
    )
    same_sub_district_different_urban_village_costs = db_models.DecimalField(
        decimal_places=2,
        default=decimal.Decimal('0'),
        max_digits=12,
        validators=[validators.MinValueValidator(decimal.Decimal('0'))],
        verbose_name=_('shipping costs if the sub-district is the same as seller')
    )

    class Meta:
        verbose_name = _('shipment configuration')
        verbose_name_plural = _('shipment configurations')

    def __str__(self):
        return 'Shipment Configuration'
inez nabila's avatar
inez nabila committed
639

640

641
642
class Batch(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
inez nabila's avatar
inez nabila committed
643

644
645
    batch_name = db_models.CharField(max_length=200, verbose_name=_('name'))

646
    start_date = db_models.DateField(
647
        blank=False,
648
        verbose_name=_('start date')
649
    )
650
    end_date = db_models.DateField(
651
        blank=False,
652
        verbose_name=_('end date')
653
654
655
    )

    shipping_cost = db_models.IntegerField(
656
        blank=True,
657
658
        verbose_name=_('shipping cost'),
        null=True
659
660
661
    )

    class Meta:
662
        ordering = ['-start_date', '-end_date', 'batch_name', 'id']
663
664
        verbose_name = _('batch')
        verbose_name_plural = _('batches')
inez nabila's avatar
inez nabila committed
665

666
    def __str__(self):
667
        return self.batch_name
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694

class ProgramProgress(db_models.Model):
    id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
    date = db_models.DateField(
        blank=False,
        verbose_name=_('date')
    )
    description = fields.CICharField(max_length=200, verbose_name=_('description'))
    image = db_models.ImageField(
        blank=True,
        null=True,
        upload_to=utils.get_upload_file_path,
        verbose_name=_('image')
    )
    program = db_models.ForeignKey(
        'api.Program',
        on_delete=db_models.CASCADE,
        related_name='program',
        verbose_name=_('program')
    )

    class Meta:
        ordering = ['-date', 'id']
        verbose_name = _('program progress')
        verbose_name_plural = _('program progress')

    def __str__(self):
inez nabila's avatar
inez nabila committed
695
        return self.name