Example #1
0
    def test_calculate_balance(self):
        available_calendar = CalendarFactory(
            activity__organizer=self.organizer)
        available_orders = OrderFactory.create_batch(
            size=3,
            calendar=available_calendar,
            status='approved',
            fee=0,
            amount=factory.Iterator([20000, 30000]))

        unavailable_calendar = CalendarFactory(
            activity__organizer=self.organizer)
        unavailable_orders = OrderFactory.create_batch(
            size=4,
            calendar=unavailable_calendar,
            status='approved',
            fee=0,
            amount=factory.Iterator([20000, 30000]))

        status = [*['available'] * 3, *['unavailable'] * 4]

        BalanceLogFactory.create_batch(
            size=7,
            order=factory.Iterator([*available_orders, *unavailable_orders]),
            organizer=self.organizer,
            status=factory.Iterator(status))

        task = CalculateOrganizerBalanceTask()
        task.delay(organizer_ids=[self.organizer.id])

        balance = Balance.objects.get(id=self.organizer.balance.id)
        self.assertEqual(balance.available, 70000)
        self.assertEqual(balance.unavailable, 100000)
Example #2
0
    def create_orders(self):
        self.stdout.write('Creando orders')
        orders = list()
        fee = self.create_fee()
        for calendar in self.calendars:
            size = self.get_quantity()
            quantity = size
            if calendar.available_capacity < 1:
                continue
            orders.append(
                OrderFactory.create_batch(size,
                                          calendar=calendar,
                                          student=factory.Iterator(
                                              Student.objects.all(),
                                              cycle=True),
                                          fee=fee,
                                          fee_detail={},
                                          quantity=quantity))

        for o in self.flat_list(orders):
            fee_detail = Order.get_fee_detail(o, False, o.payment, None)
            fee = fee_detail.get('total_fee')
            o.fee, o.fee_detail = o.fee, fee_detail
            o.save()

        return self.flat_list(orders)
Example #3
0
 def setUp(self):
     super(ListAndCreateOrganizerMessageViewTest, self).setUp()
     self.url = reverse('messages:list_and_create')
     self.calendar = CalendarFactory(activity__organizer=self.organizer)
     self.orders = OrderFactory.create_batch(3, calendar=self.calendar,
                                             status=Order.ORDER_APPROVED_STATUS)
     self.organizer_messages = OrganizerMessageFactory.create_batch(3, organizer=self.organizer,
                                                                    calendar=self.calendar)
     self.organizer_message_relation = OrganizerMessageStudentRelationFactory(
         organizer_message=self.organizer_messages[0],
         student=self.student,
     )
Example #4
0
    def setUp(self):
        self.organizer = OrganizerFactory()
        self.calendar = CalendarFactory(activity__organizer=self.organizer)
        self.organizer_message = OrganizerMessageFactory(
            calendar=self.calendar)
        self.orders = OrderFactory.create_batch(
            size=3, calendar=self.calendar, status=Order.ORDER_APPROVED_STATUS)

        self.assistants = []
        for order in self.orders:
            self.assistants.append(
                AssistantFactory(order=order,
                                 email=order.student.user.email,
                                 enrolled=True))
Example #5
0
    def setUp(self):
        super(OrdersAPITest, self).setUp()

        # Create Activities objects
        self.activity = ActivityFactory(organizer=self.organizer,
                                        published=True)
        self.other_activity = ActivityFactory(organizer=self.organizer,
                                              published=True)
        self.active_activity = ActivityFactory(published=True)
        self.inactive_activity = ActivityFactory()

        # Create Calendards objects
        self.calendar = mommy.make(Calendar, activity=self.activity)
        self.other_calendar = mommy.make(Calendar,
                                         activity=self.other_activity)
        self.free_calendar = mommy.make(Calendar,
                                        is_free=True,
                                        activity=self.active_activity,
                                        available_capacity=10)
        self.inactive_calendar = mommy.make(Calendar,
                                            activity=self.inactive_activity)
        self.full_calendar = mommy.make(Calendar,
                                        activity=self.active_activity,
                                        available_capacity=0)
        self.closed_enroll_calendar = mommy.make(Calendar,
                                                 activity=self.active_activity,
                                                 enroll_open=False)

        # Create Orders objects
        OrderFactory.create_batch(student=self.student, size=2)
        OrderFactory.create_batch(calendar=self.calendar, size=2)
        OrderFactory.create_batch(calendar=self.other_calendar, size=2)
        self.order = OrderFactory(student=self.student)
        self.another_other = OrderFactory()

        # URLs
        self.orders_by_activity_url = reverse(
            'orders:create_or_list_by_activity',
            kwargs={'activity_pk': self.activity.id})

        self.orders_by_student_url = reverse(
            'orders:list_by_student', kwargs={'student_pk': self.student.id})

        self.orders_by_organizer_url = reverse(
            'orders:list_by_organizer',
            kwargs={'organizer_pk': self.organizer.id})

        self.order_retrieve_url = reverse('orders:retrieve',
                                          kwargs={'order_pk': self.order.id})

        self.another_order_retrieve_url = reverse(
            'orders:retrieve', kwargs={'order_pk': self.another_other.id})

        self.create_order_url = reverse(
            'orders:create_or_list_by_activity',
            kwargs={'activity_pk': self.active_activity.id})

        self.create_inactive_activity_order_url = reverse(
            'orders:create_or_list_by_activity',
            kwargs={'activity_pk': self.inactive_activity.id})

        # Set permissions
        permission = Permission.objects.get_by_natural_key(
            'add_order', 'orders', 'order')
        permission.user_set.add(self.student.user)

        # counts
        self.orders_count = Order.objects.all().count()
        self.student_orders_count = Order.objects.filter(
            student=self.student).count()
        self.activity_orders_count = Order.objects.filter(
            calendar=self.calendar).count()
        self.organizer_orders_count = Order.objects. \
            filter(calendar__activity__organizer=self.organizer).count()