summaryrefslogtreecommitdiff
path: root/inventory/models.py
blob: a65142c38dd619c4178414223bf18712c9ac979a (plain)
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# This file is part of the Taler Codeless Merchant.
# (C) 2018 GNUnet e.V.
# 
# The Taler Codeless Merchant is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
# 
# The Taler Codeless Merchant is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
# for more details.
# 
# You should have received a copy of the GNU Affero General Public License along
# with the Taler Codeless Merchant.  If not, see <https://www.gnu.org/licenses/>.
#
# @author Shivam Kohli


from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver


class Merchant(models.Model):
    """ Extending the default Django User Model.
    This will hold a One-To-One relationship with the existing User Model.
    """
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    address = models.TextField()
    pay_url = models.URLField(max_length=250, default='NULL')
    website = models.URLField(max_length=250, default='NULL')


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


class Product(models.Model):
    """ The details of the product is described in this table.
    This table tracks the inventory of the product.
    """
    product_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=50, blank=True, null=True)
    description = models.CharField(max_length=300, blank=True, null=True)
    price = models.CharField(max_length=50, blank=True, null=True)
    delivery_date = models.DateTimeField(auto_now=True)
    starting_inventory = models.IntegerField(blank=True, null=True)
    minimum_required = models.IntegerField(blank=True, null=True)
    # inventory_on_hand is updated by purchase and outgoing orders.
    inventory_on_hand = models.IntegerField(blank=True, null=True)
    inventory_recieved = models.IntegerField(blank=True, null=True)
    inventory_shipped = models.IntegerField(blank=True, null=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    document = models.FileField(upload_to='document/')

    def __str__(self):
        return self.name


@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
    """ Hooking the create_user_profile method to
    the User model, whenever a save event occurs
    """
    if created:
        Merchant.objects.create(user=instance)


# @receiver(post_save, sender=User)
# def save_user_profile(sender, instance, **kwargs):
#     """ Hooking the save_user_profile method to
#     the User model, whenever a save event occurs
#     """
#     instance.Merchant.save()


class Order(models.Model):
    """ Details of the order customer buys is updated in this table.
    These details will be used to make request to the Merchant Backend API
    """
    order_id = models.CharField(max_length=300, blank=True, null=True)
    uid = models.AutoField(primary_key=True)
    product_id = models.ManyToManyField(Product, blank=True)
    summary = models.CharField(max_length=300, blank=True, null=True)
    order_date = models.DateTimeField(auto_now=True)
    address = models.CharField(max_length=250, blank=True, null=True)
    merchant = models.ForeignKey(User, on_delete=models.CASCADE)
    status = models.CharField(max_length=50, blank=True, null=True)

    def __str__(self):
        return self.summary


class Purchase(models.Model):
    """ To keep a track of the purchases the merchant makes.
    This table is essential to update the inverntory in hand.
    """
    purchase_id = models.AutoField(primary_key=True)
    product_id = models.ManyToManyField(Product, null=True)
    description = models.CharField(max_length=300, blank=True, null=True)
    purchase_date = models.DateTimeField(auto_now=True)
    product_recieved = models.IntegerField(blank=True, null=True)
    supplier = models.CharField(max_length=50, blank=True, null=True)

    def __str__(self):
        return self.description


class PaymentButton(models.Model):
    """ Design pattern for the payment button are stored in this table. """
    product = models.ForeignKey(Product, on_delete=models.CASCADE, null=True)
    text = models.CharField(max_length=100, blank=True, null=True)
    font_size = models.CharField(max_length=50, blank=True, null=True)
    color = models.CharField(max_length=50, blank=True, null=True)
    background_color = models.CharField(max_length=50, blank=True, null=True)
    border_radius = models.CharField(max_length=50, blank=True, null=True)

    def __str__(self):
        return self.text