From 92f6abaedc30a3ee47c0d84b00f243ed540a039a Mon Sep 17 00:00:00 2001 From: Alexander Dusenbery Date: Thu, 5 Dec 2024 16:38:20 -0500 Subject: [PATCH] fix: toggle all auto-apply plans when desired --- license_manager/apps/subscriptions/api.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/license_manager/apps/subscriptions/api.py b/license_manager/apps/subscriptions/api.py index a9413fdd..d37dce20 100644 --- a/license_manager/apps/subscriptions/api.py +++ b/license_manager/apps/subscriptions/api.py @@ -233,20 +233,17 @@ def sync_agreement_with_enterprise_customer(customer_agreement): def toggle_auto_apply_licenses(customer_agreement_uuid, subscription_uuid): """ - Turn auto apply licenses on for the subscription with the given uuid and off for the current - plan used for auto applied licenses. If subscription_uuid is empty or None, turn auto apply licenses + Turn auto apply licenses on for the subscription with the given uuid and off for all other + auto-applied plans in the given customer agreement. If subscription_uuid is empty or None, turn auto apply licenses off for the current plan. """ - # There should only be one plan for auto-applied licenses at any given time - current_plan_for_auto_applied_licenses = SubscriptionPlan.objects.filter( + for plan in SubscriptionPlan.objects.filter( customer_agreement_id=customer_agreement_uuid, should_auto_apply_licenses=True - ).first() - - if current_plan_for_auto_applied_licenses: - current_plan_for_auto_applied_licenses.should_auto_apply_licenses = False - current_plan_for_auto_applied_licenses.save() + ): + plan.should_auto_apply_licenses = False + plan.save() if not subscription_uuid: return