示例#1
0
 def test_total_price_to_pay_with_no_balance(self):
     order = OrderFactory()
     OrderProductFactory(order=order)
     OrderProductFactory(order=order)
     self.assertEqual(
         order.total_price_to_pay_with_balances_taken_into_account(),
         order.total_price)
示例#2
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)
示例#3
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)
示例#4
0
文件: test_views.py 项目: rikva/voko
    def test_submit_without_data_2(self):
        OrderProductFactory.create_batch(10, product__order_round=self.round,
                                         order__user=self.user)
        ret = self.client.post(self.url)
        self.assertEqual(len(OrderProduct.objects.all()), 10)

        self.assertRedirects(ret, reverse("finish_order",
                                          args=(self.order.id,)))
示例#5
0
 def test_total_order_price_with_two_orderproducts(self):
     order = OrderFactory()
     odp1 = OrderProductFactory(order=order)
     odp2 = OrderProductFactory(order=order)
     self.assertEqual(
         order.total_price,
         (order.member_fee + order.order_round.transaction_costs) +
         odp1.total_retail_price + odp2.total_retail_price)
示例#6
0
 def test_total_price_to_pay_with_credit(self):
     user = VokoUserFactory()
     BalanceFactory(user=user, type="CR", amount=0.10)
     order = OrderFactory(user=user)
     OrderProductFactory(order=order)
     OrderProductFactory(order=order)
     self.assertEqual(
         order.total_price_to_pay_with_balances_taken_into_account(),
         order.total_price - Decimal("0.10"))
示例#7
0
    def test_submit_without_data_2(self):
        OrderProductFactory.create_batch(10,
                                         product__order_round=self.round,
                                         order__user=self.user)
        ret = self.client.post(self.url)
        self.assertEqual(len(OrderProduct.objects.all()), 10)

        self.assertRedirects(ret,
                             reverse("finish_order", args=(self.order.id, )))
示例#8
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()))
示例#9
0
 def test_suppliers_with_paid_and_unpaid_orders(self):
     order_round = OrderRoundFactory()
     supplier1 = SupplierFactory()
     supplier2 = SupplierFactory()
     paid_order = OrderFactory(paid=True,
                               finalized=True,
                               order_round=order_round)
     finalized_order = OrderFactory(paid=False,
                                    finalized=True,
                                    order_round=order_round)
     OrderProductFactory(product__supplier=supplier1, order=paid_order)
     OrderProductFactory(product__supplier=supplier2, order=finalized_order)
     self.assertCountEqual(order_round.suppliers(), [supplier1])
示例#10
0
    def test_delete_some_products(self):
        user_odps = OrderProductFactory.create_batch(10, product__order_round=self.round, order=self.order)
        other_odps = OrderProductFactory.create_batch(10, product__order_round=self.round, order=self.order)

        data = {}
        for odp in user_odps[:5]:
            data["order-product-%d" % odp.product.id] = ""

        ret = self.client.post(self.url, data)
        self.assertEqual(len(OrderProduct.objects.all()), 15)
        self.assertItemsEqual(OrderProduct.objects.all(), other_odps + user_odps[5:])

        self.assertRedirects(ret, reverse("finish_order", args=(self.order.id,)))
示例#11
0
 def test_total_price_to_pay_with_more_credit_than_order_price(self):
     user = VokoUserFactory()
     BalanceFactory(user=user, type="CR", amount=100)
     order = OrderFactory(user=user)
     OrderProductFactory(order=order, amount=1, product__base_price=10)
     self.assertEqual(
         order.total_price_to_pay_with_balances_taken_into_account(), 0)
示例#12
0
    def test_delete_all_products_of_user(self):
        user_odps = OrderProductFactory.create_batch(
            10, product__order_round=self.round, order=self.order)
        other_odps = OrderProductFactory.create_batch(
            10, product__order_round=self.round, order=self.order)

        data = {}
        for odp in user_odps:
            data["order-product-%d" % odp.product.id] = 0

        ret = self.client.post(self.url, data)
        self.assertEqual(len(OrderProduct.objects.all()), 10)
        self.assertCountEqual(OrderProduct.objects.all(), other_odps)

        self.assertRedirects(ret,
                             reverse("finish_order", args=(self.order.id, )))
