Beispiel #1
0
    def get_transaction_from_form_data(formset_data, update_of):
        first_form = formset_data[0]
        creator = User.objects.get(username=first_form['creator_username'])
        new_transaction = Transaction.new_transaction(
            creator,
            TransactionType.objects.get(
                name=TransactionTypeEnum.workout.value), formset_data,
            update_of)
        attendance_block_name = AttendanceBlockEnum.workout.value
        attendees_count = sum([a['attended'] for a in formset_data])
        reward = WorkoutTransactionController._get_reward(attendees_count)

        for atomic_data in formset_data:
            attended = atomic_data['attended']
            if attended:
                receiver = User.objects.get(
                    username=atomic_data['receiver_username'])
                Attendance.new_attendance(
                    receiver, 1,
                    AttendanceType.objects.get(
                        name=AttendanceTypeEnum.workout.value),
                    first_form['description'], first_form['date'],
                    new_transaction, attendance_block_name)

                Money.new_money(
                    receiver, reward,
                    MoneyType.objects.get(name=MoneyTypeEnum.workout.value),
                    first_form['description'], new_transaction)

        return new_transaction
Beispiel #2
0
    def test_is_valid_returns_true(self):

        attendance = Attendance.new_attendance(self.receiver, 1, self.att_type,
                                               'description', '2020-01-01',
                                               self.transaction, '10-11')

        other_date = Attendance.new_attendance(self.receiver, 1, self.att_type,
                                               'description', '2020-01-02',
                                               self.transaction, '10-11')

        other_time = Attendance.new_attendance(self.receiver, 1, self.att_type,
                                               'description', '2020-01-01',
                                               self.transaction, '11-12')

        other_user = Attendance.new_attendance(self.creator, 1, self.att_type,
                                               'description', '2020-01-01',
                                               self.transaction, '10-11')

        other_date.apply()
        other_time.apply()
        other_user.apply()

        self.assertTrue(other_date.counted)
        self.assertTrue(other_time.counted)
        self.assertTrue(other_user.counted)

        self.assertTrue(attendance.is_valid())
Beispiel #3
0
    def clean(self):
        if any(self.errors):
            return
        cleaned_data = self.forms[0].cleaned_data
        receiver_username = cleaned_data.get('receiver')
        date = cleaned_data.get('date')
        block = cleaned_data.get('block')
        attendance_block = AttendanceBlock.objects.get(name=block)
        receiver = User.objects.get(username=receiver_username)
        test_attendance = Attendance(related_transaction=None,
                                     receiver=receiver,
                                     value=0,
                                     type=None,
                                     description='',
                                     counted=False,
                                     update_timestamp=None,
                                     date=date,
                                     attendance_block=attendance_block)
        if not test_attendance.is_valid():
            self.forms[0].add_error(
                'block', 'Докладчик уже занимался чем-то в этот блок.\
                            Может быть вы перепутали докладчика или блок? \
                            Если все правильно, то обратитесь пожалуйста к банкиру, он разберется в чем дело.'
            )

        del test_attendance
    def get_transaction_from_form_data(formset_data, update_of):

        first_form = formset_data[0]
        creator = User.objects.get(username=first_form['creator_username'])

        new_transaction = Transaction.new_transaction(
            creator,
            TransactionType.objects.get(
                name=TransactionTypeEnum.fac_pass.value), formset_data,
            update_of)
        for atomic_data in formset_data:
            value = atomic_data['value']
            if value:
                receiver = User.objects.get(
                    username=atomic_data['receiver_username'])
                Money.new_money(
                    receiver, atomic_data['value'],
                    MoneyType.objects.get(name=MoneyTypeEnum.fac_pass.value),
                    first_form['description'], new_transaction)

                Attendance.new_attendance(
                    receiver, 1,
                    AttendanceType.objects.get(
                        name=AttendanceTypeEnum.fac_pass.value),
                    first_form['description'], first_form['date'],
                    new_transaction)

        return new_transaction
Beispiel #5
0
    def get_transaction_from_form_data(formset_data, update_of):

        first_form = formset_data[0]
        creator = User.objects.get(username=first_form['creator_username'])

        new_transaction = Transaction.new_transaction(
            creator,
            TransactionType.objects.get(
                name=TransactionTypeEnum.purchase.value), formset_data,
            update_of)
        money_type = MoneyType.objects.get(name=first_form['money_type'])
        attendance_type = AttendanceType.objects.get(
            name=AttendanceTypeEnum.book_certificate.value)
        for atomic_data in formset_data:
            value = atomic_data['value']
            if value:
                money_value = value
                certificate_value = 0
                receiver = User.objects.get(
                    username=atomic_data['receiver_username'])

                if money_type.name == MoneyTypeEnum.books.value:
                    money_value, certificate_value = PurchaseTransactionController._get_certificate_split(
                        receiver, value)
                if money_value:
                    Money.new_money(receiver, -money_value, money_type,
                                    first_form['description'], new_transaction)
                if certificate_value:
                    Attendance.new_attendance(receiver, -certificate_value,
                                              attendance_type,
                                              first_form['description'],
                                              datetime.date.today(),
                                              new_transaction)
        return new_transaction
