def test_calculate_refund_when_0_percent_supplied(self): round = OrderRoundFactory() corr = OrderProductCorrectionFactory(order_product__order__order_round=round, order_product__product__order_round=round, supplied_percentage=0) self.assertEqual(corr.calculate_refund(), corr.order_product.total_retail_price)
def test_that_balance_is_removed_upon_deletion_of_queryset(self): OrderProductCorrectionFactory() OrderProductCorrectionFactory() self.assertEqual(len(Balance.objects.all()), 2) OrderProductCorrection.objects.all().delete() self.assertEqual(len(Balance.objects.all()), 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_that_credit_is_not_overwritten_on_second_save(self): corr = OrderProductCorrectionFactory() credit_id = corr.credit.pk corr.save() corr = OrderProductCorrection.objects.get() self.assertEqual(corr.credit.pk, credit_id)
def test_that_credit_is_not_overwritten_on_second_save(self): corr = OrderProductCorrectionFactory() credit_id = corr.credit.pk corr.save() corr = OrderProductCorrection.objects.get() self.assertEqual(corr.credit.pk, credit_id)
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)
def test_calculate_supplier_refund_with_simple_values(self): round = OrderRoundFactory() corr = OrderProductCorrectionFactory(order_product__order__order_round=round, order_product__product__order_round=round, order_product__product__base_price=10, order_product__amount=2, supplied_percentage=25) self.assertEqual(corr.calculate_supplier_refund(), Decimal('15'))
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'))
def test_no_supplier_refund_ignores_corrections_where_charge_supplier_is_false(self): round = OrderRoundFactory() corr = OrderProductCorrectionFactory(order_product__order__order_round=round, order_product__product__order_round=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'))
def test_that_credit_is_created_on_save(self): self.assertFalse(Balance.objects.all().exists()) corr = OrderProductCorrectionFactory() self.assertEqual(corr.credit.user, corr.order_product.order.user) self.assertEqual(corr.credit.amount, corr.calculate_refund()) self.assertEqual(corr.credit.notes, "Correctie in ronde %s, %dx %s, geleverd: %s%%" % (corr.order_product.product.order_round.id, corr.order_product.amount, corr.order_product.product.name, corr.supplied_percentage))
def test_calculate_supplier_refund_with_complex_values(self): round = OrderRoundFactory() corr = OrderProductCorrectionFactory(order_product__order__order_round=round, order_product__product__order_round=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'))
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'))
def test_that_credit_is_created_on_save(self): self.assertFalse(Balance.objects.all().exists()) corr = OrderProductCorrectionFactory() self.assertEqual(corr.credit.user, corr.order_product.order.user) self.assertEqual(corr.credit.amount, corr.calculate_refund()) self.assertEqual( corr.credit.notes, "Correctie in ronde %s, %dx %s, geleverd: %s%%" % (corr.order_product.product.order_round.id, corr.order_product.amount, corr.order_product.product.name, corr.supplied_percentage))
def test_calculate_refund_with_complex_values(self): round = OrderRoundFactory(markup_percentage=7.9) corr = OrderProductCorrectionFactory(order_product__order__order_round=round, order_product__product__order_round=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'))
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'))
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'))
def test_calculate_refund_with_simple_values(self): order_round = OrderRoundFactory(markup_percentage=7) 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) original_retail_price = corr.order_product.product.retail_price self.assertEqual(original_retail_price, Decimal('10.70')) self.assertEqual(corr.calculate_refund(), Decimal('16.05'))
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() })
def test_that_balance_is_removed_upon_deletion_of_single_item(self): corr = OrderProductCorrectionFactory() self.assertEqual(len(Balance.objects.all()), 1) corr.delete() self.assertEqual(len(Balance.objects.all()), 0)
def test_that_balance_is_removed_upon_deletion_of_single_item(self): corr = OrderProductCorrectionFactory() self.assertEqual(len(Balance.objects.all()), 1) corr.delete() self.assertEqual(len(Balance.objects.all()), 0)
def test_total_profit_with_corrections(self): order_round = OrderRoundFactory() OrderProductFactory(order__order_round=order_round, order__paid=True) OrderProductCorrectionFactory( order_product__order__order_round=order_round, order_product__order__paid=True)