Skip to content
Merged
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
14 changes: 13 additions & 1 deletion coldfront/plugins/ifx/management/commands/createProductUsages.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def add_arguments(self, parser):
dest='productstr',
help='Create for specified products (comma separated list)'
)
parser.add_argument(
'--project-ids',
dest='project_ids',
help='Create for specified projects (comma separated list of project IDs)'
)

def handle(self, *args, **kwargs):
month = select_month = int(kwargs['month'])
Expand All @@ -70,6 +75,11 @@ def handle(self, *args, **kwargs):
products = Product.objects.filter(product_name__in=product_names)
print(f'Only processing {product_names}')

project_ids = []
if 'project_ids' in kwargs and kwargs['project_ids']:
project_ids = [int(pid) for pid in kwargs['project_ids'].split(',')]
print(f'Only processing projects with IDs {project_ids}')

overwrite = kwargs['overwrite']
successes = 0
errors = []
Expand All @@ -82,6 +92,8 @@ def handle(self, *args, **kwargs):
if not products or product in products:
# Get the AllocationUser records
allocations = Allocation.objects.filter(resources__in=[resource], status__name='Active')
if project_ids:
allocations = allocations.filter(project__id__in=project_ids)
print(f'Processing {len(allocations)} allocations for {resource}')
for allocation in allocations:
requires_payment = allocation.get_attribute('RequiresPayment')
Expand Down Expand Up @@ -113,7 +125,7 @@ def handle(self, *args, **kwargs):
else:
print(f'Allocation {allocation} does not require payment')
else:
errors.append(f'Unable to fine a Product for resource {resource}')
errors.append(f'Unable to find a Product for resource {resource}')
print(f'{successes} records successfully created.')
if errors:
print('Errors: %s' % "\n".join(errors))
Expand Down
Loading