Beispiel #6
0
    def get_transaction_from_form_data(formset_data, update_of):
        first_form = formset_data[0]
        creator = User.objects.get(username=first_form['creator_username'])
        new_transaction = Transaction.new_transaction(
            creator,
            TransactionType.objects.get(
                name=TransactionTypeEnum.lecture.value), formset_data,
            update_of)

        attendance_block_name = AttendanceBlockEnum.lecture.value
        money_type = MoneyType.objects.get(
            name=MoneyTypeEnum.fine_lecture.value)

        for atomic_data in formset_data:
            attended = atomic_data['attended']
            receiver = User.objects.get(
                username=atomic_data['receiver_username'])
            if attended:
                attendance_type_name = AttendanceTypeEnum.lecture_attend.value
            else:
                attendance_type_name = AttendanceTypeEnum.lecture_miss.value
                fine_value = receiver.account.get_next_missed_lec_penalty()
                Money.new_money(receiver, -fine_value, money_type,
                                first_form['description'], new_transaction)

            Attendance.new_attendance(
                receiver,
                1,
                AttendanceType.objects.get(name=attendance_type_name),
                first_form['description'],
                first_form['date'],
                new_transaction,
                attendance_block_name=attendance_block_name)

        return new_transaction
Beispiel #7
0
    def test_not_applies_when_clash(self):

        attendance = Attendance.new_attendance(self.receiver, 1, self.att_type,
                                               'description', '2020-01-01',
                                               self.transaction, '10-12')

        colapsing = Attendance.new_attendance(self.receiver, 1, self.att_type,
                                              'description', '2020-01-01',
                                              self.transaction, '11-13')

        attendance.apply()
        colapsing.apply()
        self.assertTrue(attendance.counted)
        self.assertFalse(colapsing.counted)
Beispiel #8
0
  def test_equator_study_fine_calc_with_activity(self):
    account = Account.objects.get(party=1, middle_name='Middle')

    lab_fine = LAB_PASS_NEEDED_EQUATOR * LAB_PENALTY
    # arithmetic progression
    obl_fine = (INITIAL_STEP_OBL_STD * 2 + (
        (OBL_STUDY_NEEDED_EQUATOR - 2) * STEP_OBL_STD)) * (OBL_STUDY_NEEDED_EQUATOR - 1) / 2

    user2 = User.objects.get(username='******')
    user = User.objects.get(username='******')

    TransactionState.objects.create(name=States.created.value)
    TransactionType.objects.create(name=TransactionTypeEnum.seminar.value)
    AttendanceType.objects.create(name=AttendanceTypeEnum.seminar_attend.value)

    transaction = Transaction.new_transaction(
        user2,
        TransactionType.objects.get(name=TransactionTypeEnum.seminar.value), {})
    attendance = Attendance.new_attendance(
        user, 1,
        AttendanceType.objects.get(
            name=AttendanceTypeEnum.seminar_attend.value), 'desc', '1111-11-11',
        transaction)
    attendance.counted = True
    attendance.save()

    fine_with_zero_activity = lab_fine + obl_fine

    self.assertEqual(account.get_obl_study_fine_equator(), obl_fine)
    self.assertEqual(account.get_lab_fine_equator(), lab_fine)

    self.assertEqual(account.get_final_study_fine(), fine_with_zero_activity)
Beispiel #9
0
    def test_is_valid_catches_clashes_properly(self):
        attendance = Attendance.new_attendance(self.receiver, 1, self.att_type,
                                               'description', '2020-01-01',
                                               self.transaction, '10-12')

        colapsing = Attendance.new_attendance(self.receiver, 1, self.att_type,
                                              'description', '2020-01-01',
                                              self.transaction, '11-13')

        colapsing.apply()

        self.assertFalse(attendance.is_valid())
        self.assertTrue(colapsing.is_valid())

        colapsing.undo()

        self.assertTrue(attendance.is_valid())
Beispiel #10
0
    def test_changes_states_properly(self):
        attendance = Attendance.new_attendance(self.receiver, 1, self.att_type,
                                               'description', '2020-01-01',
                                               self.transaction, '10-12')

        attendance.apply()
        self.assertTrue(attendance.counted)
        attendance.undo()
        self.assertFalse(attendance.counted)
