本文整理汇总了Python中brambling.tests.factories.OrderFactory.add_discount方法的典型用法代码示例。如果您正苦于以下问题:Python OrderFactory.add_discount方法的具体用法?Python OrderFactory.add_discount怎么用?Python OrderFactory.add_discount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brambling.tests.factories.OrderFactory
的用法示例。
在下文中一共展示了OrderFactory.add_discount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OrderAlertMailerWithUnconfirmedCheckPayments
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
class OrderAlertMailerWithUnconfirmedCheckPayments(TestCase):
def setUp(self):
event = EventFactory()
self.order = OrderFactory(event=event, email='[email protected]')
transaction = TransactionFactory(event=event, order=self.order,
amount=130, method=Transaction.CHECK,
is_confirmed=False)
item = ItemFactory(event=event, name='Multipass')
item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')
discount = DiscountFactory(amount=30, discount_type='percent',
event=event, item_options=[item_option1])
self.order.add_to_cart(item_option1)
self.order.add_to_cart(item_option2)
self.order.add_discount(discount)
self.order.mark_cart_paid(transaction)
self.mailer = OrderAlertMailer(transaction, site='dancerfly.com',
secure=True)
self.event_name = event.name
def test_body_plaintext(self):
body = self.mailer.render_body(self.mailer.get_context_data(),
plaintext=True)
self.assertIn("keep an eye on your mail", body)
示例2: test_comped__sends_email
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
def test_comped__sends_email(self):
"""A successful completion with fully-comped items should send a receipt email and an alert email."""
organization = OrganizationFactory()
owner = PersonFactory()
OrganizationMember.objects.create(
person=owner,
organization=organization,
role=OrganizationMember.OWNER,
)
event = EventFactory(
collect_housing_data=False,
organization=organization,
)
order = OrderFactory(event=event)
item = ItemFactory(event=event)
item_option = ItemOptionFactory(price=100, item=item)
discount = DiscountFactory(amount=100, discount_type='percent', event=event, item_options=[item_option])
order.add_to_cart(item_option)
order.add_to_cart(item_option)
order.add_discount(discount)
view = SummaryView()
view.request = self.factory.post('/')
view.request.user = AnonymousUser()
view.event = event
view.order = order
self.assertEqual(len(mail.outbox), 0)
response = view.post(view.request)
self.assertEqual(response.status_code, 302)
self.assertEqual(len(mail.outbox), 2)
示例3: OrderAlertMailerForNonUserOrderTestCase
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
class OrderAlertMailerForNonUserOrderTestCase(TestCase):
def setUp(self):
event = EventFactory()
self.order = OrderFactory(event=event, email='[email protected]')
transaction = TransactionFactory(event=event, order=self.order,
amount=130)
item = ItemFactory(event=event, name='Multipass')
item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')
discount = DiscountFactory(amount=30, discount_type='percent',
event=event, item_options=[item_option1])
self.order.add_to_cart(item_option1)
self.order.add_to_cart(item_option2)
self.order.add_discount(discount)
self.order.mark_cart_paid(transaction)
self.mailer = OrderAlertMailer(transaction, site='dancerfly.com',
secure=True)
self.event_name = event.name
def test_subject(self):
subject = self.mailer.render_subject(self.mailer.get_context_data())
expected_subject = ('[{event_name}] New purchase by {order_email}'
.format(event_name=self.event_name,
order_email=self.order.email))
self.assertEqual(subject, expected_subject)
示例4: test_summary_data__base
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
def test_summary_data__base(self):
"""
Test that get_summary_data returns correct values for savings and
total cost.
"""
event = EventFactory()
order = OrderFactory(event=event)
item = ItemFactory(event=event)
item_option = ItemOptionFactory(price=100, item=item)
discount = DiscountFactory(amount=20, event=event, item_options=[item_option])
order.add_to_cart(item_option)
summary_data = order.get_summary_data()
self.assertEqual(summary_data['gross_cost'], 100)
self.assertEqual(summary_data['total_savings'], 0)
self.assertEqual(summary_data['net_cost'], 100)
order.add_discount(discount)
summary_data = order.get_summary_data()
self.assertEqual(summary_data['gross_cost'], 100)
self.assertEqual(summary_data['total_savings'], -20)
self.assertEqual(summary_data['net_cost'], 80)
示例5: test_summary_data__itemoption_deleted
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
def test_summary_data__itemoption_deleted(self):
"""
Test that get_summary_data returns correct values for savings and
total cost even if an itemoption was deleted.
"""
event = EventFactory()
order = OrderFactory(event=event)
item = ItemFactory(event=event)
item_option = ItemOptionFactory(price=100, item=item)
discount = DiscountFactory(amount=20, event=event, item_options=[item_option])
order.add_to_cart(item_option)
summary_data = order.get_summary_data()
self.assertEqual(summary_data['gross_cost'], 100)
self.assertEqual(summary_data['total_savings'], 0)
self.assertEqual(summary_data['net_cost'], 100)
order.add_discount(discount)
summary_data = order.get_summary_data()
self.assertEqual(summary_data['gross_cost'], 100)
self.assertEqual(summary_data['total_savings'], -20)
self.assertEqual(summary_data['net_cost'], 80)
item_option.delete()
# Make sure that the value isn't cached.
order = Order.objects.get(pk=order.pk)
summary_data = order.get_summary_data()
self.assertEqual(summary_data['gross_cost'], 100)
self.assertEqual(summary_data['total_savings'], -20)
self.assertEqual(summary_data['net_cost'], 80)
示例6: test_summary_data__discount_changed
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
def test_summary_data__discount_changed(self):
"""
Test that get_summary_data returns correct values for savings and
total cost even if a discount was changed.
"""
event = EventFactory()
order = OrderFactory(event=event)
transaction = TransactionFactory(event=event, order=order)
item = ItemFactory(event=event)
item_option = ItemOptionFactory(price=100, item=item)
discount = DiscountFactory(amount=20, event=event, item_options=[item_option])
order.add_to_cart(item_option)
order.add_discount(discount)
order.mark_cart_paid(transaction)
summary_data = order.get_summary_data()
self.assertEqual(summary_data['gross_cost'], 100)
self.assertEqual(summary_data['total_savings'], -20)
self.assertEqual(summary_data['net_cost'], 80)
discount.amount = 100
discount.save()
# Make sure that the value isn't cached.
order = Order.objects.get(pk=order.pk)
summary_data = order.get_summary_data()
self.assertEqual(summary_data['gross_cost'], 100)
self.assertEqual(summary_data['total_savings'], -20)
self.assertEqual(summary_data['net_cost'], 80)
示例7: test_cart_discount_caching
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
def test_cart_discount_caching(self):
"""
Test that the cached discount information is correct.
"""
event = EventFactory()
order = OrderFactory(event=event)
item = ItemFactory(event=event)
item_option = ItemOptionFactory(price=100, item=item)
discount = DiscountFactory(amount=20, event=event, item_options=[item_option])
order.add_to_cart(item_option)
order.add_discount(discount)
discount.delete()
self.assertTrue(order.bought_items.exists())
boughtitem = order.bought_items.all()[0]
self.assertTrue(boughtitem.discounts.exists())
boughtitemdiscount = boughtitem.discounts.all()[0]
self.assertTrue(boughtitemdiscount.discount_id is None)
self.assertEqual(boughtitemdiscount.name, discount.name)
self.assertEqual(boughtitemdiscount.code, discount.code)
self.assertEqual(boughtitemdiscount.discount_type, discount.discount_type)
self.assertEqual(boughtitemdiscount.amount, discount.amount)
self.assertEqual(boughtitemdiscount.savings(), 20)
示例8: ItemOptionViewSetTestCase
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
class ItemOptionViewSetTestCase(TestCase):
def setUp(self):
self.factory = RequestFactory()
event = EventFactory()
self.order = OrderFactory(event=event, email='[email protected]')
self.transaction = TransactionFactory(
event=event, order=self.order, amount=130,
method=Transaction.CHECK, is_confirmed=False)
item = ItemFactory(event=event, name='Multipass')
item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')
discount = DiscountFactory(amount=30, discount_type='percent',
event=event, item_options=[item_option1])
self.order.add_to_cart(item_option1)
self.order.add_to_cart(item_option2)
self.order.add_discount(discount)
self.order.mark_cart_paid(self.transaction)
order2 = OrderFactory(event=event, email='[email protected]')
order2.add_to_cart(item_option2)
transaction2 = TransactionFactory(event=event, order=self.order,
amount=130, method=Transaction.CHECK,
is_confirmed=True)
order2.mark_cart_paid(transaction2)
self.order3 = OrderFactory(event=event, email='caes[email protected]')
self.order3.add_to_cart(item_option1)
transaction3 = TransactionFactory(event=event, order=self.order3,
amount=130, method=Transaction.CHECK,
is_confirmed=True)
self.order3.mark_cart_paid(transaction3)
self.viewset = ItemOptionViewSet()
self.viewset.request = self.factory.get('/')
self.viewset.request.user = self.order.person
def test_taken_counts(self):
qs = self.viewset.get_queryset()
self.assertEqual([2, 2], [int(p.taken) for p in qs])
def test_exclude_refunded(self):
"""should exclude refunded items from the taken count"""
self.transaction.refund()
qs = self.viewset.get_queryset()
self.assertEqual([1, 1], [int(p.taken) for p in qs])
def test_exclude_transferred(self):
"""should exclude transferred items from the taken count"""
for item in self.order3.bought_items.all():
item.status = BoughtItem.TRANSFERRED
item.save()
qs = self.viewset.get_queryset()
self.assertEqual([1, 2], [int(p.taken) for p in qs])
示例9: AddDiscountTestCase
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
class AddDiscountTestCase(TestCase):
def setUp(self):
self.event = EventFactory()
self.order = OrderFactory(event=self.event)
self.item = ItemFactory(event=self.event)
self.item_option = ItemOptionFactory(price=100, item=self.item)
self.order.add_to_cart(self.item_option)
self.discount = DiscountFactory(amount=20, event=self.event, item_options=[self.item_option])
def test_add_discount_creates_boughtitemdiscount(self):
created = self.order.add_discount(self.discount)
self.assertTrue(created)
bought_item = self.order.bought_items.get()
self.assertEqual(bought_item.discounts.count(), 1)
bought_item_discount = bought_item.discounts.get()
self.assertEqual(bought_item_discount.discount, self.discount)
def test_add_discount_does_not_duplicate_discounts(self):
existing_bought_item_discount = BoughtItemDiscount.objects.create(
discount=self.discount,
bought_item=self.order.bought_items.get(),
name=self.discount.name,
code=self.discount.code,
discount_type=self.discount.discount_type,
amount=self.discount.amount,
)
created = self.order.add_discount(self.discount)
self.assertFalse(created)
bought_item = self.order.bought_items.get()
self.assertEqual(bought_item.discounts.count(), 1)
bought_item_discount = bought_item.discounts.get()
self.assertEqual(bought_item_discount, existing_bought_item_discount)
def test_created_true_if_any_discounts_created(self):
item_option2 = ItemOptionFactory(price=100, item=self.item)
self.discount.item_options.add(item_option2)
self.order.add_to_cart(item_option2)
BoughtItemDiscount.objects.create(
discount=self.discount,
bought_item=self.order.bought_items.get(item_option=self.item_option),
name=self.discount.name,
code=self.discount.code,
discount_type=self.discount.discount_type,
amount=self.discount.amount,
)
created = self.order.add_discount(self.discount)
self.assertTrue(created)
bought_item = self.order.bought_items.get(item_option=item_option2)
self.assertEqual(bought_item.discounts.count(), 1)
bought_item_discount = bought_item.discounts.get()
self.assertEqual(bought_item_discount.discount, self.discount)
示例10: test_summary_data__items_no_transaction__discount
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
def test_summary_data__items_no_transaction__discount(self):
"""
Items without transactions are included in summary data.
"""
event = EventFactory()
order = OrderFactory(event=event)
item = ItemFactory(event=event)
item_option = ItemOptionFactory(price=100, item=item)
discount = DiscountFactory(amount=20, event=event, item_options=[item_option])
order.add_to_cart(item_option)
order.add_discount(discount)
summary_data = order.get_summary_data()
self.assertEqual(summary_data['gross_cost'], 100)
self.assertEqual(summary_data['total_savings'], -20)
self.assertEqual(summary_data['net_cost'], 80)
示例11: OrderReceiptMailerWithUnconfirmedCheckPayments
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
class OrderReceiptMailerWithUnconfirmedCheckPayments(TestCase):
def setUp(self):
event = EventFactory()
self.order = OrderFactory(event=event, email='[email protected]')
transaction = TransactionFactory(event=event, order=self.order,
amount=130, method=Transaction.CHECK,
is_confirmed=False)
item = ItemFactory(event=event, name='Multipass')
item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')
discount = DiscountFactory(amount=30, discount_type='percent',
event=event, item_options=[item_option1])
self.order.add_to_cart(item_option1)
self.order.add_to_cart(item_option2)
self.order.add_discount(discount)
self.order.mark_cart_paid(transaction)
self.mailer = OrderReceiptMailer(transaction, site='dancerfly.com',
secure=True)
self.event = event
def test_still_time_to_mail_check(self):
self.event.check_postmark_cutoff = date.today() + timedelta(days=5)
body = self.mailer.render_body(self.mailer.get_context_data(),
plaintext=True)
self.assertIn("Checks must be postmarked no later than", body)
def test_past_postmark_cutoff(self):
self.event.check_postmark_cutoff = date.today() - timedelta(days=5)
body = self.mailer.render_body(self.mailer.get_context_data(),
plaintext=True)
self.assertIn("Payment was due to be postmarked", body)
def test_postmark_cutoff_today(self):
self.event.check_postmark_cutoff = date.today()
body = self.mailer.render_body(self.mailer.get_context_data(),
plaintext=True)
self.assertIn("postmarked no later than today", body)
示例12: OrderReceiptMailerForNonUserTestCase
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
class OrderReceiptMailerForNonUserTestCase(TestCase):
def setUp(self):
event = EventFactory()
self.order = OrderFactory(event=event, email='[email protected]')
transaction = TransactionFactory(event=event, order=self.order,
amount=130)
item = ItemFactory(event=event, name='Multipass')
item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')
discount = DiscountFactory(amount=30, discount_type='percent',
event=event, item_options=[item_option1])
self.order.add_to_cart(item_option1)
self.order.add_to_cart(item_option2)
self.order.add_discount(discount)
self.order.mark_cart_paid(transaction)
self.mailer = OrderReceiptMailer(transaction, site='dancerfly.com',
secure=True)
def test_recipients(self):
self.assertEqual(self.mailer.get_recipients(), [self.order.email])
示例13: OrderReceiptMailerTestCase
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
class OrderReceiptMailerTestCase(TestCase):
def setUp(self):
self.person = PersonFactory()
event = EventFactory()
owner = PersonFactory()
OrganizationMember.objects.create(
person=owner,
organization=event.organization,
role=OrganizationMember.OWNER,
)
self.order = OrderFactory(event=event, person=self.person)
transaction = TransactionFactory(event=event, order=self.order,
amount=130)
item = ItemFactory(event=event, name='Multipass')
item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')
discount = DiscountFactory(amount=30, discount_type='percent',
event=event, item_options=[item_option1])
self.order.add_to_cart(item_option1)
self.order.add_to_cart(item_option2)
self.order.add_discount(discount)
self.order.mark_cart_paid(transaction)
self.mailer = OrderAlertMailer(transaction, site='dancerfly.com',
secure=True)
self.event_name = event.name
self.discount_amount = format_money(discount.amount, event.currency)
self.total_amount = format_money(transaction.amount, event.currency)
self.option1 = '{0} ({1})'.format(item.name, item_option1.name)
self.option2 = '{0} ({1})'.format(item.name, item_option1.name)
self.item_price = format_money(item_option1.price, event.currency)
def test_render_plaintext(self):
body = self.mailer.render_body(self.mailer.get_context_data(),
plaintext=True)
self.assertIn(self.total_amount, body)
self.assertIn(self.option1, body)
self.assertIn(self.option2, body)
self.assertNotIn("outstanding check payments", body)
def test_render_inlined(self):
body = self.mailer.render_body(self.mailer.get_context_data(),
inlined=True)
self.assertIn(self.option1, body)
self.assertIn(self.option2, body)
self.assertIn(self.total_amount, body)
def test_recipients(self):
self.assertSequenceEqual(self.mailer.get_recipients(),
[self.order.event.organization.members.get().email])
def test_recipients__notify_never(self):
person = self.order.event.organization.members.get()
person.notify_new_purchases = 'never'
person.save()
self.assertSequenceEqual(self.mailer.get_recipients(),
[])
def test_recipients__notify_daily(self):
person = self.order.event.organization.members.get()
person.notify_new_purchases = 'daily'
person.save()
self.assertSequenceEqual(self.mailer.get_recipients(),
[])
def test_subject(self):
subject = self.mailer.render_subject(self.mailer.get_context_data())
expected_subject = ('[{event_name}] New purchase by {person_name}'
.format(event_name=self.event_name,
person_name=self.person.get_full_name()))
self.assertEqual(subject, expected_subject)
def test_body_non_inlined_non_plaintext(self):
body = self.mailer.render_body(self.mailer.get_context_data(),
inlined=False, plaintext=False)
self.assertIn(self.option1, body)
self.assertIn(self.option2, body)
self.assertIn(self.total_amount, body)
def test_subject_apostrophe(self):
event = EventFactory(name="Han & Leia's Wedding!")
self.person = PersonFactory(first_name="Ma'ayan", last_name="Plaut")
self.event_name = event.name
self.order = OrderFactory(event=event, person=self.person)
transaction = TransactionFactory(event=event, order=self.order, amount=130)
self.mailer = OrderAlertMailer(transaction, site='dancerfly.com',
secure=True)
subject = self.mailer.render_subject(self.mailer.get_context_data())
expected_subject = ('[{event_name}] New purchase by {person_name}'
.format(event_name=self.event_name,
person_name=self.person.get_full_name()))
self.assertEqual(subject, expected_subject)
示例14: OrderReceiptMailerTestCase
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
class OrderReceiptMailerTestCase(TestCase):
def setUp(self):
self.person = PersonFactory()
event = EventFactory()
self.order = OrderFactory(event=event, person=self.person)
transaction = TransactionFactory(event=event, order=self.order,
amount=130)
item = ItemFactory(event=event, name='Multipass')
item_option1 = ItemOptionFactory(price=100, item=item, name='Gold')
item_option2 = ItemOptionFactory(price=60, item=item, name='Silver')
discount = DiscountFactory(amount=30, discount_type='percent',
event=event, item_options=[item_option1])
self.order.add_to_cart(item_option1)
self.order.add_to_cart(item_option2)
self.order.add_discount(discount)
self.order.mark_cart_paid(transaction)
self.mailer = OrderReceiptMailer(transaction, site='dancerfly.com',
secure=True)
self.event_name = event.name
self.discount_amount = format_money(discount.amount, event.currency)
self.total_amount = format_money(transaction.amount, event.currency)
self.option1 = '{0} ({1})'.format(item.name, item_option1.name)
self.option2 = '{0} ({1})'.format(item.name, item_option1.name)
self.item_price = format_money(item_option1.price, event.currency)
def test_render_plaintext(self):
body = self.mailer.render_body(self.mailer.get_context_data(),
plaintext=True)
self.assertIn(self.total_amount, body)
self.assertIn(self.discount_amount, body)
self.assertIn(self.item_price, body)
self.assertIn(self.option1, body)
self.assertIn(self.option2, body)
def test_render_inlined(self):
body = self.mailer.render_body(self.mailer.get_context_data(),
inlined=True)
self.assertIn(self.option1, body)
self.assertIn(self.option2, body)
self.assertIn(self.item_price, body)
self.assertIn(self.discount_amount, body)
self.assertIn(self.total_amount, body)
def test_recipients(self):
self.assertEqual(self.mailer.get_recipients(), [self.person.email])
def test_subject(self):
subject = self.mailer.render_subject(self.mailer.get_context_data())
expected_subject = ('[{event_name}] Receipt for order {order_code}'
.format(event_name=self.event_name,
order_code=self.order.code))
self.assertEqual(subject, expected_subject)
def test_body_non_inlined_non_plaintext(self):
body = self.mailer.render_body(self.mailer.get_context_data(),
inlined=False, plaintext=False)
self.assertIn(self.option1, body)
self.assertIn(self.option2, body)
self.assertIn(self.item_price, body)
self.assertIn(self.discount_amount, body)
self.assertIn(self.total_amount, body)
def test_subject_apostrophe(self):
event = EventFactory(name="Han & Leia's Wedding")
self.event_name = event.name
self.order = OrderFactory(event=event, person=self.person)
transaction = TransactionFactory(event=event, order=self.order,
amount=130)
self.mailer = OrderReceiptMailer(transaction, site='dancerfly.com',
secure=True)
subject = self.mailer.render_subject(self.mailer.get_context_data())
expected_subject = ('[{event_name}] Receipt for order {order_code}'
.format(event_name=self.event_name,
order_code=self.order.code))
self.assertEqual(subject, expected_subject)
示例15: test_summary_data__transfer
# 需要导入模块: from brambling.tests.factories import OrderFactory [as 别名]
# 或者: from brambling.tests.factories.OrderFactory import add_discount [as 别名]
def test_summary_data__transfer(self):
"""Items sent or received in a transfer shouldn't count towards net cost and savings"""
event = EventFactory()
order = OrderFactory(
event=event,
person=PersonFactory(),
)
person2 = PersonFactory()
transaction = TransactionFactory(
event=event,
order=order,
is_confirmed=True,
transaction_type=Transaction.PURCHASE,
amount=80,
)
item = ItemFactory(event=event)
item_option = ItemOptionFactory(price=100, item=item)
discount = DiscountFactory(amount=20, event=event, item_options=[item_option])
order.add_to_cart(item_option)
order.add_discount(discount)
order.mark_cart_paid(transaction)
bought_item = transaction.bought_items.get()
invite = TransferInvite.get_or_create(
request=Mock(user=person2, session={}),
email=person2.email,
content=bought_item,
)[0]
invite.accept()
summary_data = order.get_summary_data()
self.assertEqual(summary_data['gross_cost'], 100)
self.assertEqual(summary_data['total_savings'], -20)
self.assertEqual(summary_data['total_refunds'], 0)
self.assertEqual(summary_data['total_payments'], 80)
self.assertEqual(summary_data['net_cost'], 80)
self.assertEqual(summary_data['net_balance'], 0)
self.assertEqual(summary_data['unconfirmed_check_payments'], False)
transactions = summary_data['transactions']
self.assertEqual(len(transactions), 2)
transfer_txn, transfer_txn_dict = transactions.items()[0]
self.assertEqual(transfer_txn.transaction_type, Transaction.TRANSFER)
self.assertEqual(transfer_txn_dict['items'], [bought_item])
self.assertEqual(transfer_txn_dict['gross_cost'], 0)
self.assertEqual(transfer_txn_dict['discounts'], [])
self.assertEqual(transfer_txn_dict['total_savings'], 0)
self.assertEqual(transfer_txn_dict['net_cost'], 0)
purchase_txn, purchase_txn_dict = transactions.items()[1]
self.assertEqual(purchase_txn.transaction_type, Transaction.PURCHASE)
self.assertEqual(purchase_txn_dict['items'], [bought_item])
self.assertEqual(purchase_txn_dict['gross_cost'], 100)
self.assertEqual(purchase_txn_dict['discounts'], [bought_item.discounts.first()])
self.assertEqual(purchase_txn_dict['total_savings'], -20)
self.assertEqual(purchase_txn_dict['net_cost'], 80)
order2 = Order.objects.get(event=event, person=person2)
summary_data2 = order2.get_summary_data()
self.assertEqual(summary_data2['gross_cost'], 0)
self.assertEqual(summary_data2['total_savings'], 0)
self.assertEqual(summary_data2['total_refunds'], 0)
self.assertEqual(summary_data2['total_payments'], 0)
self.assertEqual(summary_data2['net_cost'], 0)
self.assertEqual(summary_data2['net_balance'], 0)
self.assertEqual(summary_data2['unconfirmed_check_payments'], False)
transactions2 = summary_data2['transactions']
self.assertEqual(len(transactions2), 1)
transfer_txn2, transfer_txn2_dict = transactions.items()[0]
self.assertEqual(transfer_txn2.transaction_type, Transaction.TRANSFER)
self.assertEqual(transfer_txn2_dict['items'], [bought_item])
self.assertEqual(transfer_txn2_dict['gross_cost'], 0)
self.assertEqual(transfer_txn2_dict['discounts'], [])
self.assertEqual(transfer_txn2_dict['total_savings'], 0)
self.assertEqual(transfer_txn2_dict['net_cost'], 0)