示例#13
0
文件: test_views.py 项目: rikva/voko
    def test_delete_all_products_of_user(self):
        user_odps = OrderProductFactory.create_batch(
            10, product__order_round=self.round, order=self.order)
        other_odps = OrderProductFactory.create_batch(
            10, product__order_round=self.round, order=self.order)

        data = {}
        for odp in user_odps:
            data["order-product-%d" % odp.product.id] = 0

        ret = self.client.post(self.url, data)
        self.assertEqual(len(OrderProduct.objects.all()), 10)
        self.assertCountEqual(OrderProduct.objects.all(), other_odps)

        self.assertRedirects(ret, reverse("finish_order",
                                          args=(self.order.id,)))
示例#14
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)
示例#15
0
 def test_total_price_to_pay_with_large_debit(self):
     user = VokoUserFactory()
     BalanceFactory(user=user, type="DR", amount=100)
     order = OrderFactory(user=user)
     OrderProductFactory(order=order, amount=1, product__base_price=10)
     self.assertEqual(
         order.total_price_to_pay_with_balances_taken_into_account(),
         order.total_price + Decimal("100"))
示例#16
0
文件: test_views.py 项目: rikva/voko
 def test_other_keys_in_post_data_are_ignored(self):
     odps = OrderProductFactory.create_batch(
         10, product__order_round=self.round, order=self.order)
     ret = self.client.post(self.url, {"order_product_999": 12,
                                       "foo": "bar"})
     self.assertCountEqual(OrderProduct.objects.all(), odps)
     self.assertRedirects(ret,
                          reverse("finish_order", args=(self.order.id,)))
示例#17
0
    def test_total_order_sum(self):
        order_round = OrderRoundFactory()
        orderproduct1 = OrderProductFactory(order__order_round=order_round,
                                            order__paid=True,
                                            order__finalized=True)
        orderproduct2 = OrderProductFactory(order__order_round=order_round,
                                            order__paid=True,
                                            order__finalized=True)
        # Not paid
        OrderProductFactory(order__order_round=order_round,
                            order__paid=False,
                            order__finalized=False)

        expected_sum = (
            (orderproduct1.product.base_price * orderproduct1.amount) +
            (orderproduct2.product.base_price * orderproduct2.amount))

        self.assertEqual(order_round.total_order_sum(), expected_sum)
示例#18
0
    def test_that_creating_a_correction_creates_sufficient_credit_3(self):
        order_product = OrderProductFactory.create(amount=10,
                                                   product__base_price=Decimal(1),
                                                   product__order_round__markup_percentage=Decimal(7))

        opc = OrderProductCorrection.objects.create(order_product=order_product,
                                                    supplied_percentage=0)

        self.assertEqual(opc.credit.amount, Decimal(10 * 1.07).quantize(Decimal('.01')))
示例#19
0
 def test_that_credit_description_is_filled_in(self):
     order_product = OrderProductFactory.create()
     opc = OrderProductCorrection.objects.create(
         order_product=order_product, supplied_percentage=0)
     self.assertEqual(
         opc.credit.notes, "Correctie in ronde %d, %dx %s, geleverd: %s%%" %
         (opc.order_product.product.order_round.id,
          opc.order_product.amount, opc.order_product.product.name,
          opc.supplied_percentage))
示例#20
0
 def test_that_credit_description_is_filled_in(self):
     order_product = OrderProductFactory.create()
     opc = OrderProductCorrection.objects.create(order_product=order_product,
                                                 supplied_percentage=0)
     self.assertEqual(opc.credit.notes, "Correctie in ronde %d, %dx %s, geleverd: %s%%" %
                      (opc.order_product.product.order_round.id,
                       opc.order_product.amount,
                       opc.order_product.product.name,
                       opc.supplied_percentage))
示例#21
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")
示例#22
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()))
示例#23
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)
示例#24
0
 def test_other_keys_in_post_data_are_ignored(self):
     odps = OrderProductFactory.create_batch(
         10, product__order_round=self.round, order=self.order)
     ret = self.client.post(self.url, {
         "order_product_999": 12,
         "foo": "bar"
     })
     self.assertCountEqual(OrderProduct.objects.all(), odps)
     self.assertRedirects(ret,
                          reverse("finish_order", args=(self.order.id, )))
