Fakultas Ilmu Komputer UI

models.py 23.1 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
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'))
56
    bank_code_number = db_models.CharField(max_length=100, verbose_name=_('bank code number'), default='000')
WILLIAM GATES's avatar
WILLIAM GATES committed
57
58
59
60
61
62
63
64
65
66
    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):
67
        return '{}: {} - {}'.format(self.bank_name, self.bank_code_number, self.bank_account_number)
WILLIAM GATES's avatar
WILLIAM GATES committed
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
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
137
   
138
139
    modal = db_models.DecimalField(
        decimal_places=2,
140
        default=decimal.Decimal('0'),
141
142
143
144
145
146
147
148
149
150
151
152
        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')
    )
153
154
155
156
157
158
    image = db_models.ImageField(
        blank=True,
        null=True,
        upload_to=utils.get_upload_file_path,
        verbose_name=_('image')
    )
159
    total_profit = db_models.DecimalField(
160
161
162
163
164
165
166
167
        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')
    )
168
    unit = db_models.CharField(default='buah', max_length=200, verbose_name=_('unit'))
169
170
171
172
173
174
175
    preorder = db_models.BooleanField(blank=True, null=True, default=False, verbose_name=_('preorder'))
    preorder_duration = db_models.PositiveIntegerField(
        blank=True,
        null=True,
        default=0,
        verbose_name=_('preorder duration')
    )
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
    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
261
        blank=True,
262
263
        decimal_places=2,
        max_digits=12,
WILLIAM GATES's avatar
WILLIAM GATES committed
264
        null=True,
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
        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
291
292
293
294
295
296
    user_bank_name = db_models.CharField(
        blank=True,
        max_length=100,
        null=True,
        verbose_name=_('user bank name')
    )
297
298
299
300
301
302
    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
303
304
305
306
307
308
309
310
    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(
311
312
313
        blank=True,
        max_length=100,
        null=True,
WILLIAM GATES's avatar
WILLIAM GATES committed
314
315
316
317
318
319
320
321
322
323
324
325
326
        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')
327
    )
328
329
330
331
332
333
    transfer_destination_bank_code_number = db_models.CharField(
        blank=True,
        max_length=100,
        null=True,
        verbose_name=_('transfer destination bank code number')
    )
334
335
336
337
338
339
340
    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'))

341
    batch = db_models.ForeignKey(
inez nabila's avatar
inez nabila committed
342
343
344
345
346
347
        'api.Batch',
        null=True,
        blank=True,
        on_delete=db_models.CASCADE,
        related_name='transaction',
        verbose_name=_('batch')
348
        )
349
350

    batch_name = db_models.CharField(max_length=200, verbose_name=_('batch name'))
351
352
353
354
355

    end_date = db_models.DateField(
        null=True,
        verbose_name=_('end date')
    )
inez nabila's avatar
inez nabila committed
356
 
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
    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
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
    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
428
429
430
431
432
433
434
435
    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')
    )
436
437
438
439
440
441
    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
442
    link = db_models.URLField(blank=True, null=True, verbose_name=_('link'))
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

    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
461
462
    program = db_models.ForeignKey(
        'api.Program',
463
464
465
        null=True,
        on_delete=db_models.SET_NULL,
        related_name='program_donations',
WILLIAM GATES's avatar
WILLIAM GATES committed
466
        verbose_name=_('program')
467
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
468
469
    user = db_models.ForeignKey(
        'api.User',
470
471
472
        null=True,
        on_delete=db_models.SET_NULL,
        related_name='program_donations',
WILLIAM GATES's avatar
WILLIAM GATES committed
473
        verbose_name=_('user')
474
475
476
477
478
    )
    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(
479
480
        blank=True,
        null=True,
481
482
483
484
485
486
487
488
489
490
491
        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')
    )
492
493
494
495
496
497
    donation_type = db_models.CharField(
        choices=constants.DONATION_TYPE_CHOICES,
        default='CSH',
        max_length=3,
        verbose_name=_('donation type')
    )
498
    proof_of_bank_transfer = db_models.ImageField(
499
500
        blank=True,
        null=True,
501
502
503
        upload_to=utils.get_upload_file_path,
        verbose_name=_('proof of bank transfer')
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
504
505
506
    user_bank_name = db_models.CharField(
        blank=True,
        null=True,
507
        max_length=100,
WILLIAM GATES's avatar
WILLIAM GATES committed
508
509
        verbose_name=_('user bank name')
    )
510
    user_bank_account_name = db_models.CharField(
511
512
        blank=True,
        null=True,
513
514
515
        max_length=200,
        verbose_name=_('user bank account name')
    )
WILLIAM GATES's avatar
WILLIAM GATES committed
516
517
    bank_account_transfer_destination = db_models.ForeignKey(
        'api.BankAccountTransferDestination',
518
        blank=True,
WILLIAM GATES's avatar
WILLIAM GATES committed
519
520
521
522
523
524
525
526
        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,
527
        max_length=100,
WILLIAM GATES's avatar
WILLIAM GATES committed
528
529
530
531
532
        verbose_name=_('transfer destination bank name')
    )
    transfer_destination_bank_account_name = db_models.CharField(
        blank=True,
        null=True,
533
        max_length=200,
WILLIAM GATES's avatar
WILLIAM GATES committed
534
535
536
537
538
        verbose_name=_('transfer destination bank account name')
    )
    transfer_destination_bank_account_number = db_models.CharField(
        blank=True,
        null=True,
539
        max_length=100,
WILLIAM GATES's avatar
WILLIAM GATES committed
540
        verbose_name=_('transfer destination bank account number')
541
    )
542
543
544
545
546
547
    transfer_destination_bank_code_number = db_models.CharField(
        blank=True,
        null=True,
        max_length=100,
        verbose_name=_('transfer destination bank code number')
    )
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
    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')
    )
575
576
577
578
579
580
581
582
    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
583
        ordering = ['-updated_at', '-created_at', 'program', 'donation_number', 'id']
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
        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
602
603
class HelpContactConfig(solo_models.SingletonModel):
    email = db_models.EmailField(verbose_name=_('email'))
604
605

    class Meta:
WILLIAM GATES's avatar
WILLIAM GATES committed
606
607
        verbose_name = _('help contact configuration')
        verbose_name_plural = _('help contact configurations')
608
609

    def __str__(self):
WILLIAM GATES's avatar
WILLIAM GATES committed
610
        return 'Help Contact Configuration'
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
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
659

660

661
662
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
663

664
665
    batch_name = db_models.CharField(max_length=200, verbose_name=_('name'))

666
    start_date = db_models.DateField(
667
        blank=False,
668
        verbose_name=_('start date')
669
    )
670
    end_date = db_models.DateField(
671
        blank=False,
672
        verbose_name=_('end date')
673
674
675
    )

    shipping_cost = db_models.IntegerField(
676
        blank=True,
677
678
        verbose_name=_('shipping cost'),
        null=True
679
680
681
    )

    class Meta:
682
        ordering = ['-start_date', '-end_date', 'batch_name', 'id']
683
684
        verbose_name = _('batch')
        verbose_name_plural = _('batches')
inez nabila's avatar
inez nabila committed
685

686
    def __str__(self):
687
        return self.batch_name
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714

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
715
        return self.name