# 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 Product(models.Model):
#     # The different colours, to use as Product.<colour>
#     BLUE = "blue"
#     GREEN = "green"
#     YELLOW = "yellow"
#     ORANGE = "orange"
#     PURPLE = "purple"
#     BLACK = "black"
#     PINK = "pink"
#     CYAN = "cyan"
# 
#     # Colour choices
#     COLOUR_CHOICES = (
#             (BLUE, "Blue"),
#             (GREEN, "Green"),
#             (YELLOW, "Yellow"),
#             (ORANGE, "Orange"),
#             (PURPLE, "Purple"),
#             (BLACK, "Black"),
#             (PINK, "Pink"),
#             (CYAN, "Cyan"),
#     )
# 
#     name = models.CharField(max_length=100,
#                             validators=[validate_product_name])
#     price = models.DecimalField(max_digits=7, decimal_places=2)
#     stock_applies = models.BooleanField()
#     minimum_stock = models.PositiveSmallIntegerField(default=0)
#     stock = models.IntegerField(default=0)
#     code = models.CharField(max_length=50, unique=True, null=True, blank=True)
#     colour = models.CharField(max_length=10,
#                               choices=COLOUR_CHOICES, default="blue")
# 
#     def __str__(self):
#         return self.name
# 
#     def clean(self):
#         validate_product_name(self.name)
#         if self.code == "":
#             self.code = None
# 
#     def save(self, *args, **kwargs):
#         if not self.pk:
#             self.full_clean()
#         return super(Product, self).save(*args, **kwargs)
# 
# class Cash(models.Model):
#     amount = models.DecimalField(max_digits=7,
#                                  decimal_places=2,
#                                  default=0)
# 
# def validate_product_name(prodname):
#     regex_string = r'^\w[\w ]*$'
#     search = re.compile(regex_string).search
#     result = bool(search(prodname))
#     if not result:
#         raise ValidationError("Please only use letters, "
#                               "numbers and underscores or spaces. "
#                               "The name cannot start with a space.")
# 
# 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)


from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.urls import reverse
from decimal import Decimal
from . import helper
from .models import Order, Product, Cash, validate_product_name, Order_Item
    price = 0

    for i in range(4):
        prod = Product.objects.create(
            stock_applies=False,
            name=str(i),
            price=Decimal(3*i))
        product_list.append(prod)
        list.append(helper.order_item_from_product(prod, order))
        price += 3*i

    order.total_price = Decimal(price)
    order.save()

    return user, list, product_list


class CashViewTestCase(TestCase):
    def setUp(self):
        self.user, _, _ = _helper()

    def test_set(self):
        self.client.login(username='test', password='pswd')
        response = self.client.get(reverse('cash', args=[5]))
        self.assertEqual(response.status_code, 200)

        cash, _ = Cash.objects.get_or_create(id=0)
        self.assertEqual(cash.amount, 5)

    def test_reset(self):

# 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 Product(models.Model):
#     # The different colours, to use as Product.<colour>
#     BLUE = "blue"
#     GREEN = "green"
#     YELLOW = "yellow"
#     ORANGE = "orange"
#     PURPLE = "purple"
#     BLACK = "black"
#     PINK = "pink"
#     CYAN = "cyan"
# 
#     # Colour choices
#     COLOUR_CHOICES = (
#             (BLUE, "Blue"),
#             (GREEN, "Green"),
#             (YELLOW, "Yellow"),
#             (ORANGE, "Orange"),
#             (PURPLE, "Purple"),
#             (BLACK, "Black"),
#             (PINK, "Pink"),
#             (CYAN, "Cyan"),
#     )
# 
#     name = models.CharField(max_length=100,
#                             validators=[validate_product_name])
#     price = models.DecimalField(max_digits=7, decimal_places=2)
#     stock_applies = models.BooleanField()
#     minimum_stock = models.PositiveSmallIntegerField(default=0)
#     stock = models.IntegerField(default=0)
#     code = models.CharField(max_length=50, unique=True, null=True, blank=True)
#     colour = models.CharField(max_length=10,
#                               choices=COLOUR_CHOICES, default="blue")
# 
#     def __str__(self):
#         return self.name
# 
#     def clean(self):
#         validate_product_name(self.name)
#         if self.code == "":
#             self.code = None
# 
#     def save(self, *args, **kwargs):
#         if not self.pk:
#             self.full_clean()
#         return super(Product, self).save(*args, **kwargs)
# 
# class Cash(models.Model):
#     amount = models.DecimalField(max_digits=7,
#                                  decimal_places=2,
#                                  default=0)
# 
# def validate_product_name(prodname):
#     regex_string = r'^\w[\w ]*$'
#     search = re.compile(regex_string).search
#     result = bool(search(prodname))
#     if not result:
#         raise ValidationError("Please only use letters, "
#                               "numbers and underscores or spaces. "
#                               "The name cannot start with a space.")
# 
# 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)


# Path: web/pos/tests.py
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.urls import reverse
from decimal import Decimal
from . import helper
from .models import Order, Product, Cash, validate_product_name, Order_Item

    price = 0

    for i in range(4):
        prod = Product.objects.create(
            stock_applies=False,
            name=str(i),
            price=Decimal(3*i))
        product_list.append(prod)
        list.append(helper.order_item_from_product(prod, order))
        price += 3*i

    order.total_price = Decimal(price)
    order.save()

    return user, list, product_list


class CashViewTestCase(TestCase):
    def setUp(self):
        self.user, _, _ = _helper()

    def test_set(self):
        self.client.login(username='test', password='pswd')
        response = self.client.get(reverse('cash', args=[5]))
        self.assertEqual(response.status_code, 200)

        cash, _ = Cash.objects.get_or_create(id=0)
        self.assertEqual(cash.amount, 5)

    def test_reset(self):

        cash, _ = Cash.objects.get_or_create(id=0)