def create_deposits(): templates_ids = [t.id for t in DepositTemplate.objects.all()] for client in User.objects.all(): if get_or_create_clients_group() in client.groups.all(): deposits_count = random.randint(2, 6) for i in range(deposits_count): template_id = random_element(templates_ids) template = DepositTemplate.objects.get(pk=template_id) currencies = template.currency.keys() currency = random_element(currencies) term_percent = random_element( list(template.currency[currency]['percentage'])) accounts = list(Account.objects.filter(client=client)) if len(accounts) == 0: continue account = accounts[0] account_max_amount = float(account.residue.amount) / \ FinanceSettings.get_instance().exchange_rates[currency] amount = min(random.randint(300, 20000), account_max_amount) deposit = Deposit.create(client, template, amount, term_percent['term'], term_percent['percentage'], currency, account.id) if not deposit is None and simple_event(70): deposit.confirm()
def create(self, validated_data): validated_data['is_active'] = False profile_data = validated_data.pop('profile') instance = get_user_model().objects.create_user(**validated_data) instance.groups.add(get_or_create_clients_group()) UserProfile.objects.create(user=instance, **profile_data) return instance
def create_clients(count=10): for i in range(count): client = UserFactory(username='******'.format(i), password='******'.format(i)) Token.objects.create(user=client) client_group = get_or_create_clients_group() client.groups.add(client_group) if simple_event(50): client.profile.number_of_times_0_5_days_late = random.randint( 1, 10) if simple_event(50): client.profile.number_of_times_5_29_days_late = random.randint( 1, 10) if simple_event(70): client.profile.number_of_times_30_59_days_late = random.randint( 2, 8) if simple_event(70): client.profile.number_of_times_60_89_days_late = random.randint( 2, 8) if simple_event(90): client.profile.number_of_times_30_59_days_late = random.randint( 3, 5) client.profile.save()
def create_accounts(): for client in User.objects.all(): if get_or_create_clients_group() in client.groups.all(): accounts_count = random.randint(5, 10) for i in range(accounts_count): is_heavy_account = simple_event(10) money_range = random.randint(3000, 10000) if is_heavy_account else \ random.randint(300, 3000) Account.create(True, client, money_range)
def get_queryset(self): queryset = super(TransactionView, self).get_queryset() if self.request.user.is_superuser: return queryset if get_or_create_admins_group() in self.request.user.groups.all(): return queryset elif get_or_create_clients_group() in self.request.user.groups.all(): return queryset.filter(client=self.request.user) else: return queryset.none()
def get_queryset(self): queryset = super(UserView, self).get_queryset() if self.request.user.is_superuser: return queryset.filter(is_superuser=False) elif self.kwargs.get(self.lookup_field) == 'me': return queryset.filter(pk=self.request.user.pk) elif get_or_create_admins_group() in self.request.user.groups.all(): return queryset.filter(groups=get_or_create_clients_group()) else: return queryset.none()
def get_queryset(self): queryset = super(AccountView, self).get_queryset() if self.request.user.is_superuser: return queryset if get_or_create_admins_group() in self.request.user.groups.all(): return queryset elif get_or_create_clients_group() in self.request.user.groups.all(): statuses = [ fin_models.Account.STATUS_ACTIVE, fin_models.Account.STATUS_DISABLED, fin_models.Account.STATUS_REQUESTED_CREATING ] return queryset.filter(client=self.request.user, status__in=statuses) else: return queryset.none()
def create_credits(): templates_ids = [t.id for t in CreditTemplate.objects.all()] min_amount = { "Европа": 1000, "Калисто": 1000, "Ио": 500, "Адреаста": 15000, "Ганимед": 20000, "Ганимед+": 20000, } max_amount = { "Европа": 15000, "Калисто": 5000, "Ио": 3000, "Адреаста": 30000, "Ганимед": 50000, "Ганимед+": 50000, } for client in User.objects.all(): if get_or_create_clients_group() in client.groups.all(): credits_count = random.randint(2, 8) for i in range(credits_count): template_id = random_element(templates_ids) template = CreditTemplate.objects.get(pk=template_id) amount = random.randint(min_amount[template.name], max_amount[template.name]) accounts = list(Account.objects.filter(client=client)) if len(accounts) == 0: continue account = accounts[0] if amount < 10: continue credit = Credit.create_claim(client, template, amount, template.max_duration, CreditTemplate.ENSURING_FINE, Credit.INTO_ACCOUNT, account.id) if simple_event(70): credit.confirm()