#!/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 . # # @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.DecimalField(max_digits=50, decimal_places=5, 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