class DeliveryPack(Model): pack_id = fields.AutoField(primary_key=True) courier = ForeignKey(Courier, on_delete=CASCADE, default=None, blank=True, null=True) assign_time = fields.DateTimeField() delivery_type = fields.CharField(max_length=4, choices=Courier.COURIER_TYPE_CHOICES, default='foot') delivery_ended = fields.BooleanField(default=False) last_complete_time = fields.DateTimeField() total_weight = fields.FloatField(default=0) def orders(self): return self.order_set.all() def assign_order(self, order): order.delivery_pack = self self.total_weight += order.weight order.save() self.save() def make_order_free(self, order): if order not in self.orders(): return order.delivery_pack = None order.delivery_time = None self.total_weight -= order.weight order.save() self.save()
class Currency(models.Model): id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) iso_code = fields.CharField( verbose_name=_('ISO Code'), max_length=3, null=False, blank=False, unique=True, ) title = fields.CharField( verbose_name=_('Title'), max_length=255, null=False, blank=False, ) prefix = fields.CharField( verbose_name=_('Prefix'), max_length=255, null=False, blank=True, ) suffix = fields.CharField( verbose_name=_('Suffix'), max_length=255, null=False, blank=True, ) rate = fields.DecimalField( verbose_name=_('Conversion Rate'), max_digits=10, decimal_places=4, null=False, blank=False, default=1, ) is_active = fields.BooleanField( verbose_name=_('Is Active'), null=False, blank=False, default=True, db_index=True, ) records = models.Manager() class Meta: db_table = 'billing_currency' default_related_name = 'currencies' verbose_name = _('Currency') verbose_name_plural = _('Currencies') def __unicode__(self): return '%(id)d: %(title)s (%(iso_code)s)' % { 'id': self.id, 'iso_code': self.iso_code, 'title': self.title, }
class CartItem(models.Model): id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) cart = models.ForeignKey( Cart, related_name='items', on_delete=models.CASCADE, null=False, blank=False, ) product = models.ForeignKey( Product, related_name='items', on_delete=models.CASCADE, null=False, blank=False, ) term = fields.PositiveSmallIntegerField( verbose_name=_('Term'), null=False, blank=False, choices=Product.Payment_Terms, ) unit_price = fields.DecimalField( verbose_name=_('Unit Price'), max_digits=10, decimal_places=4, null=False, blank=False, ) quantity = fields.PositiveSmallIntegerField( verbose_name=_('Quantity'), null=False, blank=False, default=1, ) item_price = fields.DecimalField( verbose_name=_('Item Price'), max_digits=10, decimal_places=4, null=False, blank=False, ) records = models.Manager() class Meta: db_table = 'billing_cart_items' default_related_name = 'items' verbose_name = _('Cart Item') verbose_name_plural = _('Cart Items') def __unicode__(self): return str(self.id)
class Cart(models.Model): id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) user = models.ForeignKey( User, related_name='carts', null=False, blank=False, ) currency = models.ForeignKey( Currency, related_name='carts', null=False, blank=False, ) product = models.ManyToManyField( Product, through='CartItem', through_fields=('cart', 'product'), ) total_amount = fields.DecimalField( verbose_name=_('Total Amount'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) create_date = models.DateTimeField( verbose_name=_('Create Date'), null=False, blank=False, auto_now_add=True, ) update_date = models.DateTimeField( verbose_name=_('Update Date'), null=True, blank=True, auto_now=True, ) records = models.Manager() class Meta: db_table = 'billing_cart' default_related_name = 'carts' verbose_name = _('Cart') verbose_name_plural = _('Carts') def __unicode__(self): return str(self.id)
class Category(models.Model): id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) store = models.ForeignKey( Store, related_name='categories', null=False, blank=False, ) parent = models.ForeignKey( 'self', related_name='children', null=True, blank=True, ) is_active = fields.BooleanField( verbose_name=_('Is Active'), null=False, blank=False, default=True, db_index=True, ) create_date = fields.DateTimeField( verbose_name=_('Create Date'), null=False, blank=True, auto_now_add=True, ) update_date = fields.DateTimeField( verbose_name=_('Update Date'), null=True, blank=True, auto_now=True, ) records = models.Manager() class Meta: db_table = 'billing_category' default_related_name = 'categories' verbose_name = _('Category') verbose_name_plural = _('Categories') def __unicode__(self): if self.store.default_language is not None: return CategoryLang.records.get( category=self, language=self.store.default_language, ).title else: return str(self.id)
class Country(models.Model): id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) iso_code = fields.CharField( verbose_name=_('ISO Code'), max_length=2, null=False, blank=False, unique=True, ) title = fields.CharField( verbose_name=_('Title'), max_length=255, null=False, blank=False, ) default_language = models.ForeignKey( Language, related_name='countries', null=True, blank=True, ) default_currency = models.ForeignKey( Currency, related_name='countries', null=True, blank=True, ) is_active = fields.BooleanField( verbose_name=_('Is Active'), null=False, blank=False, default=True, db_index=True, ) records = models.Manager() class Meta: db_table = 'billing_country' default_related_name = 'countries' verbose_name = _('Country') verbose_name_plural = _('Countries') def __unicode__(self): return '%(id)d: %(title)s (%(iso_code)s)' % { 'id': self.id, 'iso_code': self.iso_code, 'title': self.title, }
class FileContent(models.Model): id = fields.AutoField(primary_key=True) create_time = fields.DateTimeField(default=timezone.now) file = models.ForeignKey(SomeFile, on_delete=models.CASCADE, blank=True, null=True) content = fields.TextField(blank=True, default="") def append_string(self, string: str): self.content += ('\n' + string.strip()) self.save()
class SomeFile(models.Model): id = fields.AutoField(primary_key=True) create_time = fields.DateTimeField(default=timezone.now) change_time = fields.DateTimeField(blank=True, null=True) # file will be uploaded to MEDIA_ROOT/upload file = models.FileField(upload_to='upload/', blank=True, null=True) status = fields.CharField(max_length=20, default='new', choices=STATUS) @property def file_exist(self): return Path(self.file.path).exists() if self.file else False @property def file_name(self): return self.file.path if self.file else ''
class Setting(models.Model): id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) store = models.ForeignKey( Store, related_name='settings', null=False, blank=False, ) name = fields.CharField( verbose_name=_('Name'), max_length=255, null=False, blank=False, ) value = fields.CharField( verbose_name=_('Value'), max_length=255, null=False, blank=False, ) records = SettingManager() class Meta: db_table = 'billing_setting' default_related_name = 'settings' unique_together = (('store', 'name')) verbose_name = _('Setting') verbose_name_plural = _('Settings') def __unicode__(self): return '%(id)d: %(name)s => %(value)s' % { 'id': self.id, 'name': self.name, 'value': self.value, }
class Ability(models.Model): """ Define what kind of help a participant can do ? Probably we just keep on creating it at the backend and provide them as checkboxes for the frontend. """ TYPE_OF_VERBS = [ ("F", "Fetch"), ("P", "Provide"), ("T", "Transport"), ("N", "Notify"), ] id = fields.AutoField(primary_key=True) title = fields.CharField(verbose_name="Name of ability", max_length=30) verb = fields.CharField( verbose_name="Action on the title, (eg, GET)", default="F", max_length=3, choices=TYPE_OF_VERBS, ) def __str__(self): return f"{self.get_verb_display()}-{self.title}"
class ProductPricing(models.Model): id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) product = models.ForeignKey( Product, related_name='pricing', null=False, blank=False, ) currency = models.ForeignKey( Currency, related_name='pricing', null=False, blank=False, ) onetime_setup_fee = fields.DecimalField( verbose_name=_('One Time (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) onetime = fields.DecimalField( verbose_name=_('One Time'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) onetime_cost = fields.DecimalField( verbose_name=_('One Time (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) hourly_setup_fee = fields.DecimalField( verbose_name=_('Hourly (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) hourly = fields.DecimalField( verbose_name=_('Hourly'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) hourly_cost = fields.DecimalField( verbose_name=_('Hourly (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) daily_setup_fee = fields.DecimalField( verbose_name=_('Daily (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) daily = fields.DecimalField( verbose_name=_('Daily'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) daily_cost = fields.DecimalField( verbose_name=_('Daily (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) weekly_setup_fee = fields.DecimalField( verbose_name=_('Weekly (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) weekly = fields.DecimalField( verbose_name=_('Weekly'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) weekly_cost = fields.DecimalField( verbose_name=_('Weekly (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) monthly_setup_fee = fields.DecimalField( verbose_name=_('Monthly (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) monthly = fields.DecimalField( verbose_name=_('Monthly'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) monthly_cost = fields.DecimalField( verbose_name=_('Monthly (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) quarterly_setup_fee = fields.DecimalField( verbose_name=_('Quarterly (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) quarterly = fields.DecimalField( verbose_name=_('Quarterly'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) quarterly_cost = fields.DecimalField( verbose_name=_('Quarterly (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) semi_annually_setup_fee = fields.DecimalField( verbose_name=_('Semi-Annually (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) semi_annually = fields.DecimalField( verbose_name=_('Semi-Annually'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) semi_annually_cost = fields.DecimalField( verbose_name=_('Semi-Annually (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) annually_setup_fee = fields.DecimalField( verbose_name=_('Annually (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) annually = fields.DecimalField( verbose_name=_('Annually'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) annually_cost = fields.DecimalField( verbose_name=_('Annually (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) biennially_setup_fee = fields.DecimalField( verbose_name=_('Biennially (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) biennially = fields.DecimalField( verbose_name=_('Biennially'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) biennially_cost = fields.DecimalField( verbose_name=_('Biennially (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) triennially_setup_fee = fields.DecimalField( verbose_name=_('Triennially (Setup Fee)'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) triennially = fields.DecimalField( verbose_name=_('Triennially'), max_digits=10, decimal_places=4, null=False, blank=True, default=-1, ) triennially_cost = fields.DecimalField( verbose_name=_('Triennially (Cost)'), max_digits=10, decimal_places=4, null=False, blank=True, default=0, ) records = models.Manager() class Meta: db_table = 'billing_product_pricing' default_related_name = 'pricing' unique_together = (('product', 'currency')) verbose_name = _('Product Pricing') verbose_name_plural = _('Product Pricing')
class ProductLang(models.Model): id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) product = models.ForeignKey( Product, related_name='langs', null=False, blank=False, ) language = models.ForeignKey( Language, related_name='products', null=False, blank=False, ) title = fields.CharField( verbose_name=_('Title'), max_length=255, null=False, blank=False, ) description = fields.TextField( verbose_name=_('Description'), null=False, blank=True, ) url_key = fields.CharField( verbose_name=_('URL Key'), max_length=255, null=False, blank=False, db_index=True, ) meta_title = fields.CharField( verbose_name=_('Meta Title'), max_length=255, null=False, blank=True, ) meta_description = fields.CharField( verbose_name=_('Meta Description'), max_length=255, null=False, blank=True, ) records = models.Manager() class Meta: db_table = 'billing_product_lang' default_related_name = 'langs' verbose_name = _('Product Language') verbose_name_plural = _('Product Languages') def __unicode__(self): return '%(id)d: %(lang)s => %(title)s' % { 'id': self.id, 'lang': self.language.title, 'title': self.title, }
class Product(models.Model): Payment_Types = ( (0, _('Free')), (1, _('One-Time')), (2, _('Recurring')), ) Payment_Terms = ( (0, _('One-Time')), (1, _('Hourly')), (24, _('Daily')), ) id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) store = models.ForeignKey( Store, related_name='products', null=False, blank=False, ) main_category = models.ForeignKey( Category, verbose_name=_('Main Category'), related_name='products', null=False, blank=False, ) quantity = fields.PositiveSmallIntegerField( verbose_name=_('Quantity'), null=False, blank=False, default=1, ) enable_stock_control = fields.BooleanField( verbose_name=_('Enable Stock Control'), null=False, blank=False, default=False, ) payment_types = fields.PositiveSmallIntegerField( verbose_name=_('Payment Type'), choices=Payment_Types, null=False, blank=False, default=2, ) is_active = fields.BooleanField( verbose_name=_('Is Active'), null=False, blank=False, default=True, db_index=True, ) create_date = fields.DateTimeField( verbose_name=_('Create Date'), null=False, blank=True, auto_now_add=True, ) update_date = fields.DateTimeField( verbose_name=_('Update Date'), null=True, blank=True, auto_now=True, ) category = models.ManyToManyField( 'Category', verbose_name=_('Categories'), related_name='categories', db_table='billing_product_categories', ) records = models.Manager() class Meta: db_table = 'billing_product' default_related_name = 'products' verbose_name = _('Product') verbose_name_plural = _('Products') def __unicode__(self): if self.store.default_language is not None: return ProductLang.records.get( product=self, language=self.store.default_language, ).title else: return str(self.id)
class User(AbstractBaseUser, PermissionsMixin): id = fields.AutoField( verbose_name=_('ID'), primary_key=True, ) site = models.ForeignKey( Site, related_name='users', null=True, blank=True, db_index=True, ) email = fields.EmailField( verbose_name=_('Email Address'), max_length=255, null=False, blank=False, unique=True, ) first_name = fields.CharField( verbose_name=_('First Name'), max_length=32, null=True, blank=False, ) last_name = fields.CharField( verbose_name=_('Last Name'), max_length=32, null=True, blank=False, ) is_active = fields.BooleanField( verbose_name=_('Is Active'), null=False, blank=False, default=True, db_index=True, ) create_date = fields.DateTimeField( verbose_name=_('Create Date'), null=False, blank=True, auto_now_add=True, ) update_date = fields.DateTimeField( verbose_name=_('Update Date'), null=True, blank=True, auto_now=True, ) @property def is_staff(self): return self.is_superuser USERNAME_FIELD = 'email' REQUIRED_FIELDS = [] objects = UserManager() class Meta: db_table = 'auth_user' verbose_name = _('User') verbose_name_plural = _('Users') get_latest_by = 'create_date' default_related_name = 'users' def get_short_name(self): return self.first_name if self.first_name is not None else self.email def get_full_name(self): return '{0} {1}'.format(self.first_name, self.last_name) def __str__(self): return self.email