示例#1
0
 def test_total_corrections_with_no_corrections(self):
     order_round = OrderRoundFactory()
     self.assertEqual(order_round.total_corrections(), {
         'supplier_inc': 0,
         'voko_inc': 0,
         'supplier_exc': 0
     })
示例#2
0
 def test_number_of_orders_with_paid_and_unpaid_orders(self):
     round = OrderRoundFactory()
     paid1 = OrderFactory(order_round=round, paid=True)
     paid2 = OrderFactory(order_round=round, paid=True)
     paid3 = OrderFactory(order_round=round, paid=True)
     unpaid1 = OrderFactory(order_round=round, paid=False)
     unpaid2 = OrderFactory(order_round=round, paid=False, finalized=True)
     self.assertEqual(round.number_of_orders(), 3)
示例#3
0
 def test_total_corrections(self):
     round = OrderRoundFactory()
     corr1 = OrderProductCorrectionFactory(order_product__order__order_round=round, charge_supplier=True)
     corr2 = OrderProductCorrectionFactory(order_product__order__order_round=round, charge_supplier=False)
     self.assertEqual(round.total_corrections(),
         {'supplier_inc': corr1.calculate_refund(),
          'voko_inc': corr2.calculate_refund(),
          'supplier_exc': corr1.calculate_supplier_refund()})
示例#4
0
    def setUp(self):
        now = datetime.now(tz=UTC)

        self.prev_order_round = OrderRoundFactory(open_for_orders=now - timedelta(days=8),
                                                  closed_for_orders=now - timedelta(days=4))
        self.cur_order_round = OrderRoundFactory(open_for_orders=now - timedelta(days=1),
                                                 closed_for_orders=now + timedelta(days=3))
        self.next_order_round = OrderRoundFactory(open_for_orders=now + timedelta(days=6),
                                                  closed_for_orders=now + timedelta(days=9))
示例#5
0
 def test_suppliers_with_paid_and_unpaid_orders(self):
     round = OrderRoundFactory()
     supplier1 = SupplierFactory()
     supplier2 = SupplierFactory()
     paid_order = OrderFactory(paid=True, finalized=True, order_round=round)
     finalized_order = OrderFactory(paid=False, finalized=True, order_round=round)
     supplier1_orderproduct = OrderProductFactory(product__supplier=supplier1, order=paid_order)
     supplier2_orderproduct = OrderProductFactory(product__supplier=supplier2, order=finalized_order)
     self.assertItemsEqual(round.suppliers(), [supplier1])
示例#6
0
    def test_supplier_total_order_sum_with_one_order(self):
        round = OrderRoundFactory()
        supplier1 = SupplierFactory()
        paid_order = OrderFactory(paid=True, finalized=True, order_round=round)
        supplier1_orderproduct = OrderProductFactory(product__supplier=supplier1, order=paid_order)
        self.assertItemsEqual(round.suppliers(), [supplier1])

        self.assertEqual(round.supplier_total_order_sum(supplier1),
                         supplier1_orderproduct.product.base_price * supplier1_orderproduct.amount)
示例#7
0
文件: test_models.py 项目: rikva/voko
    def test_number_of_orders_with_paid_and_unpaid_orders(self):
        order_round = OrderRoundFactory()
        # 3 paid
        OrderFactory(order_round=order_round, paid=True)
        OrderFactory(order_round=order_round, paid=True)
        OrderFactory(order_round=order_round, paid=True)
        # 2 unpaid
        OrderFactory(order_round=order_round, paid=False)
        OrderFactory(order_round=order_round, paid=False, finalized=True)

        self.assertEqual(order_round.number_of_orders(), 3)
示例#8
0
    def test_supplier_total_order_sum_with_multiple_orders(self):
        round = OrderRoundFactory()
        supplier1 = SupplierFactory()
        supplier1_orderproduct1 = OrderProductFactory(product__supplier=supplier1, order__order_round=round,
                                                      order__paid=True, order__finalized=True)
        supplier1_orderproduct2 = OrderProductFactory(product__supplier=supplier1, order__order_round=round,
                                                      order__paid=True, order__finalized=True)

        self.assertEqual(round.supplier_total_order_sum(supplier1),
                         (supplier1_orderproduct1.product.base_price * supplier1_orderproduct1.amount) +
                         (supplier1_orderproduct2.product.base_price * supplier1_orderproduct2.amount))
