Beispiel #1
0
    def test_08_order_payment(self):
        """Test basic order payment model behavior"""
        order = self.create_order()
        product = self.create_product()

        order.modify_item(product, 10)
        order.recalculate_total()

        payment = order.payments.model(
            order=order,
            currency='CHF',
            amount=Decimal('49.90'),
            payment_method='Mafia style',
        )

        # The descriptor cannot be used through create(), therefore
        # we need this stupid little dance
        payment.data = {'anything': 42}
        payment.save()

        order = Order.objects.get(pk=order.pk)
        self.assertAlmostEqual(order.paid, 0)

        payment.authorized = datetime.now()
        payment.save()

        order = Order.objects.get(pk=order.pk)
        self.assertAlmostEqual(order.balance_remaining,
                               order.total - payment.amount)

        self.assertEqual(order.payments.all()[0].data['anything'], 42)

        payment2 = order.payments.model(
            order=order.reload(),
            currency='EUR',  # mismatch!
            amount=Decimal('100'),
            payment_method='Whatever',
        )
        payment2.data = {}
        payment2.save()

        order2 = order.reload()

        # Shouldn't have changed
        self.assertAlmostEqual(order2.balance_remaining,
                               order.balance_remaining)
        self.assertNotEqual(order2.notes, order.notes)
    def test_08_order_payment(self):
        """Test basic order payment model behavior"""
        order = self.create_order()
        product = self.create_product()

        order.modify_item(product.variations.get(), 10)
        order.recalculate_total()

        payment = order.payments.model(
            order=order,
            currency='CHF',
            amount=Decimal('49.90'),
            payment_method='Mafia style',
            )

        # The descriptor cannot be used through create(), therefore
        # we need this stupid little dance
        payment.data = {'anything': 42}
        payment.save()

        order = Order.objects.get(pk=order.pk)
        self.assertAlmostEqual(order.paid, 0)

        payment.authorized = datetime.now()
        payment.save()

        order = Order.objects.get(pk=order.pk)
        self.assertAlmostEqual(order.balance_remaining, order.total - payment.amount)

        self.assertEqual(order.payments.all()[0].data['anything'], 42)

        payment2 = order.payments.model(
            order=order.reload(),
            currency='EUR', # mismatch!
            amount=Decimal('100'),
            payment_method='Whatever',
            )
        payment2.data = {}
        payment2.save()

        order2 = order.reload()

        # Shouldn't have changed
        self.assertAlmostEqual(order2.balance_remaining, order.balance_remaining)
        self.assertNotEqual(order2.notes, order.notes)