From 8d9b55549b5dc40dbc782efb5f0763f08cc3f5bd Mon Sep 17 00:00:00 2001 From: claire-peters Date: Wed, 10 Jan 2024 16:29:14 -0800 Subject: [PATCH 1/5] add simple FiineAPI account check --- coldfront/core/allocation/views.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/coldfront/core/allocation/views.py b/coldfront/core/allocation/views.py index 3be2aa744c..ceb3f0ad2e 100644 --- a/coldfront/core/allocation/views.py +++ b/coldfront/core/allocation/views.py @@ -288,6 +288,22 @@ def post(self, request, *args, **kwargs): allocation_obj.is_changeable = form_data.get('is_changeable') allocation_obj.status = form_data.get('status') + # check if corresponding Account for expense code exists + if 'ifxbilling' in settings.INSTALLED_APPS: + # pull up the person corresponding to the PI + person = FiineAPI.readPerson(ifxid=allocation_obj.project.pi.ifxid) + if allocation_obj not in [a.account.code for a in person.facility_accounts]: + account = FiineAPI.listAccounts(code=allocation_obj.expense_code)[0] + if not matched_fiineaccts: + account = FiineAPI.createAccount(**account_data) + + facility_account_dict = { + 'facility': 'Research Computing Storage', + 'account': { 'id': account.id }, + } + person.facility_accounts.append(facility_account_dict) + FiineAPI.updatePerson(ifxid=allocation_obj.project.pi.ifxid, **person.to_dict()) + if 'approve' in action: err = None # ensure that Tier gets swapped out for storage volume From 0b296b2964bd6752d24c693f64e15d750dee7506 Mon Sep 17 00:00:00 2001 From: claire-peters Date: Wed, 10 Jan 2024 16:51:37 -0800 Subject: [PATCH 2/5] bugfix --- coldfront/core/allocation/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coldfront/core/allocation/views.py b/coldfront/core/allocation/views.py index ceb3f0ad2e..e39eb7b877 100644 --- a/coldfront/core/allocation/views.py +++ b/coldfront/core/allocation/views.py @@ -294,7 +294,7 @@ def post(self, request, *args, **kwargs): person = FiineAPI.readPerson(ifxid=allocation_obj.project.pi.ifxid) if allocation_obj not in [a.account.code for a in person.facility_accounts]: account = FiineAPI.listAccounts(code=allocation_obj.expense_code)[0] - if not matched_fiineaccts: + if not account: account = FiineAPI.createAccount(**account_data) facility_account_dict = { From 20606e85da34ad4367a9e7ac196e246e83c7bd41 Mon Sep 17 00:00:00 2001 From: claire-peters Date: Fri, 12 Jan 2024 14:27:41 -0500 Subject: [PATCH 3/5] try fixing views --- coldfront/core/allocation/views.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/coldfront/core/allocation/views.py b/coldfront/core/allocation/views.py index e39eb7b877..c72500cbbe 100644 --- a/coldfront/core/allocation/views.py +++ b/coldfront/core/allocation/views.py @@ -65,7 +65,7 @@ from coldfront.core.resource.models import Resource from coldfront.core.utils.common import get_domain_url, import_from_settings from coldfront.core.utils.mail import send_allocation_admin_email, send_allocation_customer_email - +from coldfront.plugins.ifx.models import ProjectOrganization if 'ifxbilling' in settings.INSTALLED_APPS: from fiine.client import API as FiineAPI @@ -292,9 +292,19 @@ def post(self, request, *args, **kwargs): if 'ifxbilling' in settings.INSTALLED_APPS: # pull up the person corresponding to the PI person = FiineAPI.readPerson(ifxid=allocation_obj.project.pi.ifxid) + pid = person.id if allocation_obj not in [a.account.code for a in person.facility_accounts]: - account = FiineAPI.listAccounts(code=allocation_obj.expense_code)[0] - if not account: + try: + account = FiineAPI.listAccounts(code=allocation_obj.expense_code)[0] + except IndexError: + + account_data = {'code':allocation_obj.expense_code, + 'account_type': 'Expense Code', + 'name': 'name_placeholder', + 'active': 'true', + 'organization': + ProjectOrganization.objects.get(project=allocation_obj.project).organization.name, + } account = FiineAPI.createAccount(**account_data) facility_account_dict = { @@ -302,7 +312,10 @@ def post(self, request, *args, **kwargs): 'account': { 'id': account.id }, } person.facility_accounts.append(facility_account_dict) - FiineAPI.updatePerson(ifxid=allocation_obj.project.pi.ifxid, **person.to_dict()) + ifxid = str(allocation_obj.project.pi.ifxid) + pdict = person.to_dict() + # pdict.pop('ifxid') + FiineAPI.updatePerson(id=person.ifxid, **pdict) if 'approve' in action: err = None From 934806e7d7567318dbba08f17b75adf049dd589e Mon Sep 17 00:00:00 2001 From: claire-peters Date: Tue, 16 Jan 2024 13:55:35 -0500 Subject: [PATCH 4/5] formatting --- coldfront/core/allocation/views.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/coldfront/core/allocation/views.py b/coldfront/core/allocation/views.py index c72500cbbe..2167c5bcab 100644 --- a/coldfront/core/allocation/views.py +++ b/coldfront/core/allocation/views.py @@ -292,30 +292,28 @@ def post(self, request, *args, **kwargs): if 'ifxbilling' in settings.INSTALLED_APPS: # pull up the person corresponding to the PI person = FiineAPI.readPerson(ifxid=allocation_obj.project.pi.ifxid) - pid = person.id if allocation_obj not in [a.account.code for a in person.facility_accounts]: try: account = FiineAPI.listAccounts(code=allocation_obj.expense_code)[0] except IndexError: - - account_data = {'code':allocation_obj.expense_code, - 'account_type': 'Expense Code', - 'name': 'name_placeholder', - 'active': 'true', - 'organization': - ProjectOrganization.objects.get(project=allocation_obj.project).organization.name, - } + account_data = { + 'code':allocation_obj.expense_code, + 'account_type': 'Expense Code', + 'name': 'name_placeholder', + 'active': 'true', + 'organization': + ProjectOrganization.objects.get(project=allocation_obj.project).organization.name, + } account = FiineAPI.createAccount(**account_data) facility_account_dict = { - 'facility': 'Research Computing Storage', - 'account': { 'id': account.id }, + 'facility': 'Research Computing Storage', + 'account': { 'id': account.id }, } person.facility_accounts.append(facility_account_dict) ifxid = str(allocation_obj.project.pi.ifxid) pdict = person.to_dict() - # pdict.pop('ifxid') - FiineAPI.updatePerson(id=person.ifxid, **pdict) + FiineAPI.updatePerson(**pdict) if 'approve' in action: err = None From c0778690c3bc5b541449a8a589aa3b41780ab942 Mon Sep 17 00:00:00 2001 From: claire-peters Date: Thu, 18 Jan 2024 17:17:13 -0500 Subject: [PATCH 5/5] update facility_account_dict --- coldfront/core/allocation/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coldfront/core/allocation/views.py b/coldfront/core/allocation/views.py index 2167c5bcab..79a780b6cd 100644 --- a/coldfront/core/allocation/views.py +++ b/coldfront/core/allocation/views.py @@ -308,7 +308,8 @@ def post(self, request, *args, **kwargs): facility_account_dict = { 'facility': 'Research Computing Storage', - 'account': { 'id': account.id }, + 'account': account.code, + 'is_valid': True, } person.facility_accounts.append(facility_account_dict) ifxid = str(allocation_obj.project.pi.ifxid)