示例#9
0
    def test_number_of_orders_with_paid_and_unpaid_orders(self):
        order_round = OrderRoundFactory()
        # 3 paid
        OrderFactory(order_round=order_round, paid=True)
        OrderFactory(order_round=order_round, paid=True)
        OrderFactory(order_round=order_round, paid=True)
        # 2 unpaid
        OrderFactory(order_round=order_round, paid=False)
        OrderFactory(order_round=order_round, paid=False, finalized=True)

        self.assertEqual(order_round.number_of_orders(), 3)
示例#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)
示例#11
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])
示例#12
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)
示例#13
0
    def test_total_order_sum(self):
        round = OrderRoundFactory()
        orderproduct1 = OrderProductFactory(order__order_round=round,
                                            order__paid=True,
                                            order__finalized=True)
        orderproduct2 = OrderProductFactory(order__order_round=round,
                                            order__paid=True,
                                            order__finalized=True)
        orderproduct3 = OrderProductFactory(order__order_round=round,
                                            order__paid=False,
                                            order__finalized=False)

        self.assertEqual(round.total_order_sum(),
            (orderproduct1.product.base_price * orderproduct1.amount) +
            (orderproduct2.product.base_price * orderproduct2.amount))
示例#14
0
    def test_total_corrections(self):
        order_round = OrderRoundFactory()
        corr1 = OrderProductCorrectionFactory(
            order_product__order__order_round=order_round,
            charge_supplier=True)
        corr2 = OrderProductCorrectionFactory(
            order_product__order__order_round=order_round,
            charge_supplier=False)

        self.assertEqual(
            order_round.total_corrections(), {
                'supplier_inc': corr1.calculate_refund(),
                'voko_inc': corr2.calculate_refund(),
                'supplier_exc': corr1.calculate_supplier_refund()
            })
示例#15
0
 def test_given_one_closed_order_round_it_is_returned(self):
     self.mock_datetime.now.return_value = datetime(2014,
                                                    11,
                                                    6,
                                                    0,
                                                    0,
                                                    tzinfo=UTC)
     orderround = OrderRoundFactory(open_for_orders=datetime(2014,
                                                             10,
                                                             27,
                                                             0,
                                                             0,
                                                             tzinfo=UTC),
                                    closed_for_orders=datetime(2014,
                                                               10,
                                                               31,
                                                               19,
                                                               0,
                                                               tzinfo=UTC),
                                    collect_datetime=datetime(2014,
                                                              11,
                                                              5,
                                                              17,
                                                              30,
                                                              tzinfo=UTC))
     ret = get_current_order_round()
     self.assertEqual(ret, orderround)
示例#16
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)
示例#17
0
    def test_given_previous_and_current_order_rounds_current_is_returned(self):
        OrderRoundFactory(open_for_orders=datetime(2014,
                                                   10,
                                                   27,
                                                   0,
                                                   0,
                                                   tzinfo=UTC),
                          closed_for_orders=datetime(2014,
                                                     10,
                                                     31,
                                                     19,
                                                     0,
                                                     tzinfo=UTC),
                          collect_datetime=datetime(2014,
                                                    11,
                                                    5,
                                                    17,
                                                    30,
                                                    tzinfo=UTC))
        current = OrderRoundFactory(open_for_orders=datetime(2014,
                                                             11,
                                                             10,
                                                             0,
                                                             0,
                                                             tzinfo=UTC),
                                    closed_for_orders=datetime(2014,
                                                               11,
                                                               14,
                                                               19,
                                                               0,
                                                               tzinfo=UTC),
                                    collect_datetime=datetime(2014,
                                                              11,
                                                              19,
                                                              17,
                                                              30,
                                                              tzinfo=UTC))
        self.mock_datetime.now.return_value = datetime(2014,
                                                       11,
                                                       15,
                                                       0,
                                                       0,
                                                       tzinfo=UTC)

        ret = get_current_order_round()
        self.assertEqual(ret, current)
示例#18
0
 def setUp(self):
     self.round = OrderRoundFactory()
     self.url = reverse('view_products')
     self.login()
     self.order = OrderFactory(paid=False,
                               finalized=False,
                               user=self.user,
                               order_round=self.round)
示例#19
0
    def test_context_contains_current_order_round(self):
        current = self.round
        other_round = OrderRoundFactory()

        ret = self.client.get(self.url)
        self.assertEqual(ret.context['current_order_round'], current)

        ret = self.client.get(self.url + "?round=%d" % other_round.id)
        self.assertEqual(ret.context['current_order_round'], other_round)
