Exemplo n.º 1
0
    def test_verbose_availability_with_stock_3(self):
        OrderRoundFactory()
        product = ProductFactory(order_round=None)
        stock1 = ProductStockFactory(product=product, type=ProductStock.TYPE_ADDED)
        stock2 = ProductStockFactory(product=product, type=ProductStock.TYPE_ADDED)
        odp1 = OrderProductFactory(product=product, amount=1, order__paid=True)

        self.assertEqual(product.verbose_availability(), "%s in voorraad" % ((stock1.amount + stock2.amount) - odp1.amount))
Exemplo n.º 2
0
    def test_verbose_availability_with_stock_sold_out(self):
        OrderRoundFactory()
        product = ProductFactory(order_round=None)
        stock = ProductStockFactory(product=product, type=ProductStock.TYPE_ADDED)
        OrderProductFactory(product=product, amount=stock.amount,
                            order__paid=True)

        self.assertEqual(product.verbose_availability(), "uitverkocht")
Exemplo n.º 3
0
 def test_verbose_availability_with_stock_2(self):
     product = ProductFactory(order_round=None)
     stock1 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     stock2 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     self.assertEqual(product.verbose_availability(),
                      "%s in voorraad" % (stock1.amount + stock2.amount))
Exemplo n.º 4
0
 def test_verbose_availability_with_stock_2(self):
     product = ProductFactory(order_round=None)
     stock1 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     stock2 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     self.assertEqual(product.verbose_availability(),
                      "%s in voorraad" % (stock1.amount + stock2.amount))
Exemplo n.º 5
0
    def test_verbose_availability_with_stock_4(self):
        OrderRoundFactory()
        product = ProductFactory(order_round=None)
        stock1 = ProductStockFactory(product=product, type=ProductStock.TYPE_ADDED, amount=10)
        stock2 = ProductStockFactory(product=product, type=ProductStock.TYPE_ADDED, amount=5)
        stock3 = ProductStockFactory(product=product, type=ProductStock.TYPE_LOST, amount=3)
        odp1 = OrderProductFactory(product=product, amount=1, order__paid=True)

        self.assertEqual(product.verbose_availability(), "11 in voorraad")
Exemplo n.º 6
0
    def test_verbose_availability_with_stock_sold_out(self):
        OrderRoundFactory()
        product = ProductFactory(order_round=None)
        stock = ProductStockFactory(product=product,
                                    type=ProductStock.TYPE_ADDED)
        OrderProductFactory(product=product,
                            amount=stock.amount,
                            order__paid=True)

        self.assertEqual(product.verbose_availability(), "uitverkocht")
Exemplo n.º 7
0
    def test_product_round_override(self):
        round1 = self.round
        round2 = OrderRoundFactory()
        products1 = ProductFactory.create_batch(50, order_round=round1)
        products2 = ProductFactory.create_batch(50, order_round=round2)

        ret = self.client.get(self.url)
        self.assertCountEqual(ret.context['object_list'], products1)

        ret = self.client.get(self.url + "?round=%d" % round2.id)
        self.assertCountEqual(ret.context['object_list'], products2)
Exemplo n.º 8
0
    def test_determine_new_product_1(self):
        round1 = OrderRoundFactory()
        round2 = OrderRoundFactory()

        product1 = ProductFactory(order_round=round1)
        product2 = ProductFactory(order_round=round2)

        self.assertFalse(product2.new)
        product2.determine_if_product_is_new_and_set_label()
        product2 = Product.objects.get(id=product2.id)
        self.assertTrue(product2.new)
Exemplo n.º 9
0
    def test_product_round_override(self):
        round1 = self.round
        round2 = OrderRoundFactory()
        products1 = ProductFactory.create_batch(50, order_round=round1)
        products2 = ProductFactory.create_batch(50, order_round=round2)

        ret = self.client.get(self.url)
        self.assertItemsEqual(ret.context['object_list'], products1)

        ret = self.client.get(self.url + "?round=%d" % round2.id)
        self.assertItemsEqual(ret.context['object_list'], products2)
