# 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
    Gets the order for the current user.
    """

    usr = User.objects.get_by_natural_key(username)
    q = Order.objects.filter(user=usr, done=False)\
                     .order_by('-last_change')
    if q.count() >= 1:
        return q[0]
    else:
        return Order.objects.create(user=usr)


def order_item_from_product(product, order):
    """
    Creates an Order-Item from a given Product,
    to be added to an Order.
    """

    return Order_Item.objects.create(product=product,
                                     order=order,
                                     price=product.price,
                                     name=product.name)


def product_list_from_order(order):
    """
    Returns a list of Products that appear in an Order
    """

    product_list = []

# 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

    Gets the order for the current user.
    """

    usr = User.objects.get_by_natural_key(username)
    q = Order.objects.filter(user=usr, done=False)\
                     .order_by('-last_change')
    if q.count() >= 1:
        return q[0]
    else:
        return Order.objects.create(user=usr)


def order_item_from_product(product, order):
    """
    Creates an Order-Item from a given Product,
    to be added to an Order.
    """

    return Order_Item.objects.create(product=product,
                                     order=order,
                                     price=product.price,
                                     name=product.name)


def product_list_from_order(order):
    """
    Returns a list of Products that appear in an Order
    """

    product_list = []

    order_item_list = Order_Item.objects.filter(order=order)