示例#20
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)
示例#21
0
    def test_calculate_refund_when_0_percent_supplied(self):
        order_round = OrderRoundFactory()
        corr = OrderProductCorrectionFactory(
            order_product__order__order_round=order_round,
            order_product__product__order_round=order_round,
            supplied_percentage=0)

        self.assertEqual(corr.calculate_refund(),
                         corr.order_product.total_retail_price)
示例#22
0
    def test_calculate_supplier_refund_with_simple_values(self):
        order_round = OrderRoundFactory()
        corr = OrderProductCorrectionFactory(
            order_product__order__order_round=order_round,
            order_product__product__order_round=order_round,
            order_product__product__base_price=10,
            order_product__amount=2,
            supplied_percentage=25)

        self.assertEqual(corr.calculate_supplier_refund(), Decimal('15'))
示例#23
0
    def test_redirect_when_order_round_is_closed(self):
        # No order matches, so not found
        month_ago = datetime.now(tz=UTC) - timedelta(days=30)
        order_round = OrderRoundFactory(closed_for_orders=month_ago)
        assert order_round.is_open is False
        self.order.order_round = order_round
        self.order.save()

        ret = self.client.post(self.url, {'bank': "EXAMPLE_BANK"})
        self.assertRedirects(ret, reverse('view_products'))
示例#24
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")
示例#25
0
文件: test_models.py 项目: rikva/voko
    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)
示例#26
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)
示例#27
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)
示例#28
0
    def test_supplier_refund_ignores_corrections_if_charge_supplier_is_false(
            self):
        order_round = OrderRoundFactory()
        corr = OrderProductCorrectionFactory(
            order_product__order__order_round=order_round,
            order_product__product__order_round=order_round,
            order_product__product__base_price=10,
            order_product__amount=2,
            supplied_percentage=25,
            charge_supplier=False)

        self.assertEqual(corr.calculate_supplier_refund(), Decimal('0'))
示例#29
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))
示例#30
0
    def test_calculate_supplier_refund_with_complex_values(self):
        order_round = OrderRoundFactory()
        corr = OrderProductCorrectionFactory(
            order_product__order__order_round=order_round,
            order_product__product__order_round=order_round,
            order_product__product__base_price=9.95,
            order_product__amount=2,
            supplied_percentage=24)
        # Total price: 9.95 * 2 = 19.90
        # 19.90 * 0.76 = 15.12

        self.assertEqual(corr.calculate_supplier_refund(), Decimal('15.12'))
示例#31
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)
示例#32
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
示例#33
0
    def test_calculate_refund_with_complex_values(self):
        order_round = OrderRoundFactory(markup_percentage=7.9)
        corr = OrderProductCorrectionFactory(
            order_product__order__order_round=order_round,
            order_product__product__order_round=order_round,
            order_product__product__base_price=9.95,
            order_product__amount=2,
            supplied_percentage=24)

        original_retail_price = corr.order_product.product.retail_price
        self.assertEqual(original_retail_price, Decimal('10.74'))

        self.assertEqual(corr.calculate_refund(), Decimal('16.32'))
示例#34
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")
示例#35
0
    def setUp(self):
        now = datetime.now(tz=UTC)

        self.prev_order_round = OrderRoundFactory(
            open_for_orders=now - timedelta(days=8),
            closed_for_orders=now - timedelta(days=4))
        self.cur_order_round = OrderRoundFactory(
            open_for_orders=now - timedelta(days=1),
            closed_for_orders=now + timedelta(days=3))
        self.next_order_round = OrderRoundFactory(
            open_for_orders=now + timedelta(days=6),
            closed_for_orders=now + timedelta(days=9))
示例#36
0
    def test_order_is_not_completed_when_round_is_closed_and_notification_is_sent(self):  # noqa
        month_ago = datetime.now(tz=UTC) - timedelta(days=30)
        order_round = OrderRoundFactory(closed_for_orders=month_ago)
        assert order_round.is_open is False
        self.order.order_round = order_round
        self.order.save()

        assert self.order.paid is False

        self.mollie_client.return_value.payments.get. \
            return_value.isPaid.return_value = True
        self.client.post(self.url, {"id": self.payment.mollie_id})

        payment = Payment.objects.get()
        self.assertFalse(payment.order.paid)
        self.mock_create_credit.assert_called_once_with()
        # self.assertFalse(self.mock_complete_after_payment.called)

        self.mock_failure_notification.assert_called_once_with()
示例#37
0
 def setUp(self):
     self.round = OrderRoundFactory()
     self.order = OrderFactory(order_round=self.round)