Exemplo n.º 10
0
    def test_determine_new_product_1(self):
        round1 = OrderRoundFactory()
        round2 = OrderRoundFactory()

        # Old, new
        ProductFactory(order_round=round1)
        new_product = ProductFactory(order_round=round2)

        self.assertFalse(new_product.new)
        new_product.determine_if_product_is_new_and_set_label()
        new_product = Product.objects.get(id=new_product.id)
        self.assertTrue(new_product.new)
Exemplo n.º 11
0
    def test_determine_new_product_1(self):
        round1 = OrderRoundFactory()
        round2 = OrderRoundFactory()

        # Old, new
        ProductFactory(order_round=round1)
        new_product = ProductFactory(order_round=round2)

        self.assertFalse(new_product.new)
        new_product.determine_if_product_is_new_and_set_label()
        new_product = Product.objects.get(id=new_product.id)
        self.assertTrue(new_product.new)
Exemplo n.º 12
0
    def test_verbose_availability_with_stock_3(self):
        OrderRoundFactory()
        product = ProductFactory(order_round=None)
        stock1 = ProductStockFactory(product=product,
                                     type=ProductStock.TYPE_ADDED)
        stock2 = ProductStockFactory(product=product,
                                     type=ProductStock.TYPE_ADDED)
        odp1 = OrderProductFactory(product=product, amount=1, order__paid=True)

        self.assertEqual(
            product.verbose_availability(),
            "%s in voorraad" % ((stock1.amount + stock2.amount) - odp1.amount))
Exemplo n.º 13
0
    def test_stock_products_without_stock_are_excluded(self):
        order = OrderFactory(order_round=self.round, user=self.user)

        product = ProductFactory(order_round=self.round)
        sproduct = ProductFactory(order_round=None)

        OrderProductFactory(order=order, product=product)
        OrderProductFactory(order=order, product=sproduct)

        ret = self.client.get(self.url)
        self.assertNotIn(sproduct, list(ret.context['view'].products()))
        self.assertIn(product, list(ret.context['view'].products()))
Exemplo n.º 14
0
    def test_determine_new_product_2(self):
        round1 = OrderRoundFactory()
        round2 = OrderRoundFactory()
        supplier = SupplierFactory()
        unit = UnitFactory()

        product1 = ProductFactory(order_round=round1, name="Appels", supplier=supplier, unit=unit)
        product2 = ProductFactory(order_round=round1, name="Appels", supplier=supplier, unit=unit)

        self.assertFalse(product2.new)
        product2.determine_if_product_is_new_and_set_label()
        product2 = Product.objects.get(id=product2.id)
        self.assertFalse(product2.new)
Exemplo n.º 15
0
    def test_verbose_availability_with_stock_4(self):
        OrderRoundFactory()
        product = ProductFactory(order_round=None)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_ADDED,
                            amount=10)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_ADDED,
                            amount=5)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_LOST,
                            amount=3)
        OrderProductFactory(product=product, amount=1, order__paid=True)

        self.assertEqual(product.verbose_availability(), "11 in voorraad")
Exemplo n.º 16
0
    def test_determine_new_product_2(self):
        round1 = OrderRoundFactory()
        OrderRoundFactory()
        supplier = SupplierFactory()
        unit = UnitFactory()

        # old product
        ProductFactory(order_round=round1, name="Appels",
                       supplier=supplier, unit=unit)
        new_product = ProductFactory(order_round=round1, name="Appels",
                                     supplier=supplier, unit=unit)

        self.assertFalse(new_product.new)
        new_product.determine_if_product_is_new_and_set_label()
        new_product = Product.objects.get(id=new_product.id)
        self.assertFalse(new_product.new)