示例#25
0
    def test_that_creating_a_correction_creates_sufficient_credit_3(self):
        order_product = OrderProductFactory.create(
            amount=10,
            product__base_price=Decimal(1),
            product__order_round__markup_percentage=Decimal(7))

        opc = OrderProductCorrection.objects.create(
            order_product=order_product, supplied_percentage=0)

        self.assertEqual(opc.credit.amount,
                         Decimal(10 * 1.07).quantize(Decimal('.01')))
示例#26
0
    def test_supplier_total_order_sum_with_multiple_orders(self):
        order_round = OrderRoundFactory()
        supplier1 = SupplierFactory()
        supplier1_orderproduct1 = OrderProductFactory(
            product__supplier=supplier1,
            order__order_round=order_round,
            order__paid=True,
            order__finalized=True)
        supplier1_orderproduct2 = OrderProductFactory(
            product__supplier=supplier1,
            order__order_round=order_round,
            order__paid=True,
            order__finalized=True)

        expected_sum = ((supplier1_orderproduct1.product.base_price *
                         supplier1_orderproduct1.amount) +
                        (supplier1_orderproduct2.product.base_price *
                         supplier1_orderproduct2.amount))

        self.assertEqual(order_round.supplier_total_order_sum(supplier1),
                         expected_sum)
示例#27
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))
示例#28
0
    def test_that_creating_a_correction_creates_sufficient_credit_4(self):
        order_product = OrderProductFactory.create(amount=1,
                                                   product__base_price=Decimal(1),
                                                   product__order_round__markup_percentage=Decimal(7))

        opc = OrderProductCorrection.objects.create(order_product=order_product,
                                                    supplied_percentage=50)

        # Price is 1 Euro, markup is 7%, so total price is 1.07.
        # Half of 1.07 is 0.535
        # Rounding is ROUND_DOWN to 2 decimals, so 0.53.

        self.assertEqual(opc.credit.amount, Decimal('0.53'))
示例#29
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()))
示例#30
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)
示例#31
0
    def test_change_amounts(self):
        user_odps = OrderProductFactory.create_batch(10, product__order_round=self.round, order=self.order,
                                                     amount=5)

        data = {}
        for odp in user_odps:
            data["order-product-%d" % odp.product.id] = "3"
        ret = self.client.post(self.url, data)

        for odp in OrderProduct.objects.all():
            self.assertEqual(odp.amount, 3)

        self.assertRedirects(ret, reverse("finish_order", args=(self.order.id,)))
示例#32
0
    def test_create_debit(self):
        order = OrderFactory()
        OrderProductFactory(order=order)
        self.assertIsNone(order.debit)
        order.create_debit()

        order = Order.objects.get()
        self.assertEqual(order.debit.user, order.user)
        self.assertEqual(order.debit.type, "DR")
        self.assertEqual(order.debit.amount, order.total_price)
        self.assertEqual(
            order.debit.notes,
            "Debit van %s voor bestelling #%d" % (order.total_price, order.id))
示例#33
0
    def setUp(self):
        super(TestChooseBank, self).setUp()
        self.url = reverse('finance.choosebank')
        self.login()

        self.order_round = OrderRoundFactory.create()
        o_p = OrderProductFactory.create(order__order_round=self.order_round,
                                         product__order_round=self.order_round,
                                         order__user=self.user,
                                         order__finalized=True)
        o_p.order.create_debit()
        o_p.save()
        self.order = o_p.order
示例#34
0
    def test_that_creating_a_correction_creates_sufficient_credit_5(self):
        order_product = OrderProductFactory.create(amount=2,
                                                   product__base_price=Decimal(1),
                                                   product__order_round__markup_percentage=Decimal(7))

        opc = OrderProductCorrection.objects.create(order_product=order_product,
                                                    supplied_percentage=45)

        # Price is 1 Euro, markup is 7%, amount is 2, so total price is 2.14.
        # 0.9 supplied, so 1.1 was not supplied.
        # 1.07 * 1.1 = 1.177
        # Rounding is ROUND_DOWN to 2 decimals, so 1.17.

        self.assertEqual(opc.credit.amount, Decimal('1.17'))