示例#38
0
    def test_given_multiple_open_order_rounds_return_first_one(self):
        round1 = OrderRoundFactory()
        OrderRoundFactory()

        self.assertTrue(round1.is_open)
        self.assertEqual(get_current_order_round(), round1)
示例#39
0
    def test_given_multiple_future_rounds_the_first_one_is_returned(self):
        # December 12
        OrderRoundFactory(open_for_orders=datetime(2014,
                                                   12,
                                                   8,
                                                   0,
                                                   0,
                                                   tzinfo=UTC),
                          closed_for_orders=datetime(2014,
                                                     12,
                                                     12,
                                                     19,
                                                     0,
                                                     tzinfo=UTC),
                          collect_datetime=datetime(2014,
                                                    12,
                                                    17,
                                                    17,
                                                    30,
                                                    tzinfo=UTC))
        # October 24
        OrderRoundFactory(open_for_orders=datetime(2014,
                                                   11,
                                                   24,
                                                   0,
                                                   0,
                                                   tzinfo=UTC),
                          closed_for_orders=datetime(2014,
                                                     11,
                                                     28,
                                                     19,
                                                     0,
                                                     tzinfo=UTC),
                          collect_datetime=datetime(2014,
                                                    12,
                                                    3,
                                                    17,
                                                    30,
                                                    tzinfo=UTC))
        # October 10
        future1 = OrderRoundFactory(open_for_orders=datetime(2014,
                                                             11,
                                                             10,
                                                             0,
                                                             0,
                                                             tzinfo=UTC),
                                    closed_for_orders=datetime(2014,
                                                               11,
                                                               14,
                                                               19,
                                                               0,
                                                               tzinfo=UTC),
                                    collect_datetime=datetime(2014,
                                                              11,
                                                              19,
                                                              17,
                                                              30,
                                                              tzinfo=UTC))

        self.mock_datetime.now.return_value = datetime(2014,
                                                       11,
                                                       1,
                                                       0,
                                                       0,
                                                       tzinfo=UTC)

        ret = get_current_order_round()
        self.assertEqual(ret, future1)
示例#40
0
 def setUp(self):
     self.supplier = SupplierFactory()
     self.order_round = OrderRoundFactory.create()
示例#41
0
 def test_total_corrections_with_no_corrections(self):
     round = OrderRoundFactory()
     self.assertEqual(round.total_corrections(),
         {'supplier_inc': 0, 'voko_inc': 0, 'supplier_exc': 0})
