# Path: web/pos/models.py
# class Order(models.Model):
#     user = models.ForeignKey(settings.AUTH_USER_MODEL,
#                              on_delete=models.CASCADE)
#     total_price = models.DecimalField(max_digits=10,
#                                       decimal_places=2,
#                                       default=0)
#     done = models.BooleanField(default=False)
#     last_change = models.DateTimeField(auto_now=True)
# 
#     def get_absolute_url(self):
#         return reverse('view_order', args=[self.id])
# 
# class Cash(models.Model):
#     amount = models.DecimalField(max_digits=7,
#                                  decimal_places=2,
#                                  default=0)
# 
# class Order_Item(models.Model):
#     product = models.ForeignKey(Product,
#                                 on_delete=models.CASCADE)
#     order = models.ForeignKey(Order, on_delete=models.CASCADE)
#     price = models.DecimalField(max_digits=7, decimal_places=2)
#     name = models.CharField(max_length=100)
#     timestamp = models.DateTimeField(auto_now=True)
# 
# class Setting(models.Model):
#     key = models.CharField(max_length=50)
#     value = models.CharField(max_length=100)
# 
#     def __str__(self):
#         return self.key
# 
#     def __bool__(self):
#         return bool(self.value)
# 
#     __nonzero__ = __bool__


from django.contrib.auth.models import User
from .models import Order, Cash, Order_Item, Setting


def get_currency():
    """
    Gets the current currency from the Settings database table
    """

    currency, is_created = Setting.objects.get_or_create(key="currency")

    if is_created:
        currency.value = "€"
        currency.save()

    return currency.value


def get_company():
    """
    Gets the company name from the Settings in the database
    """


# Path: web/pos/models.py
# class Order(models.Model):
#     user = models.ForeignKey(settings.AUTH_USER_MODEL,
#                              on_delete=models.CASCADE)
#     total_price = models.DecimalField(max_digits=10,
#                                       decimal_places=2,
#                                       default=0)
#     done = models.BooleanField(default=False)
#     last_change = models.DateTimeField(auto_now=True)
# 
#     def get_absolute_url(self):
#         return reverse('view_order', args=[self.id])
# 
# class Cash(models.Model):
#     amount = models.DecimalField(max_digits=7,
#                                  decimal_places=2,
#                                  default=0)
# 
# class Order_Item(models.Model):
#     product = models.ForeignKey(Product,
#                                 on_delete=models.CASCADE)
#     order = models.ForeignKey(Order, on_delete=models.CASCADE)
#     price = models.DecimalField(max_digits=7, decimal_places=2)
#     name = models.CharField(max_length=100)
#     timestamp = models.DateTimeField(auto_now=True)
# 
# class Setting(models.Model):
#     key = models.CharField(max_length=50)
#     value = models.CharField(max_length=100)
# 
#     def __str__(self):
#         return self.key
# 
#     def __bool__(self):
#         return bool(self.value)
# 
#     __nonzero__ = __bool__


# Path: web/pos/helper.py
from django.contrib.auth.models import User
from .models import Order, Cash, Order_Item, Setting



def get_currency():
    """
    Gets the current currency from the Settings database table
    """

    currency, is_created = Setting.objects.get_or_create(key="currency")

    if is_created:
        currency.value = "€"
        currency.save()

    return currency.value


def get_company():
    """
    Gets the company name from the Settings in the database
    """


    company, is_created = Setting.objects.get_or_create(key="company")