Skip to content

Commit

Permalink
Change to current, fix association bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjamc committed Sep 26, 2024
1 parent aaa947a commit 86f6f8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
12 changes: 6 additions & 6 deletions quotas/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,17 +1354,17 @@ def __init__(self, *args, **kwargs):
self.workbasket = self.request.user.current_workbasket
sub_quota_definition_sid = kwargs.pop("sid")
ValidityPeriodForm.__init__(self, *args, **kwargs)
self.sub_quota = models.QuotaDefinition.objects.approved_up_to_transaction(
self.workbasket.transactions.last(),
).get(sid=sub_quota_definition_sid)
self.sub_quota = models.QuotaDefinition.objects.current().get(
sid=sub_quota_definition_sid,
)
self.init_fields()
self.set_initial_data()
self.init_layout(self.request)

def set_initial_data(self):
association = models.QuotaAssociation.objects.approved_up_to_transaction(
self.workbasket.transactions.last(),
).get(sub_quota__sid=self.sub_quota.sid)
association = models.QuotaAssociation.objects.current().get(
sub_quota__sid=self.sub_quota.sid,
)
self.original_definition = association.main_quota
fields = self.fields
fields["relationship_type"].initial = association.sub_quota_relation_type
Expand Down
25 changes: 5 additions & 20 deletions quotas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,15 +1175,13 @@ def last_transaction(self):

@property
def sub_quota(self):
return models.QuotaDefinition.objects.approved_up_to_transaction(
self.last_transaction,
).get(sid=self.kwargs["sid"])
return models.QuotaDefinition.objects.current().get(sid=self.kwargs["sid"])

@property
def association(self):
return models.QuotaAssociation.objects.approved_up_to_transaction(
self.last_transaction,
).get(sub_quota__sid=self.sub_quota.sid)
return models.QuotaAssociation.objects.current().get(
sub_quota__sid=self.sub_quota.sid,
)

def get_main_definition(self):
return self.association.main_quota
Expand All @@ -1208,11 +1206,6 @@ def get_result_object(self, form):

def update_association(self, instance, sub_quota_relation_type, coefficient):
"Update the association too if there is updated data submitted."
if (
self.original_association.sub_quota_relation_type == sub_quota_relation_type
and self.original_association.coefficient == coefficient
):
return
form_data = {
"main_quota": self.get_main_definition(),
"sub_quota": self.sub_quota,
Expand Down Expand Up @@ -1253,12 +1246,6 @@ def get_result_object(self, form):

def update_association(self, instance, sub_quota_relation_type, coefficient):
"Update the association too if there is updated data submitted."
if (
self.association.sub_quota_relation_type == sub_quota_relation_type
and self.association.coefficient == coefficient
):
return
# If this association already has an edit in the workbasket - update that one
current_instance = self.association.version_at(self.last_transaction)
form_data = {
"main_quota": self.get_main_definition(),
Expand All @@ -1277,9 +1264,7 @@ class SubQuotaConfirmUpdate(TrackedModelDetailView):

@property
def association(self):
return QuotaAssociation.objects.approved_up_to_transaction(
self.workbasket.transactions.last(),
).get(sub_quota__sid=self.kwargs["sid"])
return QuotaAssociation.objects.current().get(sub_quota__sid=self.kwargs["sid"])

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down

0 comments on commit 86f6f8f

Please sign in to comment.