Exemplo n.º 17
0
    def test_amount_ordered_only_counts_orderproducts_of_paid_orders(self):
        product = ProductFactory()
        OrderProductFactory(product=product, order__paid=False)
        odp2 = OrderProductFactory(product=product, order__paid=True)
        odp3 = OrderProductFactory(product=product, order__paid=True)

        self.assertEqual(product.amount_ordered, odp2.amount + odp3.amount)
Exemplo n.º 18
0
    def test_that_stock_product_amount_is_decreased(self):
        # 10 available
        product = ProductFactory(order_round=None)
        ProductStockFactory(product=product, amount=10)
        self.assertEqual(10, product.amount_available)

        order1 = OrderFactory(order_round=self.round,
                              finalized=True,
                              paid=True)
        OrderProductFactory(order=order1, product=product, amount=8)

        # 8 ordered, leaves 2
        self.assertEqual(8, product.amount_ordered)
        self.assertEqual(2, product.amount_available)

        # attempt to order 5
        order2 = OrderFactory(order_round=self.round)
        order2_product = OrderProductFactory(order=order2,
                                             product=product,
                                             amount=5)

        update_totals_for_products_with_max_order_amounts(order2)

        # re-fetch, amount is decreased to remaining 2
        order2_product = OrderProduct.objects.get(pk=order2_product.pk)
        self.assertEqual(2, order2_product.amount)
Exemplo n.º 19
0
 def test_is_available_on_stock_product_2(self):
     OrderRoundFactory()
     product = ProductFactory(order_round=None)
     ProductStockFactory(product=product, amount=5)
     ProductStockFactory(product=product, amount=4)
     OrderProductFactory(product=product, amount=9, order__paid=True)
     self.assertFalse(product.is_available)
Exemplo n.º 20
0
    def test_changing_product_is_prohibited(self):
        ps = ProductStockFactory(type='added')

        ps.product = ProductFactory()

        with self.assertRaises(AssertionError):
            ps.save()
Exemplo n.º 21
0
 def test_amount_available_with_stock_1(self):
     product = ProductFactory(maximum_total_order=None, order_round=None)
     stock1 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     stock2 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     self.assertEqual(product.amount_available,
                      (stock1.amount + stock2.amount))
Exemplo n.º 22
0
    def test_attribute_is_added_to_products_with_orderproduct(self):
        order = OrderFactory(order_round=self.round, user=self.user)
        product = ProductFactory(order_round=self.round)

        odp1 = OrderProductFactory(order=order, product=product)

        ret = self.client.get(self.url)
        self.assertEqual(
            list(ret.context['view'].products())[0].ordered_amount,
            odp1.amount)
Exemplo n.º 23
0
    def test_order_more_than_max(self):
        product = ProductFactory(order_round=self.round, maximum_total_order=1)
        self.assertTrue(product.is_available)

        ret = self.client.post(self.url, {"order-product-%d" % product.id: 2},
                               follow=True)
        self.assertMsgInResponse(
            ret, "Van het product '%s' van %s is nog %s %s beschikbaar!" %
            (product.name, product.supplier.name, product.amount_available,
             product.unit_of_measurement.lower()))
Exemplo n.º 24
0
    def test_determine_new_product_2(self):
        round1 = OrderRoundFactory()
        OrderRoundFactory()
        supplier = SupplierFactory()
        unit = UnitFactory()

        # old product
        ProductFactory(order_round=round1,
                       name="Appels",
                       supplier=supplier,
                       unit=unit)
        new_product = ProductFactory(order_round=round1,
                                     name="Appels",
                                     supplier=supplier,
                                     unit=unit)

        self.assertFalse(new_product.new)
        new_product.determine_if_product_is_new_and_set_label()
        new_product = Product.objects.get(id=new_product.id)
        self.assertFalse(new_product.new)