Beispiel #11
0
    def get_transaction_from_form_data(formset_data, update_of):
        first_form = formset_data[0]

        mark = sum([
            int(first_form[key])
            for key in SeminarTransactionController._get_mark_keys()
        ])
        money_reward = SeminarTransactionController._get_reward_from_mark(mark)

        creator = User.objects.get(username=first_form['creator_username'])

        new_transaction = Transaction.new_transaction(
            creator,
            TransactionType.objects.get(
                name=TransactionTypeEnum.seminar.value), formset_data,
            update_of)

        reader = User.objects.get(username=first_form['receiver'])
        Attendance.new_attendance(
            reader, 1,
            AttendanceType.objects.get(
                name=AttendanceTypeEnum.seminar_pass.value),
            first_form['description'], first_form['date'], new_transaction,
            first_form['block'])

        Money.new_money(
            reader, money_reward,
            MoneyType.objects.get(name=MoneyTypeEnum.seminar_pass.value),
            first_form['description'], new_transaction)

        for atomic_data in formset_data:
            attended = atomic_data['attended']
            if attended:
                receiver = User.objects.get(
                    username=atomic_data['receiver_username'])
                Attendance.new_attendance(
                    receiver, 1,
                    AttendanceType.objects.get(
                        name=AttendanceTypeEnum.seminar_attend.value),
                    first_form['description'], first_form['date'],
                    new_transaction, first_form['block'])
        return new_transaction
Beispiel #12
0
 def get_transaction_from_form_data(formset_data, update_of):
     first_form = formset_data[0]
     creator = User.objects.get(username=first_form['creator_username'])
     new_transaction = Transaction.new_transaction(
         creator,
         TransactionType.objects.get(
             name=TransactionTypeEnum.fac_attend.value), formset_data,
         update_of)
     for atomic_data in formset_data:
         attended = atomic_data['attended']
         if attended:
             receiver = User.objects.get(
                 username=atomic_data['receiver_username'])
             Attendance.new_attendance(
                 receiver, 1,
                 AttendanceType.objects.get(
                     name=AttendanceTypeEnum.fac_attend.value),
                 first_form['description'], first_form['date'],
                 new_transaction, first_form['block'])
     return new_transaction
    def get_transaction_from_form_data(formset_data, update_of):
        first_form = formset_data[0]
        creator = User.objects.get(username=first_form['creator_username'])
        money_type = MoneyType.objects.get(name=first_form['money_type'])
        print(money_type)
        print(first_form)

        new_transaction = Transaction.new_transaction(
            creator,
            TransactionType.objects.get(
                name=TransactionTypeEnum.activity.value), formset_data,
            update_of)

        places = {
            key:
            list(filter(lambda t, k=key: t['place'] == str(k), formset_data))
            for key in range(1, 5)
        }
        for place in places:
            if not places[place]:
                continue
            reward = ActivityTransactionController._get_reward_for_place(
                place, money_type, len(places[place]))
            for form in places[place]:
                receiver = User.objects.get(username=form['receiver_username'])
                if reward:
                    Money.new_money(receiver, reward, money_type,
                                    first_form['description'], new_transaction)

                    if form['cert'] and place == 1:
                        Attendance.new_attendance(
                            receiver, BOOK_CERTIFICATE_VALUE,
                            AttendanceType.objects.get(name=AttendanceTypeEnum.
                                                       book_certificate.value),
                            first_form['description'], form['date'],
                            new_transaction)

        return new_transaction
    def get_transaction_from_form_data(formset_data, update_of):

        first_form = formset_data[0]
        creator = User.objects.get(username=first_form['creator_username'])

        new_transaction = Transaction.new_transaction(
            creator,
            TransactionType.objects.get(name=TransactionTypeEnum.lab.value),
            formset_data, update_of)

        money_type = MoneyType.objects.get(name=MoneyTypeEnum.lab_pass.value)
        att_type = AttendanceType.objects.get(
            name=AttendanceTypeEnum.lab_pass.value)
        receiver_1 = User.objects.get(
            username=first_form['receiver_username_1'])
        receiver_2 = User.objects.get(
            username=first_form['receiver_username_2'])

        description = first_form['description']
        description_1 = '{} \nПартнер: {}'.format(
            description, receiver_2.account.long_name())
        description_2 = '{} \nПартнер: {}'.format(
            description, receiver_1.account.long_name())

        Money.new_money(receiver_1, first_form['value_1'], money_type,
                        description_1, new_transaction)

        Money.new_money(receiver_2, first_form['value_2'], money_type,
                        description_2, new_transaction)

        Attendance.new_attendance(receiver_1, 1, att_type, description_1,
                                  first_form['date'], new_transaction)

        Attendance.new_attendance(receiver_2, 1, att_type, description_2,
                                  first_form['date'], new_transaction)
        return new_transaction