You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
4.5 KiB
199 lines
4.5 KiB
from django.conf import settings |
|
from django.db import models |
|
from django.core.files import File |
|
from django.contrib.auth.models import User |
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
|
|
class Account(models.Model): |
|
user = models.OneToOneField( |
|
User |
|
) |
|
card_number = models.CharField( |
|
verbose_name=_('card number'), |
|
max_length=32, |
|
unique=True, |
|
blank=True, |
|
null=True, |
|
) |
|
pin = models.CharField( |
|
verbose_name=_('PIN'), |
|
max_length=32, |
|
blank=True, |
|
) |
|
daily_digest = models.BooleanField( |
|
verbose_name=_('daily digest'), |
|
default=True, |
|
) |
|
credit = models.DecimalField( |
|
verbose_name=_('credit'), |
|
max_digits=5, |
|
decimal_places=2, |
|
default=0, |
|
) |
|
debit_limit = models.DecimalField( |
|
verbose_name=_('debit limit'), |
|
max_digits=5, |
|
decimal_places=2, |
|
default=None, |
|
blank=True, |
|
null=True, |
|
) |
|
avatar = models.ImageField( |
|
verbose_name=_('avatar'), |
|
upload_to='avatars', |
|
blank=True, |
|
null=True, |
|
) |
|
|
|
def __str__(self): |
|
return self.user.username |
|
|
|
class Meta: |
|
verbose_name = _('account') |
|
verbose_name_plural = _('accounts') |
|
|
|
|
|
class ProductCategory(models.Model): |
|
name = models.CharField( |
|
verbose_name=_('name'), |
|
max_length=32, |
|
unique=True, |
|
) |
|
comment = models.CharField( |
|
verbose_name=_('comment'), |
|
max_length=128, |
|
blank=True, |
|
) |
|
|
|
def __str__(self): |
|
return '%s (%s)' % (self.name, self.comment) |
|
|
|
class Meta: |
|
verbose_name = _('product category') |
|
verbose_name_plural = _('product categories') |
|
|
|
|
|
class Product(models.Model): |
|
name = models.CharField( |
|
verbose_name=_('name'), |
|
max_length=32, |
|
unique=True, |
|
) |
|
price = models.DecimalField( |
|
verbose_name=_('price'), |
|
max_digits=5, |
|
decimal_places=2, |
|
) |
|
active = models.BooleanField( |
|
verbose_name=_('active'), |
|
default=True, |
|
) |
|
category = models.ForeignKey( |
|
ProductCategory, |
|
verbose_name=_('category'), |
|
blank=True, |
|
null=True, |
|
) |
|
image = models.ImageField( |
|
verbose_name=_('image'), |
|
upload_to='products', |
|
blank=True, |
|
null=True, |
|
) |
|
image_thumbnail = models.ImageField( |
|
verbose_name=_('image'), |
|
upload_to='products_thumb', |
|
blank=True, |
|
null=True, |
|
) |
|
|
|
def __unicode__(self): |
|
return self.name |
|
|
|
class Meta: |
|
verbose_name = _('product') |
|
verbose_name_plural = _('products') |
|
|
|
|
|
class ProductBarcode(models.Model): |
|
barcode = models.CharField( |
|
verbose_name=_('barcode'), |
|
max_length=32, |
|
unique=True, |
|
) |
|
comment = models.CharField( |
|
verbose_name=_('comment'), |
|
max_length=128, |
|
blank=True, |
|
) |
|
product = models.ForeignKey( |
|
Product, |
|
verbose_name=_('product'), |
|
) |
|
|
|
def __unicode__(self): |
|
return self.barcode |
|
|
|
class Meta: |
|
verbose_name = _('barcode') |
|
verbose_name_plural = _('barcodes') |
|
|
|
|
|
class Transaction(models.Model): |
|
account = models.ForeignKey( |
|
Account, |
|
verbose_name=_('account'), |
|
) |
|
timestamp = models.DateTimeField( |
|
verbose_name=_('timestamp'), |
|
auto_now_add=True, |
|
) |
|
subject = models.CharField( |
|
verbose_name=_('subject'), |
|
max_length=32, |
|
) |
|
description = models.TextField( |
|
verbose_name=_('description'), |
|
) |
|
amount = models.DecimalField( |
|
verbose_name=_('amount'), |
|
max_digits=5, |
|
decimal_places=2, |
|
) |
|
|
|
class Meta: |
|
verbose_name = _('transaction') |
|
verbose_name_plural = _('transactions') |
|
|
|
|
|
class SalesLogEntry(models.Model): |
|
account = models.ForeignKey( |
|
Account, |
|
verbose_name=_('account'), |
|
) |
|
product = models.ForeignKey( |
|
Product, |
|
verbose_name=_('product'), |
|
) |
|
count = models.IntegerField( |
|
verbose_name=_('count'), |
|
) |
|
unit_price = models.DecimalField( |
|
verbose_name=_('unit price'), |
|
max_digits=5, |
|
decimal_places=2, |
|
) |
|
timestamp = models.DateTimeField( |
|
verbose_name=_('timestamp'), |
|
auto_now_add=True, |
|
) |
|
|
|
def __unicode__(self): |
|
return '%dx %s - %s' % (self.count, self.product, self.account) |
|
|
|
class Meta: |
|
verbose_name = _('sales log entry') |
|
verbose_name_plural = _('sales log entries') |
|
|
|
|
|
|