Exemplo n.º 25
0
    def test_create_corrections_creates_corrections_for_all_orderproducts_of_paid_orders(self):
        product = ProductFactory()
        paid_odp1 = OrderProductFactory(product=product, order__paid=True)
        paid_odp2 = OrderProductFactory(product=product, order__paid=True)
        nonpaid_odp2 = OrderProductFactory(product=product, order__paid=False)

        self.assertItemsEqual(OrderProductCorrection.objects.all(), [])
        product.create_corrections()

        corrections = OrderProductCorrection.objects.all().order_by('id')
        self.assertEqual(len(corrections), 2)

        self.assertEqual(corrections[0].order_product, paid_odp1)
        self.assertEqual(corrections[0].supplied_percentage, 0)
        self.assertEqual(corrections[0].notes,
                         'Product niet geleverd: "%s" (%s) [%s]' %
                         (paid_odp1.product.name, paid_odp1.product.supplier.name, paid_odp1.product.id))
        self.assertEqual(corrections[0].charge_supplier, True)

        self.assertEqual(corrections[1].order_product, paid_odp2)
Exemplo n.º 26
0
    def test_add_stock_with_different_price_creates_new_product(self):
        product = ProductFactory(order_round=None, base_price=1)
        ProductStockFactory(product=product, amount=5)
        self.assertEqual(product.all_stock(), 5)

        ret = self.client.post(self.url, data={
            'amount': 7,
            'product_id': product.id,
            'type': 'added',
            'notes': "foo",
            'base_price': "1.5"  # different than '1'
        })

        self.assertEqual(ret.status_code, 201)
        prod_stock = ProductStock.objects.last()

        self.assertEqual(ProductStock.objects.count(), 2)

        new_product = Product.objects.last()

        self.assertEqual(prod_stock.product, new_product)
        self.assertEqual(prod_stock.type, 'added')
        self.assertEqual(prod_stock.amount, 7)
        self.assertEqual(prod_stock.notes, 'foo')

        self.assertEqual(product.all_stock(), 5)
        self.assertEqual(new_product.all_stock(), 7)

        # Check cloned product
        self.assertEqual(new_product.base_price, 1.5)
        self.assertEqual(new_product.name, product.name)
        self.assertEqual(new_product.unit, product.unit)
        self.assertEqual(new_product.unit_amount, product.unit_amount)
        self.assertEqual(new_product.supplier, product.supplier)
        self.assertEqual(new_product.order_round, product.order_round)
        self.assertEqual(new_product.category, product.category)
        self.assertEqual(new_product.new, product.new)
        self.assertEqual(new_product.maximum_total_order,
                         product.maximum_total_order)
        self.assertEqual(new_product.enabled, product.enabled)
Exemplo n.º 27
0
    def test_creates_corrections_for_all_orderproducts_of_paid_orders(self):
        product = ProductFactory()
        paid_odp1 = OrderProductFactory(product=product, order__paid=True)
        paid_odp2 = OrderProductFactory(product=product, order__paid=True)
        # non paid
        OrderProductFactory(product=product, order__paid=False)

        self.assertCountEqual(OrderProductCorrection.objects.all(), [])
        product.create_corrections()

        corrections = OrderProductCorrection.objects.all().order_by('id')
        self.assertEqual(len(corrections), 2)

        self.assertEqual(corrections[0].order_product, paid_odp1)
        self.assertEqual(corrections[0].supplied_percentage, 0)
        self.assertEqual(
            corrections[0].notes, 'Product niet geleverd: "%s" (%s) [%s]' %
            (paid_odp1.product.name, paid_odp1.product.supplier.name,
             paid_odp1.product.id))
        self.assertEqual(corrections[0].charge_supplier, True)

        self.assertEqual(corrections[1].order_product, paid_odp2)
Exemplo n.º 28
0
    def test_amount_available_with_stock_2(self):
        product = ProductFactory(maximum_total_order=None, order_round=None)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_ADDED,
                            amount=10)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_ADDED,
                            amount=20),
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_LOST,
                            amount=5),

        self.assertEqual(product.amount_available, 25)