示例#35
0
    def test_supplier_total_order_sum_with_one_order(self):
        order_round = OrderRoundFactory()
        supplier1 = SupplierFactory()
        paid_order = OrderFactory(paid=True,
                                  finalized=True,
                                  order_round=order_round)
        supplier1_orderproduct = OrderProductFactory(
            product__supplier=supplier1, order=paid_order)
        self.assertCountEqual(order_round.suppliers(), [supplier1])

        self.assertEqual(
            order_round.supplier_total_order_sum(supplier1),
            supplier1_orderproduct.product.base_price *
            supplier1_orderproduct.amount)
示例#36
0
    def test_that_creating_a_correction_creates_sufficient_credit_4(self):
        order_product = OrderProductFactory.create(
            amount=1,
            product__base_price=Decimal(1),
            product__order_round__markup_percentage=Decimal(7))

        opc = OrderProductCorrection.objects.create(
            order_product=order_product, supplied_percentage=50)

        # Price is 1 Euro, markup is 7%, so total price is 1.07.
        # Half of 1.07 is 0.535
        # Rounding is ROUND_DOWN to 2 decimals, so 0.53.

        self.assertEqual(opc.credit.amount, Decimal('0.53'))
示例#37
0
    def test_change_amounts(self):
        user_odps = OrderProductFactory.create_batch(
            10, product__order_round=self.round, order=self.order, amount=5)

        data = {}
        for odp in user_odps:
            data["order-product-%d" % odp.product.id] = "3"
        ret = self.client.post(self.url, data)

        for odp in OrderProduct.objects.all():
            self.assertEqual(odp.amount, 3)

        self.assertRedirects(ret,
                             reverse("finish_order", args=(self.order.id, )))
示例#38
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")
示例#39
0
    def test_that_saving_order_correction_does_not_alter_the_credit(self):
        order_product = OrderProductFactory.create(amount=10,
                                                   product__base_price=Decimal(1),
                                                   product__order_round__markup_percentage=Decimal(7))

        opc = OrderProductCorrection.objects.create(order_product=order_product,
                                                    supplied_percentage=0)

        self.assertEqual(opc.credit.amount, Decimal(10 * 1.07).quantize(Decimal('.01')))

        opc.supplied_percentage = 10
        opc.save()

        opc = OrderProductCorrection.objects.all().get()
        self.assertEqual(opc.credit.amount, Decimal(10 * 1.07).quantize(Decimal('.01')))
示例#40
0
    def test_that_creating_a_correction_creates_sufficient_credit_5(self):
        order_product = OrderProductFactory.create(
            amount=2,
            product__base_price=Decimal(1),
            product__order_round__markup_percentage=Decimal(7))

        opc = OrderProductCorrection.objects.create(
            order_product=order_product, supplied_percentage=45)

        # Price is 1 Euro, markup is 7%, amount is 2, so total price is 2.14.
        # 0.9 supplied, so 1.1 was not supplied.
        # 1.07 * 1.1 = 1.177
        # Rounding is ROUND_DOWN to 2 decimals, so 1.17.

        self.assertEqual(opc.credit.amount, Decimal('1.17'))
示例#41
0
文件: test_models.py 项目: rikva/voko
    def test_that_creating_a_correction_creates_sufficient_credit_1(self):
        order_product = OrderProductFactory.create(
            amount=10,
            product__base_price=Decimal('1'),
            product__order_round__markup_percentage=Decimal('7')
        )

        opc = OrderProductCorrection.objects.create(
            order_product=order_product,
            supplied_percentage=50)

        # Retail price is 1,07 per item
        # 10 items were ordered
        # 50% was delivered to member
        # so refund for 5 items.
        # 5 * 1,07 = 5,35
        expected_credit = Decimal('5.35')
        self.assertEqual(opc.credit.amount, expected_credit)
示例#42
0
 def test_creating_a_correction(self):
     order_product = OrderProductFactory.create()
     OrderProductCorrection.objects.create(order_product=order_product,
                                           supplied_percentage=0)
示例#43
0
 def test_total_cost_price(self):
     odp1 = OrderProductFactory()
     self.assertEqual(odp1.total_cost_price(),
                      odp1.amount * odp1.product.base_price)