示例#42
0
class TestOrderRoundModel(VokoTestCase):
    def setUp(self):
        now = datetime.now(tz=UTC)

        self.prev_order_round = OrderRoundFactory(open_for_orders=now - timedelta(days=8),
                                                  closed_for_orders=now - timedelta(days=4))
        self.cur_order_round = OrderRoundFactory(open_for_orders=now - timedelta(days=1),
                                                 closed_for_orders=now + timedelta(days=3))
        self.next_order_round = OrderRoundFactory(open_for_orders=now + timedelta(days=6),
                                                  closed_for_orders=now + timedelta(days=9))

    def test_is_not_open_yet(self):
        self.assertFalse(self.prev_order_round.is_not_open_yet())
        self.assertFalse(self.cur_order_round.is_not_open_yet())
        self.assertTrue(self.next_order_round.is_not_open_yet())

    def test_is_over(self):
        self.assertTrue(self.prev_order_round.is_over())
        self.assertFalse(self.cur_order_round.is_over())
        self.assertFalse(self.next_order_round.is_over())

    def test_is_open_property(self):
        self.assertFalse(self.prev_order_round.is_open)
        self.assertTrue(self.cur_order_round.is_open)
        self.assertFalse(self.next_order_round.is_open)

    @skip("This test also fails because some weird stuff with get_current_order_round")
    def test_is_current(self):
        self.assertFalse(self.prev_order_round.is_current())
        self.assertTrue(self.cur_order_round.is_current())
        self.assertFalse(self.next_order_round.is_current())

    def test_suppliers_with_no_orders(self):
        self.assertEqual(self.cur_order_round.suppliers(), [])

    def test_suppliers_with_paid_and_unpaid_orders(self):
        round = OrderRoundFactory()
        supplier1 = SupplierFactory()
        supplier2 = SupplierFactory()
        paid_order = OrderFactory(paid=True, finalized=True, order_round=round)
        finalized_order = OrderFactory(paid=False, finalized=True, order_round=round)
        supplier1_orderproduct = OrderProductFactory(product__supplier=supplier1, order=paid_order)
        supplier2_orderproduct = OrderProductFactory(product__supplier=supplier2, order=finalized_order)
        self.assertItemsEqual(round.suppliers(), [supplier1])

    def test_supplier_total_order_sum_with_one_order(self):
        round = OrderRoundFactory()
        supplier1 = SupplierFactory()
        paid_order = OrderFactory(paid=True, finalized=True, order_round=round)
        supplier1_orderproduct = OrderProductFactory(product__supplier=supplier1, order=paid_order)
        self.assertItemsEqual(round.suppliers(), [supplier1])

        self.assertEqual(round.supplier_total_order_sum(supplier1),
                         supplier1_orderproduct.product.base_price * supplier1_orderproduct.amount)

    def test_supplier_total_order_sum_with_multiple_orders(self):
        round = OrderRoundFactory()
        supplier1 = SupplierFactory()
        supplier1_orderproduct1 = OrderProductFactory(product__supplier=supplier1, order__order_round=round,
                                                      order__paid=True, order__finalized=True)
        supplier1_orderproduct2 = OrderProductFactory(product__supplier=supplier1, order__order_round=round,
                                                      order__paid=True, order__finalized=True)

        self.assertEqual(round.supplier_total_order_sum(supplier1),
                         (supplier1_orderproduct1.product.base_price * supplier1_orderproduct1.amount) +
                         (supplier1_orderproduct2.product.base_price * supplier1_orderproduct2.amount))

    def test_total_order_sum(self):
        round = OrderRoundFactory()
        orderproduct1 = OrderProductFactory(order__order_round=round,
                                            order__paid=True,
                                            order__finalized=True)
        orderproduct2 = OrderProductFactory(order__order_round=round,
                                            order__paid=True,
                                            order__finalized=True)
        orderproduct3 = OrderProductFactory(order__order_round=round,
                                            order__paid=False,
                                            order__finalized=False)

        self.assertEqual(round.total_order_sum(),
            (orderproduct1.product.base_price * orderproduct1.amount) +
            (orderproduct2.product.base_price * orderproduct2.amount))

    def test_total_corrections_with_no_corrections(self):
        round = OrderRoundFactory()
        self.assertEqual(round.total_corrections(),
            {'supplier_inc': 0, 'voko_inc': 0, 'supplier_exc': 0})

    def test_total_corrections(self):
        round = OrderRoundFactory()
        corr1 = OrderProductCorrectionFactory(order_product__order__order_round=round, charge_supplier=True)
        corr2 = OrderProductCorrectionFactory(order_product__order__order_round=round, charge_supplier=False)
        self.assertEqual(round.total_corrections(),
            {'supplier_inc': corr1.calculate_refund(),
             'voko_inc': corr2.calculate_refund(),
             'supplier_exc': corr1.calculate_supplier_refund()})

    def test_total_profit_without_corrections(self):
        round = OrderRoundFactory()
        orderprod1 = OrderProductFactory(order__order_round=round, order__paid=True)
        self.assertEqual(round.total_profit(), orderprod1.product.profit * orderprod1.amount)

    @skip("TODO: Think out logic")
    def test_total_profit_with_corrections(self):
        round = OrderRoundFactory()
        orderprod1 = OrderProductFactory(order__order_round=round, order__paid=True)
        ordercorr1 = OrderProductCorrectionFactory(order_product__order__order_round=round,
                                                   order_product__order__paid=True)
        # TODO: How do we handle (partly) lost profit of corrections?

    def test_number_of_orders_with_no_orders(self):
        round = OrderRoundFactory()
        self.assertEqual(round.number_of_orders(), 0)

    def test_number_of_orders_with_paid_and_unpaid_orders(self):
        round = OrderRoundFactory()
        paid1 = OrderFactory(order_round=round, paid=True)
        paid2 = OrderFactory(order_round=round, paid=True)
        paid3 = OrderFactory(order_round=round, paid=True)
        unpaid1 = OrderFactory(order_round=round, paid=False)
        unpaid2 = OrderFactory(order_round=round, paid=False, finalized=True)
        self.assertEqual(round.number_of_orders(), 3)
示例#43
0
 def test_number_of_orders_with_no_orders(self):
     round = OrderRoundFactory()
     self.assertEqual(round.number_of_orders(), 0)
示例#44
0
 def test_total_profit_without_corrections(self):
     round = OrderRoundFactory()
     orderprod1 = OrderProductFactory(order__order_round=round, order__paid=True)
     self.assertEqual(round.total_profit(), orderprod1.product.profit * orderprod1.amount)