Exemplo n.º 29
0
    def test_new_stock(self):
        product = ProductFactory(order_round=None)
        self.assertFalse(ProductStock.objects.all())
        self.assertEqual(product.all_stock(), 0)

        ret = self.client.post(self.url, data={
            'amount': 10,
            'product_id': product.id,
            'type': 'added',
            'notes': "foo",
            'base_price': str(product.base_price)
        })

        self.assertEqual(ret.status_code, 201)
        prod_stock = ProductStock.objects.first()

        self.assertCountEqual(product.stock.all(),
                              (prod_stock,))

        self.assertEqual(prod_stock.product, product)
        self.assertEqual(prod_stock.type, 'added')
        self.assertEqual(prod_stock.amount, 10)
        self.assertEqual(prod_stock.notes, 'foo')
        self.assertEqual(product.all_stock(), 10)
Exemplo n.º 30
0
    def test_subtract_stock(self):
        product = ProductFactory(order_round=None)
        ProductStockFactory(product=product, amount=5)
        self.assertEqual(product.all_stock(), 5)

        ret = self.client.post(self.url, data={
            'amount': 3,
            'product_id': product.id,
            'type': 'lost',
            'notes': "foo",
            'base_price': str(product.base_price)
        })

        self.assertEqual(ret.status_code, 201)
        prod_stock = ProductStock.objects.last()

        self.assertEqual(ProductStock.objects.count(), 2)

        self.assertEqual(prod_stock.product, product)
        self.assertEqual(prod_stock.type, 'lost')
        self.assertEqual(prod_stock.amount, 3)
        self.assertEqual(prod_stock.notes, 'foo')

        self.assertEqual(product.all_stock(), 2)
Exemplo n.º 31
0
    def test_order_one_product(self):
        self.assertFalse(OrderProduct.objects.exists())

        product = ProductFactory(order_round=self.round)
        ret = self.client.post(self.url, {"order-product-%d" % product.id: 3})

        odp = OrderProduct.objects.get()
        self.assertEqual(odp.product, product)
        self.assertEqual(odp.amount, 3)
        self.assertEqual(odp.order.order_round, self.round)
        self.assertEqual(odp.total_retail_price, product.retail_price * 3)
        self.assertEqual(odp.base_price, product.base_price)
        self.assertEqual(odp.retail_price, product.retail_price)

        self.assertRedirects(ret,
                             reverse("finish_order", args=(self.order.id, )))
Exemplo n.º 32
0
    def test_that_sold_out_product_is_removed(self):
        product = ProductFactory(order_round=self.round,
                                 maximum_total_order=10)
        self.assertEqual(10, product.amount_available)

        order1 = OrderFactory(order_round=self.round,
                              finalized=True,
                              paid=True)
        OrderProductFactory(order=order1, product=product, amount=10)

        self.assertEqual(10, product.amount_ordered)
        self.assertEqual(0, product.amount_available)

        order2 = OrderFactory(order_round=self.round)
        OrderProductFactory(order=order2, amount=1)

        update_totals_for_products_with_max_order_amounts(order2)

        self.assertEqual(1, len(product.orderproducts.all()))
Exemplo n.º 33
0
    def test_sold_out_stock_product_is_removed(self):
        # 10 available
        product = ProductFactory(order_round=None)
        ProductStockFactory(product=product, amount=10)
        self.assertEqual(10, product.amount_available)

        order1 = OrderFactory(order_round=self.round,
                              finalized=True,
                              paid=True)
        OrderProductFactory(order=order1, product=product, amount=10)

        # 10 ordered, 0 remain
        self.assertEqual(10, product.amount_ordered)
        self.assertEqual(0, product.amount_available)

        # order 1 more
        order2 = OrderFactory(order_round=self.round)
        OrderProductFactory(order=order2, product=product, amount=1)

        self.assertEqual(2, len(product.orderproducts.all()))
        update_totals_for_products_with_max_order_amounts(order2)
        self.assertEqual(1, len(product.orderproducts.all()))
