From 5cc25a002b1940a9d148287d0771671994f939a0 Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Thu, 5 Sep 2024 14:02:33 -0400 Subject: [PATCH] sponsors: implement better handling of benefit feature configuration naming (#2523) When cloning benefits year-to-year, search/replace the year if it is part of the name. Otherwise continue to suffix... this stops the internal_id_2022_2023_2024_2025 nonsense. --- sponsors/models/benefits.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sponsors/models/benefits.py b/sponsors/models/benefits.py index 635b3f6b9..750f5af6c 100644 --- a/sponsors/models/benefits.py +++ b/sponsors/models/benefits.py @@ -146,7 +146,10 @@ def create_benefit_feature(self, sponsor_benefit, **kwargs): def get_clone_kwargs(self, new_benefit): kwargs = super().get_clone_kwargs(new_benefit) - kwargs["internal_name"] = f"{self.internal_name}_{new_benefit.year}" + if str(self.benefit.year) in self.internal_name: + kwargs["internal_name"] = self.internal_name.replace(str(self.benefit.year), str(new_benefit.year)) + else: + kwargs["internal_name"] = f"{self.internal_name}_{new_benefit.year}" due_date = kwargs.get("due_date") if due_date: kwargs["due_date"] = due_date.replace(year=new_benefit.year)