Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expense codes to FIINE when an allocation gets approved #272

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion coldfront/core/allocation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -288,6 +288,34 @@ 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]:
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 = {
'facility': 'Research Computing Storage',
'account': account.code,
'is_valid': True,
}
person.facility_accounts.append(facility_account_dict)
ifxid = str(allocation_obj.project.pi.ifxid)
pdict = person.to_dict()
FiineAPI.updatePerson(**pdict)

if 'approve' in action:
err = None
# ensure that Tier gets swapped out for storage volume
Expand Down