Exemplo n.º 34
0
 def test_verbose_availability_2(self):
     product = ProductFactory(maximum_total_order=None)
     self.assertEqual(product.verbose_availability(), "Onbeperkt")
Exemplo n.º 35
0
 def test_determine_new_product_with_one_order_round(self):
     product = ProductFactory()
     self.assertEqual(len(OrderRound.objects.all()), 1)
     self.assertIsNone(product.determine_if_product_is_new_and_set_label())
Exemplo n.º 36
0
 def test_verbose_availability_1(self):
     product = ProductFactory(maximum_total_order=99)
     o1 = OrderProductFactory(product=product, order__paid=True).amount
     o2 = OrderProductFactory(product=product, order__paid=True).amount
     self.assertEqual(product.verbose_availability(), "%s van 99" % (99 - (o1 + o2)))
Exemplo n.º 37
0
 def test_verbose_availability_2(self):
     product = ProductFactory(maximum_total_order=None)
     self.assertEqual(product.verbose_availability(), "Onbeperkt")
Exemplo n.º 38
0
 def test_context_contains_products_ordered_by_name(self):
     ProductFactory.create_batch(50, order_round=self.round)
     ret = self.client.get(self.url)
     self.assertItemsEqual(ret.context['view'].products(), Product.objects.all().order_by('name'))
Exemplo n.º 39
0
 def test_is_available_when_not_sold_out(self):
     product = ProductFactory(maximum_total_order=10)
     OrderProductFactory(product=product, order__paid=True, amount=1)
     self.assertTrue(product.is_available)
Exemplo n.º 40
0
 def test_verbose_availability_1(self):
     product = ProductFactory(maximum_total_order=99)
     o1 = OrderProductFactory(product=product, order__paid=True).amount
     o2 = OrderProductFactory(product=product, order__paid=True).amount
     self.assertEqual(product.verbose_availability(),
                      "%s van 99" % (99 - (o1 + o2)))
Exemplo n.º 41
0
 def test_percentage_available_with_max(self):
     product = ProductFactory(maximum_total_order=10)
     OrderProductFactory(product=product, order__paid=True, amount=1)
     self.assertEqual(product.percentage_available, 90)
Exemplo n.º 42
0
 def test_percentage_available_is_rounded_to_int(self):
     product = ProductFactory(maximum_total_order=99)
     OrderProductFactory(product=product, order__paid=True, amount=25)
     self.assertEqual(product.percentage_available, 74)
Exemplo n.º 43
0
 def test_determine_new_product_with_one_order_round(self):
     product = ProductFactory()
     self.assertEqual(len(OrderRound.objects.all()), 1)
     self.assertIsNone(product.determine_if_product_is_new_and_set_label())
Exemplo n.º 44
0
 def test_is_available_on_stock_product_1(self):
     product = ProductFactory(order_round=None)
     ProductStockFactory(product=product, amount=2)
     self.assertTrue(product.is_available)
Exemplo n.º 45
0
 def test_percentage_available_with_stock_is_always_0(self):
     product = ProductFactory()
     ProductStockFactory(amount=10, product=product)
     OrderProductFactory(product=product, order__paid=True, amount=1)
     self.assertEqual(product.percentage_available, 100)
Exemplo n.º 46
0
 def test_percentage_available_ignores_non_paid_orders(self):
     product = ProductFactory(maximum_total_order=10)
     OrderProductFactory(product=product, order__paid=False, amount=1)
     self.assertEqual(product.percentage_available, 100)
Exemplo n.º 47
0
 def test_is_available_when_no_max(self):
     product = ProductFactory(maximum_total_order=None)
     self.assertTrue(product.is_available)