def getAccountFormByGroupAndGroupType(request, group, groupType): # Get the user object user = request.user # Create different form w.r.t. different group and group type if (not user.isMarried()) and (getAccountType(request.session) != 'joint account'): form = TypedClientAccountForm(user=user, groupType=groupType, group=group) message = getTitleMessageForAccountForm(session=request.session, group=group, groupType=groupType) template = loader.get_template( 'client/profile_client_accounts_form.html') context = { 'form': form, 'group': group, 'hide_submit_button': True, 'title_message': message, } content = template.render(context, request) else: content = getAccountOwnerFormView( user=user, isJoint=(getAccountType(request.session) == 'joint account')) return content
def createAccount(request, group): if (request.method != 'POST') or (not request.is_ajax()): raise Http404("Page not found.") # Get the user object client = request.user if (client is None) or (not client.hasRole('ROLE_CLIENT')): return JsonResponse({ 'status': 'error', 'message': 'Client does not exist.', }) # Check account group is valid or not allowedGroups = AccountGroup.getGroupChoices() if (group, group) not in allowedGroups: return HttpResponseBadRequest('Invalid group type') groupTypeId = None groupType = None clientAccount = ClientAccount(value=0, is_pre_saved=False) if (group == AccountGroup.GROUP_DEPOSIT_MONEY) or ( group == AccountGroup.GROUP_FINANCIAL_INSTITUTION): groupType = getAccountGroupType(session=request.session) clientAccount.groupType = groupType # print("Checkpoint 0: groupType is") # print(groupType) if request.method == 'POST': # print("Checkpoint 1a: Enter into request.method POST") ############### # Pre-process form data before validation ############### print("createAccount: ", request.POST) post = request.POST.copy() post['value'] = float(post['value'].replace(',', '')) post['groupType'] = groupType.pk request.POST = post # print(request.POST.get('value')) form = TypedClientAccountForm(request.POST, user=client, group=group, groupType=groupType) if form.is_valid(): # print("Checkpoint 2a: Successfully validate the form") clientAccount = form.save(commit=False) clientAccount.client = client clientAccount.is_pre_saved = False clientAccount.save() removeAccountGroup(session=request.session) removeAccountType(session=request.session) removeAccountGroupType(session=request.session) removeAccountOwners(session=request.session) if group == 'employer_retirement': responseData = processEmployerRetirementAccountForm( clientAccount) else: responseData = processAccountForm(request=request) # Check if the group type is deposit and how many accounts the client has applied isType = (clientAccount.groupType.group.name == AccountGroup.GROUP_DEPOSIT_MONEY) systemAccounts = SystemAccount.objects.filter( client=client, type=clientAccount.system_type) responseData['in_right_box'] = False if ( isType or (systemAccounts.count() < 1)) else True responseData['transfer_url'] = reverse( 'rx_client_dashboard_select_system_account', kwargs={'account_id': clientAccount.pk}, ) removeIsConsolidateAccount(session=request.session) removeAccountStep(session=request.session) return JsonResponse(responseData) else: print('Checkpoint 2b: Form is not valid') print(form.errors) print(form.non_field_errors) else: # print("Checkpoint 1b: Cannot enter into request.method POST") form = TypedClientAccountForm(user=client, group=group, groupType=groupType) message = getTitleMessageForAccountForm(session=request.session, group=group, groupType=groupType) template = loader.get_template('client/profile_client_accounts_form.html') context = { 'form': form, 'group': group, 'hide_submit_button': True, 'title_message': message, } content = template.render(context, request) data = { 'status': 'error', 'content': content, } return JsonResponse(data)