From 894a04ea880237ddb0e0a2723135c4afbcbe5936 Mon Sep 17 00:00:00 2001 From: nboyse Date: Mon, 13 Nov 2023 13:46:43 +0000 Subject: [PATCH] fix: use current() instead of approved_up_to_transaction() in codebase --- additional_codes/forms.py | 10 ++++----- additional_codes/views.py | 9 +++----- certificates/forms.py | 8 +++---- certificates/views.py | 9 +++----- commodities/business_rules.py | 31 +++++++++------------------ commodities/forms.py | 2 +- commodities/models/dc.py | 8 +++---- commodities/models/orm.py | 6 +++--- commodities/tests/test_views.py | 7 ++---- commodities/views.py | 9 ++------ common/business_rules.py | 10 ++++----- common/models/tracked_qs.py | 3 ++- common/models/trackedmodel.py | 12 +++++------ common/querysets.py | 2 +- common/tests/test_models.py | 2 +- conftest.py | 4 +--- docs/source/architecture/index.rst | 2 +- footnotes/forms.py | 2 +- footnotes/views.py | 6 +++--- geo_areas/business_rules.py | 4 ++-- geo_areas/forms.py | 2 +- geo_areas/models.py | 4 ++-- geo_areas/views.py | 4 ++-- measures/business_rules.py | 24 +++++++++------------ measures/forms.py | 11 +++------- measures/models.py | 4 ++-- measures/patterns.py | 2 +- measures/querysets.py | 4 +--- measures/tests/factories.py | 8 ++----- measures/tests/test_util.py | 16 ++++---------- measures/tests/test_views.py | 34 +++++++++++++----------------- measures/util.py | 4 +--- measures/views.py | 23 ++++++-------------- quotas/business_rules.py | 28 +++++++----------------- quotas/models.py | 4 ++-- quotas/tests/test_views.py | 28 ++++++++---------------- quotas/views.py | 14 +++++------- regulations/business_rules.py | 2 +- regulations/forms.py | 3 +-- regulations/models.py | 2 +- regulations/views.py | 6 +++--- workbaskets/views/mixins.py | 6 +----- 42 files changed, 138 insertions(+), 241 deletions(-) diff --git a/additional_codes/forms.py b/additional_codes/forms.py index e718c69876..879716c7e8 100644 --- a/additional_codes/forms.py +++ b/additional_codes/forms.py @@ -155,13 +155,11 @@ def clean(self): def save(self, commit=True): instance = super().save(commit=False) - tx = WorkBasket.get_current_transaction(self.request) - highest_sid = ( - models.AdditionalCode.objects.approved_up_to_transaction(tx).aggregate( - Max("sid"), - )["sid__max"] - ) or 0 + models.AdditionalCode.objects.current().aggregate( + Max("sid"), + )["sid__max"] + ) or 0 instance.sid = highest_sid + 1 if commit: diff --git a/additional_codes/views.py b/additional_codes/views.py index c1df992f9e..ba0c7e1b5f 100644 --- a/additional_codes/views.py +++ b/additional_codes/views.py @@ -40,9 +40,8 @@ class AdditionalCodeViewSet(viewsets.ReadOnlyModelViewSet): filter_backends = [AdditionalCodeFilterBackend] def get_queryset(self): - tx = WorkBasket.get_current_transaction(self.request) return ( - AdditionalCode.objects.approved_up_to_transaction(tx) + AdditionalCode.objects.current() .select_related("type") .prefetch_related("descriptions") ) @@ -60,8 +59,7 @@ class AdditionalCodeMixin: model: Type[TrackedModel] = AdditionalCode def get_queryset(self): - tx = WorkBasket.get_current_transaction(self.request) - return AdditionalCode.objects.approved_up_to_transaction(tx).select_related( + return AdditionalCode.objects.current().select_related( "type", ) @@ -180,8 +178,7 @@ class AdditionalCodeDescriptionMixin: model: Type[TrackedModel] = AdditionalCodeDescription def get_queryset(self): - tx = WorkBasket.get_current_transaction(self.request) - return AdditionalCodeDescription.objects.approved_up_to_transaction(tx) + return AdditionalCodeDescription.objects.current() class AdditionalCodeDescriptionCreate( diff --git a/certificates/forms.py b/certificates/forms.py index eca9e8cdc2..ccc9b93ec6 100644 --- a/certificates/forms.py +++ b/certificates/forms.py @@ -50,8 +50,7 @@ def __init__(self, *args, **kwargs): def filter_certificates_for_sid(self, sid): certificate_type = self.cleaned_data["certificate_type"] - tx = WorkBasket.get_current_transaction(self.request) - return models.Certificate.objects.approved_up_to_transaction(tx).filter( + return models.Certificate.objects.current().filter( sid=sid, certificate_type=certificate_type, ) @@ -64,14 +63,13 @@ def next_sid(self, instance): form's save() method (with its commit param set either to True or False). """ - current_transaction = WorkBasket.get_current_transaction(self.request) # Filter certificate by type and find the highest sid, using regex to # ignore legacy, non-numeric identifiers return get_next_id( - models.Certificate.objects.filter( + models.Certificate.objects.current().filter( sid__regex=r"^[0-9]*$", certificate_type__sid=instance.certificate_type.sid, - ).approved_up_to_transaction(current_transaction), + ), instance._meta.get_field("sid"), max_len=3, ) diff --git a/certificates/views.py b/certificates/views.py index ca0a7285dd..ef45f8fdac 100644 --- a/certificates/views.py +++ b/certificates/views.py @@ -33,9 +33,8 @@ class CertificatesViewSet(viewsets.ReadOnlyModelViewSet): permission_classes = [permissions.IsAuthenticated] def get_queryset(self): - tx = WorkBasket.get_current_transaction(self.request) return ( - models.Certificate.objects.approved_up_to_transaction(tx) + models.Certificate.objects.current() .select_related("certificate_type") .prefetch_related("descriptions") ) @@ -53,8 +52,7 @@ class CertificateMixin: model: Type[TrackedModel] = models.Certificate def get_queryset(self): - tx = WorkBasket.get_current_transaction(self.request) - return models.Certificate.objects.approved_up_to_transaction(tx).select_related( + return models.Certificate.objects.current().select_related( "certificate_type", ) @@ -171,8 +169,7 @@ class CertificateDescriptionMixin: model: Type[TrackedModel] = models.CertificateDescription def get_queryset(self): - tx = WorkBasket.get_current_transaction(self.request) - return models.CertificateDescription.objects.approved_up_to_transaction(tx) + return models.CertificateDescription.objects.current() class CertificateCreateDescriptionMixin: diff --git a/commodities/business_rules.py b/commodities/business_rules.py index de91d8951f..f5b08a00ab 100644 --- a/commodities/business_rules.py +++ b/commodities/business_rules.py @@ -43,12 +43,8 @@ def __init__(self, transaction=None): self.logger = logging.getLogger(type(self).__name__) def parent_spans_child(self, parent, child) -> bool: - parent_validity = parent.indented_goods_nomenclature.version_at( - self.transaction, - ).valid_between - child_validity = child.indented_goods_nomenclature.version_at( - self.transaction, - ).valid_between + parent_validity = parent.indented_goods_nomenclature.version_at().valid_between + child_validity = child.indented_goods_nomenclature.version_at().valid_between return validity_range_contains_range(parent_validity, child_validity) def parents_span_childs_future(self, parents, child): @@ -59,17 +55,13 @@ def parents_span_childs_future(self, parents, child): parents_validity = [] for parent in parents: parents_validity.append( - parent.indented_goods_nomenclature.version_at( - self.transaction, - ).valid_between, + parent.indented_goods_nomenclature.version_at().valid_between, ) # sort by start date so any gaps will be obvious parents_validity.sort(key=lambda daterange: daterange.lower) - child_validity = child.indented_goods_nomenclature.version_at( - self.transaction, - ).valid_between + child_validity = child.indented_goods_nomenclature.version_at().valid_between if ( not child_validity.upper_inf @@ -108,7 +100,7 @@ def validate(self, indent): from commodities.models.dc import get_chapter_collection try: - good = indent.indented_goods_nomenclature.version_at(self.transaction) + good = indent.indented_goods_nomenclature.version_at() except TrackedModel.DoesNotExist: self.logger.warning( "Goods nomenclature %s no longer exists at transaction %s " @@ -166,10 +158,9 @@ def validate(self, good): if not ( good.code.is_chapter - or GoodsNomenclatureOrigin.objects.filter( + or GoodsNomenclatureOrigin.objects.current().filter( new_goods_nomenclature__sid=good.sid, ) - .approved_up_to_transaction(good.transaction) .exists() ): raise self.violation( @@ -252,9 +243,9 @@ class NIG11(ValidityStartDateRules): def get_objects(self, good): GoodsNomenclatureIndent = good.indents.model - return GoodsNomenclatureIndent.objects.filter( + return GoodsNomenclatureIndent.objects.current().filter( indented_goods_nomenclature__sid=good.sid, - ).approved_up_to_transaction(self.transaction) + ) class NIG12(DescriptionsRules): @@ -305,7 +296,7 @@ def validate(self, association): goods_nomenclature__sid=association.goods_nomenclature.sid, valid_between__overlap=association.valid_between, ) - .approved_up_to_transaction(association.transaction) + .current() .exclude( id=association.pk, ) @@ -351,9 +342,7 @@ def has_violation(self, good): goods_nomenclature__sid=good.sid, additional_code__isnull=False, ) - .approved_up_to_transaction( - self.transaction, - ) + .current() .exists() ) diff --git a/commodities/forms.py b/commodities/forms.py index 30243dcc9a..de87c90c2f 100644 --- a/commodities/forms.py +++ b/commodities/forms.py @@ -75,7 +75,7 @@ def init_fields(self): ].help_text = "Leave empty if the footnote is needed for an unlimited time" self.fields[ "associated_footnote" - ].queryset = Footnote.objects.approved_up_to_transaction(self.tx).filter( + ].queryset = Footnote.objects.current().filter( footnote_type__application_code__in=[1, 2], ) self.fields[ diff --git a/commodities/models/dc.py b/commodities/models/dc.py index 38ba18ce2e..3c9bd5ed0d 100644 --- a/commodities/models/dc.py +++ b/commodities/models/dc.py @@ -502,7 +502,7 @@ def get_dependent_measures( measure_qs = Measure.objects.filter(goods_sid_query) if self.moment.clock_type.is_transaction_clock: - measure_qs = measure_qs.approved_up_to_transaction(self.moment.transaction) + measure_qs = measure_qs.current() else: measure_qs = measure_qs.latest_approved() @@ -823,7 +823,7 @@ def get_snapshot( date=snapshot_date, ) - commodities = self._get_snapshot_commodities(transaction, snapshot_date) + commodities = self._get_snapshot_commodities(snapshot_date) return CommodityTreeSnapshot( moment=moment, @@ -832,7 +832,6 @@ def get_snapshot( def _get_snapshot_commodities( self, - transaction: Transaction, snapshot_date: date, ) -> List[Commodity]: """ @@ -853,8 +852,7 @@ def _get_snapshot_commodities( that match the latest_version goods. """ item_ids = {c.item_id for c in self.commodities if c.obj} - goods = GoodsNomenclature.objects.approved_up_to_transaction( - transaction, + goods = GoodsNomenclature.objects.current( ).filter( item_id__in=item_ids, valid_between__contains=snapshot_date, diff --git a/commodities/models/orm.py b/commodities/models/orm.py index 02e2456c95..fb4683f765 100644 --- a/commodities/models/orm.py +++ b/commodities/models/orm.py @@ -111,9 +111,9 @@ def get_url(self): return reverse("commodity-ui-detail", kwargs={"sid": self.sid}) def get_dependent_measures(self, transaction=None): - return self.measures.model.objects.filter( + return self.measures.model.objects.current().filter( goods_nomenclature__sid=self.sid, - ).approved_up_to_transaction(transaction) + ) @property def is_taric_code(self) -> bool: @@ -200,7 +200,7 @@ def get_good_indents( ) -> QuerySet: """Return the related goods indents based on approval status.""" good = self.indented_goods_nomenclature - return good.indents.approved_up_to_transaction( + return good.indents.current( as_of_transaction or self.transaction, ) diff --git a/commodities/tests/test_views.py b/commodities/tests/test_views.py index 9b70747fb1..f9ef26cd49 100644 --- a/commodities/tests/test_views.py +++ b/commodities/tests/test_views.py @@ -68,7 +68,7 @@ def test_commodity_list_queryset(): good_1 = factories.SimpleGoodsNomenclatureFactory.create(item_id="1010000000") good_2 = factories.SimpleGoodsNomenclatureFactory.create(item_id="1000000000") tx = Transaction.objects.last() - commodity_count = GoodsNomenclature.objects.approved_up_to_transaction(tx).count() + commodity_count = GoodsNomenclature.objects.current().count() with override_current_transaction(tx): qs = view.get_queryset() @@ -520,11 +520,8 @@ def test_commodity_footnote_update_success(valid_user_client, date_ranges): "end_date": "", } response = valid_user_client.post(url, data) - tx = Transaction.objects.last() updated_association = ( - FootnoteAssociationGoodsNomenclature.objects.approved_up_to_transaction( - tx, - ).first() + FootnoteAssociationGoodsNomenclature.objects.current().first() ) assert response.status_code == 302 assert response.url == updated_association.get_url("confirm-update") diff --git a/commodities/views.py b/commodities/views.py index 2e72ebb9a9..6af0cdd3b8 100644 --- a/commodities/views.py +++ b/commodities/views.py @@ -49,9 +49,7 @@ def get_queryset(self): """ tx = WorkBasket.get_current_transaction(self.request) return ( - GoodsNomenclature.objects.approved_up_to_transaction( - tx, - ) + GoodsNomenclature.objects.current() .prefetch_related("descriptions") .as_at_and_beyond(date.today()) .filter(suffix=80) @@ -69,10 +67,7 @@ class FootnoteAssociationMixin: model = FootnoteAssociationGoodsNomenclature def get_queryset(self): - tx = WorkBasket.get_current_transaction(self.request) - return FootnoteAssociationGoodsNomenclature.objects.approved_up_to_transaction( - tx, - ) + return self.model.objects.current() class CommodityList(CommodityMixin, WithPaginationListView): diff --git a/common/business_rules.py b/common/business_rules.py index 79b7a62832..c7d6a93771 100644 --- a/common/business_rules.py +++ b/common/business_rules.py @@ -144,7 +144,7 @@ def get_linked_models( related_instances = [getattr(model, field.name)] for instance in related_instances: try: - yield instance.version_at(transaction) + yield instance.version_at() except TrackedModel.DoesNotExist: # `related_instances` will contain all instances, even # deleted ones, and `version_at` will return @@ -278,8 +278,7 @@ def validate(self, model): if ( type(model) - .objects.filter(**query) - .approved_up_to_transaction(self.transaction) + .objects.current().filter(**query) .exclude(version_group=model.version_group) .exists() ): @@ -305,8 +304,7 @@ def validate(self, model): query["valid_between__overlap"] = model.valid_between if ( - model.__class__.objects.filter(**query) - .approved_up_to_transaction(self.transaction) + model.__class__.objects.current().filter(**query) .exclude(version_group=model.version_group) .exists() ): @@ -573,7 +571,7 @@ def validate(self, exclusion): Membership = geo_group._meta.get_field("members").related_model if ( - not Membership.objects.approved_up_to_transaction(self.transaction) + not Membership.objects.current() .filter( geo_group__sid=geo_group.sid, member__sid=exclusion.excluded_geographical_area.sid, diff --git a/common/models/tracked_qs.py b/common/models/tracked_qs.py index bda41c4f24..ae0bc92a87 100644 --- a/common/models/tracked_qs.py +++ b/common/models/tracked_qs.py @@ -69,7 +69,8 @@ def current(self) -> TrackedModelQuerySet: ) def approved_up_to_transaction(self, transaction=None) -> TrackedModelQuerySet: - """Get the approved versions of the model being queried, unless there + """This function is called using the current() function instead of directly calling it on model queries. + Get the approved versions of the model being queried, unless there exists a version of the model in a draft state within a transaction preceding (and including) the given transaction in the workbasket of the given transaction.""" diff --git a/common/models/trackedmodel.py b/common/models/trackedmodel.py index 671635821b..5d5c7e082e 100644 --- a/common/models/trackedmodel.py +++ b/common/models/trackedmodel.py @@ -342,7 +342,7 @@ def current_version(self: Cls) -> Cls: raise self.__class__.DoesNotExist("Object has no current version") return current_version - def version_at(self: Cls, transaction) -> Cls: + def version_at(self: Cls) -> Cls: """ The latest version of this model that was approved as of the given transaction. @@ -350,7 +350,7 @@ def version_at(self: Cls, transaction) -> Cls: :param transaction Transaction: Limit versions to this transaction :rtype TrackedModel: """ - return self.get_versions().approved_up_to_transaction(transaction).get() + return self.get_versions().current().get() @classproperty def copyable_fields(cls): @@ -504,12 +504,12 @@ def copy( kwargs.update(nested_fields) if not ignore: - for model in queryset.approved_up_to_transaction(transaction): + for model in queryset.current(): model.copy(transaction, **kwargs) return new_object - def in_use_by(self, via_relation: str, transaction=None) -> QuerySet[TrackedModel]: + def in_use_by(self, via_relation: str) -> QuerySet[TrackedModel]: """ Returns all of the models that are referencing this one via the specified relation and exist as of the passed transaction. @@ -526,7 +526,7 @@ def in_use_by(self, via_relation: str, transaction=None) -> QuerySet[TrackedMode return remote_model.objects.filter( **{f"{remote_field_name}__version_group": self.version_group} - ).approved_up_to_transaction(transaction) + ).current() def in_use(self, transaction=None, *relations: str) -> bool: """ @@ -572,7 +572,7 @@ def in_use(self, transaction=None, *relations: str) -> bool: # If we find any objects for any relation, then the model is in use. for relation_name in using_models: - relation_queryset = self.in_use_by(relation_name, transaction) + relation_queryset = self.in_use_by(relation_name) if relation_queryset.exists(): return True diff --git a/common/querysets.py b/common/querysets.py index 77dedac89c..4939af3142 100644 --- a/common/querysets.py +++ b/common/querysets.py @@ -66,7 +66,7 @@ def not_current(self, asof_transaction=None) -> QuerySet: :param transaction Transaction: The transaction to limit versions to. :rtype QuerySet: """ - current = self.approved_up_to_transaction(asof_transaction) + current = self.current() return self.difference(current) diff --git a/common/tests/test_models.py b/common/tests/test_models.py index 74a333b99f..cffdd525b8 100644 --- a/common/tests/test_models.py +++ b/common/tests/test_models.py @@ -291,7 +291,7 @@ def test_current_as_of(sample_model): assert models.TestModel1.objects.latest_approved().get().pk == sample_model.pk assert ( - models.TestModel1.objects.approved_up_to_transaction(transaction).get().pk + models.TestModel1.objects.current().get().pk == unapproved_version.pk ) diff --git a/conftest.py b/conftest.py index 0f69c106bc..59d8db6819 100644 --- a/conftest.py +++ b/conftest.py @@ -786,9 +786,7 @@ def check( assert workbasket is not None try: - imported = model_class.objects.approved_up_to_transaction( - workbasket.current_transaction, - ).get(**db_kwargs) + imported = model_class.objects.current().get(**db_kwargs) except model_class.DoesNotExist: if model.update_type == UpdateType.DELETE: imported = ( diff --git a/docs/source/architecture/index.rst b/docs/source/architecture/index.rst index 6dcdd0b693..bdabea63de 100644 --- a/docs/source/architecture/index.rst +++ b/docs/source/architecture/index.rst @@ -106,7 +106,7 @@ that is not draft is considered to be "current". There are a number of convenience methods for finding "current" models. .. autoclass:: common.models.trackedmodel.TrackedModelQuerySet - :members: latest_approved, approved_up_to_transaction + :members: latest_approved, current Workbaskets diff --git a/footnotes/forms.py b/footnotes/forms.py index 5d34b7dd66..c67b79b41b 100644 --- a/footnotes/forms.py +++ b/footnotes/forms.py @@ -128,7 +128,7 @@ def next_sid(self, instance): return get_next_id( models.Footnote.objects.filter( footnote_type__footnote_type_id=instance.footnote_type.footnote_type_id, - ).approved_up_to_transaction(tx), + ).current(), instance._meta.get_field("footnote_id"), max_len=3, ) diff --git a/footnotes/views.py b/footnotes/views.py index 491ee876f3..2a66deb697 100644 --- a/footnotes/views.py +++ b/footnotes/views.py @@ -41,7 +41,7 @@ class FootnoteViewSet(viewsets.ReadOnlyModelViewSet): def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) return ( - models.Footnote.objects.approved_up_to_transaction(tx) + models.Footnote.objects.current() .select_related("footnote_type") .prefetch_related("descriptions") ) @@ -63,7 +63,7 @@ class FootnoteMixin: def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return models.Footnote.objects.approved_up_to_transaction(tx).select_related( + return models.Footnote.objects.current().select_related( "footnote_type", ) @@ -73,7 +73,7 @@ class FootnoteDescriptionMixin: def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return models.FootnoteDescription.objects.approved_up_to_transaction(tx) + return models.FootnoteDescription.objects.current() class FootnoteCreateDescriptionMixin: diff --git a/geo_areas/business_rules.py b/geo_areas/business_rules.py index 43ba73545d..59daf160f1 100644 --- a/geo_areas/business_rules.py +++ b/geo_areas/business_rules.py @@ -172,7 +172,7 @@ def validate(self, membership): member__version_group=membership.member.version_group, valid_between__overlap=membership.valid_between, ) - .approved_up_to_transaction(membership.transaction) + .current() .exclude( id=membership.id, ) @@ -209,7 +209,7 @@ def validate(self, membership): parent.members.filter( member__sid=membership.member.sid, ) - .approved_up_to_transaction(membership.transaction) + .current() .exclude( valid_between__contains=membership.valid_between, ) diff --git a/geo_areas/forms.py b/geo_areas/forms.py index c629c04429..9d54afdf60 100644 --- a/geo_areas/forms.py +++ b/geo_areas/forms.py @@ -329,7 +329,7 @@ def clean(self): if membership and action == GeoMembershipAction.DELETE: tx = WorkBasket.get_current_transaction(self.request) - if membership.member_used_in_measure_exclusion(transaction=tx): + if membership.member_used_in_measure_exclusion(): self.add_error( "membership", f"{membership.member.structure_description} is referenced as an excluded geographical area in a measure and cannot be deleted as a member of the area group.", diff --git a/geo_areas/models.py b/geo_areas/models.py index 66f1c5e525..edc8b60752 100644 --- a/geo_areas/models.py +++ b/geo_areas/models.py @@ -224,8 +224,8 @@ def other(self, area: GeographicalArea) -> GeographicalArea: else: raise ValueError(f"{area} is not part of membership {self}") - def member_used_in_measure_exclusion(self, transaction): - return self.member.in_use(transaction, "measureexcludedgeographicalarea") + def member_used_in_measure_exclusion(self): + return self.member.in_use("measureexcludedgeographicalarea") class GeographicalAreaDescription(DescriptionMixin, TrackedModel): diff --git a/geo_areas/views.py b/geo_areas/views.py index a197331a20..bd75195070 100644 --- a/geo_areas/views.py +++ b/geo_areas/views.py @@ -52,7 +52,7 @@ class GeoAreaMixin: def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return GeographicalArea.objects.approved_up_to_transaction(tx) + return GeographicalArea.objects.current() class GeoAreaDescriptionMixin: @@ -60,7 +60,7 @@ class GeoAreaDescriptionMixin: def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return GeographicalAreaDescription.objects.approved_up_to_transaction(tx) + return GeographicalAreaDescription.objects.current() class GeoAreaCreateDescriptionMixin: diff --git a/measures/business_rules.py b/measures/business_rules.py index 1c317f3387..3c2222b69c 100644 --- a/measures/business_rules.py +++ b/measures/business_rules.py @@ -212,11 +212,10 @@ def validate(self, measure): goods = ( type(measure.goods_nomenclature) - .objects.filter( + .objects.current().filter( sid=measure.goods_nomenclature.sid, valid_between__overlap=measure.effective_valid_between, ) - .approved_up_to_transaction(measure.transaction) ) explosion_level = measure.measure_type.measure_explosion_level @@ -614,8 +613,7 @@ def validate(self, measure): ) if ( measure.additional_code - and not AdditionalCodeTypeMeasureType.objects.approved_up_to_transaction( - self.transaction, + and not AdditionalCodeTypeMeasureType.objects.current( ) .filter( additional_code_type__sid=measure.additional_code.type.sid, @@ -841,7 +839,7 @@ class ME43(BusinessRule): def validate(self, measure_component): duty_expressions_used = ( type(measure_component) - .objects.approved_up_to_transaction(measure_component.transaction) + .objects.current() .exclude(pk=measure_component.pk if measure_component.pk else None) .excluding_versions_of(version_group=measure_component.version_group) .filter( @@ -891,7 +889,7 @@ def validate(self, measure): ) if ( components.filter(inapplicable) - .approved_up_to_transaction(self.transaction) + .current() .exists() ): raise self.violation(measure, self.messages[code].format(self)) @@ -1028,7 +1026,7 @@ def validate(self, measure_condition): version_group=measure_condition.version_group, ) .filter(**kwargs) - .approved_up_to_transaction(self.transaction) + .current() .exists() ): raise self.violation(measure_condition) @@ -1103,7 +1101,7 @@ class ME108(BusinessRule): def validate(self, component): if ( type(component) - .objects.approved_up_to_transaction(component.transaction) + .objects.current() .exclude(pk=component.pk or None) .excluding_versions_of(version_group=component.version_group) .filter( @@ -1145,7 +1143,7 @@ class ActionRequiresDuty(BusinessRule): condition component must be created with a duty amount.""" def validate(self, condition): - components = condition.components.approved_up_to_transaction(self.transaction) + components = condition.components.current() components_have_duty = any([c.duty_amount is not None for c in components]) if condition.action.requires_duty and not components_have_duty: raise self.violation( @@ -1245,7 +1243,7 @@ def validate(self, exclusion): from measures.models import Measure # Need to get latest version of measure - measures = Measure.objects.approved_up_to_transaction(self.transaction).filter( + measures = Measure.objects.current().filter( sid=exclusion.modified_measure.sid, ) @@ -1255,9 +1253,7 @@ def validate(self, exclusion): if measures.exists(): measure = measures.last() geo_area = measure.geographical_area - members = geo_area.members.approved_up_to_transaction( - self.transaction, - ) + members = geo_area.members.current() matching_members_to_exclusion_period = members.filter( Q( @@ -1324,7 +1320,7 @@ class ME70(BusinessRule): def validate(self, association): if ( type(association) - .objects.approved_up_to_transaction(association.transaction) + .objects.current() .exclude(pk=association.pk or None) .excluding_versions_of(version_group=association.version_group) .filter( diff --git a/measures/forms.py b/measures/forms.py index 7faf482a0d..eb8281282b 100644 --- a/measures/forms.py +++ b/measures/forms.py @@ -541,9 +541,7 @@ def __init__(self, *args, **kwargs): if f"instance_footnotes_{self.instance.sid}" not in self.request.session.keys(): tx = WorkBasket.get_current_transaction(self.request) associations = ( - models.FootnoteAssociationMeasure.objects.approved_up_to_transaction( - tx, - ).filter( + models.FootnoteAssociationMeasure.objects.current().filter( footnoted_measure__sid=self.instance.sid, ) ) @@ -708,15 +706,12 @@ def save(self, commit=True): for pk in footnote_pks: footnote = ( - Footnote.objects.filter(pk=pk) - .approved_up_to_transaction(instance.transaction) + Footnote.objects.current().filter(pk=pk) .first() ) existing_association = ( - models.FootnoteAssociationMeasure.objects.approved_up_to_transaction( - instance.transaction, - ) + models.FootnoteAssociationMeasure.objects.current() .filter( footnoted_measure__sid=instance.sid, associated_footnote__footnote_id=footnote.footnote_id, diff --git a/measures/models.py b/measures/models.py index 2f1edaaa81..5031d28499 100644 --- a/measures/models.py +++ b/measures/models.py @@ -656,14 +656,14 @@ def auto_value_fields(cls): def has_components(self, transaction): return ( - MeasureComponent.objects.approved_up_to_transaction(transaction) + MeasureComponent.objects.current() .filter(component_measure__sid=self.sid) .exists() ) def has_condition_components(self, transaction): return ( - MeasureConditionComponent.objects.approved_up_to_transaction(transaction) + MeasureConditionComponent.objects.current() .filter(condition__dependent_measure__sid=self.sid) .exists() ) diff --git a/measures/patterns.py b/measures/patterns.py index 332692a918..ef025d49b7 100644 --- a/measures/patterns.py +++ b/measures/patterns.py @@ -517,7 +517,7 @@ def get_measures(self, code: GoodsNomenclature, as_at: date): date.""" return ( Measure.objects.with_validity_field() - .approved_up_to_transaction(self.workbasket.transactions.last()) + .current() .as_at(as_at) .filter(goods_nomenclature__sid=code.sid) ) diff --git a/measures/querysets.py b/measures/querysets.py index 62c23fc342..75a8ca3c60 100644 --- a/measures/querysets.py +++ b/measures/querysets.py @@ -94,9 +94,7 @@ def duty_sentence( # Components with the greatest transaction_id that is less than # or equal to component_parent's transaction_id, are considered 'current'. - component_qs = component_parent.components.approved_up_to_transaction( - component_parent.transaction, - ) + component_qs = component_parent.components.current() if not component_qs: return "" latest_transaction_id = component_qs.aggregate( diff --git a/measures/tests/factories.py b/measures/tests/factories.py index 21a9db8432..850f4d4497 100644 --- a/measures/tests/factories.py +++ b/measures/tests/factories.py @@ -31,17 +31,13 @@ class Meta: measure_type_description = factory.SelfAttribute("measure.measure_type.description") duty_sentence = factory.sequence(lambda n: f"{n}.00%") origin_description = factory.LazyAttribute( - lambda m: m.measure.geographical_area.descriptions.approved_up_to_transaction( - transaction=m.measure.geographical_area.transaction, - ) + lambda m: m.measure.geographical_area.descriptions.current() .last() .description, ) excluded_origin_descriptions = factory.LazyAttribute( lambda m: random.choice(MeasureSheetRow.separators).join( - e.excluded_geographical_area.descriptions.approved_up_to_transaction( - transaction=e.excluded_geographical_area.transaction, - ) + e.excluded_geographical_area.descriptions.current() .last() .description for e in m.measure.exclusions.all() diff --git a/measures/tests/test_util.py b/measures/tests/test_util.py index f1eaef53ce..2190cd146e 100644 --- a/measures/tests/test_util.py +++ b/measures/tests/test_util.py @@ -40,9 +40,7 @@ def test_diff_components_update( MeasureComponent, "component_measure", ) - components = new_measure.components.approved_up_to_transaction( - workbasket.current_transaction, - ) + components = new_measure.components.current() assert components.count() == 1 @@ -86,9 +84,7 @@ def test_diff_components_update_multiple( MeasureComponent, "component_measure", ) - components = component_1.component_measure.components.approved_up_to_transaction( - workbasket.current_transaction, - ) + components = component_1.component_measure.components.current() assert components.count() == 2 @@ -116,9 +112,7 @@ def test_diff_components_create(workbasket, duty_sentence_parser): MeasureComponent, "component_measure", ) - components = measure.components.approved_up_to_transaction( - workbasket.current_transaction, - ) + components = measure.components.current() assert components.count() == 1 @@ -151,9 +145,7 @@ def test_diff_components_delete( MeasureComponent, "component_measure", ) - components = component.component_measure.components.approved_up_to_transaction( - workbasket.current_transaction, - ) + components = component.component_measure.components.current() assert components.count() == 0 diff --git a/measures/tests/test_views.py b/measures/tests/test_views.py index 344e90735b..b4eea57cfd 100644 --- a/measures/tests/test_views.py +++ b/measures/tests/test_views.py @@ -527,10 +527,10 @@ def test_measure_update_duty_sentence( if update_data: tx = Transaction.objects.last() - measure = Measure.objects.approved_up_to_transaction(tx).get( + measure = Measure.objects.current().get( sid=measure_form.instance.sid, ) - components = measure.components.approved_up_to_transaction(tx).filter( + components = measure.components.current().filter( component_measure__sid=measure_form.instance.sid, ) @@ -663,13 +663,13 @@ def test_measure_update_create_conditions( assert response.url == reverse("measure-ui-confirm-update", args=(measure.sid,)) tx = Transaction.objects.last() - updated_measure = Measure.objects.approved_up_to_transaction(tx).get( + updated_measure = Measure.objects.current().get( sid=measure.sid, ) - assert updated_measure.conditions.approved_up_to_transaction(tx).count() == 1 + assert updated_measure.conditions.current().count() == 1 - condition = updated_measure.conditions.approved_up_to_transaction(tx).first() + condition = updated_measure.conditions.current().first() assert ( condition.condition_code.pk @@ -689,7 +689,7 @@ def test_measure_update_create_conditions( ) assert condition.update_type == UpdateType.CREATE - components = condition.components.approved_up_to_transaction(tx).order_by( + components = condition.components.current().order_by( *MeasureConditionComponent._meta.ordering ) @@ -719,7 +719,7 @@ def test_measure_update_edit_conditions( client.post(url, data=measure_edit_conditions_data) transaction_count = Transaction.objects.count() tx = Transaction.objects.last() - measure_with_condition = Measure.objects.approved_up_to_transaction(tx).get( + measure_with_condition = Measure.objects.current().get( sid=measure.sid, ) previous_condition = measure_with_condition.conditions.last() @@ -734,15 +734,15 @@ def test_measure_update_edit_conditions( ] = "10 GBP / 100 kg" client.post(url, data=measure_edit_conditions_data) tx = Transaction.objects.last() - updated_measure = Measure.objects.approved_up_to_transaction(tx).get( + updated_measure = Measure.objects.current().get( sid=measure.sid, ) # We expect one transaction for updating the measure and updating the condition, one for deleting a component and updating a component assert Transaction.objects.count() == transaction_count + 2 - assert updated_measure.conditions.approved_up_to_transaction(tx).count() == 1 + assert updated_measure.conditions.current().count() == 1 - condition = updated_measure.conditions.approved_up_to_transaction(tx).first() + condition = updated_measure.conditions.current().first() assert condition.pk != previous_condition.pk assert condition.required_certificate == None @@ -750,7 +750,7 @@ def test_measure_update_edit_conditions( assert condition.update_type == UpdateType.UPDATE assert condition.sid == previous_condition.sid - components = condition.components.approved_up_to_transaction(tx).all() + components = condition.components.current().all() assert components.count() == 1 @@ -840,11 +840,11 @@ def test_measure_update_remove_conditions( assert Transaction.objects.count() == transaction_count + 1 tx = Transaction.objects.last() - updated_measure = Measure.objects.approved_up_to_transaction(tx).get( + updated_measure = Measure.objects.current().get( sid=measure.sid, ) - assert updated_measure.conditions.approved_up_to_transaction(tx).count() == 0 + assert updated_measure.conditions.current().count() == 0 def test_measure_update_invalid_conditions( @@ -993,15 +993,11 @@ def test_measure_update_group_exclusion(client, valid_user, erga_omnes): }, ) - assert not MeasureExcludedGeographicalArea.objects.approved_up_to_transaction( - Transaction.objects.last(), - ).exists() + assert not MeasureExcludedGeographicalArea.objects.current().exists() client.post(url, data=data) measure_area_exclusions = ( - MeasureExcludedGeographicalArea.objects.approved_up_to_transaction( - Transaction.objects.last(), - ) + MeasureExcludedGeographicalArea.objects.current() ) assert measure_area_exclusions.count() == 2 diff --git a/measures/util.py b/measures/util.py index bf00efd6a7..d2aebb36f6 100644 --- a/measures/util.py +++ b/measures/util.py @@ -55,9 +55,7 @@ def diff_components( ) new_components = parser.parse(duty_sentence) - old_components = instance.components.approved_up_to_transaction( - workbasket.current_transaction, - ) + old_components = instance.components.current() new_by_id = {c.duty_expression.id: c for c in new_components} old_by_id = {c.duty_expression.id: c for c in old_components} all_ids = set(new_by_id.keys()) | set(old_by_id.keys()) diff --git a/measures/views.py b/measures/views.py index 848938a884..6d1cb5f6e8 100644 --- a/measures/views.py +++ b/measures/views.py @@ -64,7 +64,7 @@ class MeasureTypeViewSet(viewsets.ReadOnlyModelViewSet): def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return MeasureType.objects.approved_up_to_transaction(tx).order_by( + return MeasureType.objects.current().order_by( "description", ) @@ -75,7 +75,7 @@ class MeasureMixin: def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return Measure.objects.approved_up_to_transaction(tx) + return Measure.objects.current() class MeasureSessionStoreMixin: @@ -732,7 +732,7 @@ def get_form(self, step=None, data=None, files=None): if hasattr(f, "fields"): for field in f.fields.values(): if hasattr(field, "queryset"): - field.queryset = field.queryset.approved_up_to_transaction(tx) + field.queryset = field.queryset.current() form.is_valid() if hasattr(form, "cleaned_data"): @@ -771,26 +771,20 @@ def get_form(self, form_class=None): if hasattr(form, "field"): for field in form.fields.values(): if hasattr(field, "queryset"): - field.queryset = field.queryset.approved_up_to_transaction(tx) + field.queryset = field.queryset.current() return form def get_footnotes(self, measure): - tx = WorkBasket.get_current_transaction(self.request) - associations = FootnoteAssociationMeasure.objects.approved_up_to_transaction( - tx, - ).filter( + associations = FootnoteAssociationMeasure.objects.current().filter( footnoted_measure__sid=measure.sid, ) return [a.associated_footnote for a in associations] def get_conditions(self, measure): - tx = WorkBasket.get_current_transaction(self.request) return ( - measure.conditions.with_reference_price_string().approved_up_to_transaction( - tx, - ) + measure.conditions.with_reference_price_string().current() ) def get_context_data(self, **kwargs): @@ -857,10 +851,7 @@ def create_conditions(self, obj): formset = self.get_context_data()["conditions_formset"] excluded_sids = [] conditions_data = [] - workbasket = WorkBasket.current(self.request) - existing_conditions = obj.conditions.approved_up_to_transaction( - workbasket.get_current_transaction(self.request), - ) + existing_conditions = obj.conditions.current() for f in formset.forms: f.is_valid() diff --git a/quotas/business_rules.py b/quotas/business_rules.py index 5d625626c5..04e33d02c0 100644 --- a/quotas/business_rules.py +++ b/quotas/business_rules.py @@ -34,9 +34,7 @@ def validate(self, quota_definition): related_model = self.get_relation_model(quota_definition) if quota_definition.update_type == UpdateType.DELETE: kwargs = {f"{self.sid_prefix}sid": quota_definition.sid} - if related_model.objects.approved_up_to_transaction( - transaction=quota_definition.transaction, - ).filter(**kwargs): + if related_model.objects.current().filter(**kwargs): raise self.violation(quota_definition) @@ -53,7 +51,7 @@ class ON2(BusinessRule): def validate(self, order_number): if ( type(order_number) - .objects.approved_up_to_transaction(order_number.transaction) + .objects.current() .filter( order_number=order_number.order_number, valid_between__overlap=order_number.valid_between, @@ -73,9 +71,7 @@ def validate(self, order_number): origin_exists = False for order_number_version in order_number_versions: if ( - order_number_version.origins.approved_up_to_transaction( - order_number.transaction, - ).count() + order_number_version.origins.current().count() > 0 ): origin_exists = True @@ -92,7 +88,7 @@ class ON5(BusinessRule): def validate(self, origin): if ( type(origin) - .objects.approved_up_to_transaction(origin.transaction) + .objects.current() .filter( order_number__sid=origin.order_number.sid, geographical_area__sid=origin.geographical_area.sid, @@ -186,9 +182,7 @@ def validate(self, order_number_origin): check that there are no measures linked to the origin . """ - measures = measures_models.Measure.objects.approved_up_to_transaction( - order_number_origin.transaction, - ) + measures = measures_models.Measure.objects.current() if not measures.exists(): return @@ -326,9 +320,7 @@ class OverlappingQuotaDefinition(BusinessRule): def validate(self, quota_definition): potential_quota_definition_matches = ( type(quota_definition) - .objects.approved_up_to_transaction( - quota_definition.transaction, - ) + .objects.current() .filter( order_number=quota_definition.order_number, valid_between__overlap=quota_definition.valid_between, @@ -358,9 +350,7 @@ def validate(self, quota_definition): if quota_definition.valid_between.lower < datetime.date.today(): return True - if quota_definition.sub_quota_associations.approved_up_to_transaction( - self.transaction, - ).exists(): + if quota_definition.sub_quota_associations.current().exists(): return True if quota_definition.volume != quota_definition.initial_volume: @@ -471,9 +461,7 @@ class QA6(BusinessRule): def validate(self, association): if ( - association.main_quota.sub_quota_associations.approved_up_to_transaction( - association.transaction, - ) + association.main_quota.sub_quota_associations.current() .values( "sub_quota_relation_type", ) diff --git a/quotas/models.py b/quotas/models.py index db28e56947..5d2b88afdc 100644 --- a/quotas/models.py +++ b/quotas/models.py @@ -170,8 +170,8 @@ class QuotaOrderNumberOrigin(TrackedModel, ValidityMixin): UpdateValidity, ) - def order_number_in_use(self, transaction): - return self.order_number.in_use(transaction) + def order_number_in_use(self): + return self.order_number.in_use() @property def structure_description(self): diff --git a/quotas/tests/test_views.py b/quotas/tests/test_views.py index 45ea87bf4e..d6e1faf09f 100644 --- a/quotas/tests/test_views.py +++ b/quotas/tests/test_views.py @@ -723,12 +723,10 @@ def test_quota_edit_origin_new_versions(valid_user_client): tx = Transaction.objects.last() - quota = models.QuotaOrderNumber.objects.approved_up_to_transaction(tx).get( + quota = models.QuotaOrderNumber.objects.current().get( sid=quota.sid, ) - origins = models.QuotaOrderNumberOrigin.objects.approved_up_to_transaction( - tx, - ).filter( + origins = models.QuotaOrderNumberOrigin.objects.current().filter( order_number=quota, ) @@ -774,7 +772,7 @@ def test_quota_edit_origin_exclusions( tx = Transaction.objects.last() - origin = models.QuotaOrderNumberOrigin.objects.approved_up_to_transaction(tx).get( + origin = models.QuotaOrderNumberOrigin.objects.current().get( sid=origin.sid, ) @@ -832,25 +830,21 @@ def test_quota_edit_origin_exclusions_remove( tx = Transaction.objects.last() - updated_quota = models.QuotaOrderNumber.objects.approved_up_to_transaction(tx).get( + updated_quota = models.QuotaOrderNumber.objects.current().get( sid=quota.sid, ) updated_origin = ( - updated_quota.quotaordernumberorigin_set.approved_up_to_transaction(tx) + updated_quota.quotaordernumberorigin_set.current() ).first() assert ( - updated_origin.quotaordernumberoriginexclusion_set.approved_up_to_transaction( - tx, - ).count() + updated_origin.quotaordernumberoriginexclusion_set.current().count() == 0 ) assert ( country1 - not in updated_origin.quotaordernumberoriginexclusion_set.approved_up_to_transaction( - tx, - ) + not in updated_origin.quotaordernumberoriginexclusion_set.current() ) @@ -883,11 +877,8 @@ def test_update_quota_definition(valid_user_client, date_ranges): kwargs={"sid": quota_definition.sid}, ) - tx = Transaction.objects.last() - updated_definition = models.QuotaDefinition.objects.approved_up_to_transaction( - tx, - ).get( + updated_definition = models.QuotaDefinition.objects.current().get( sid=quota_definition.sid, ) @@ -959,8 +950,7 @@ def test_quota_create_origin( assert response.status_code == 302 - tx = Transaction.objects.last() - origin = models.QuotaOrderNumberOrigin.objects.approved_up_to_transaction(tx).get( + origin = models.QuotaOrderNumberOrigin.objects.current().get( sid=response.url.split("/")[2], ) diff --git a/quotas/views.py b/quotas/views.py index 42e72b2936..d63416fa67 100644 --- a/quotas/views.py +++ b/quotas/views.py @@ -50,8 +50,7 @@ class QuotaOrderNumberViewset(viewsets.ReadOnlyModelViewSet): filter_backends = [OrderNumberFilterBackend] def get_queryset(self): - tx = WorkBasket.get_current_transaction(self.request) - return models.QuotaOrderNumber.objects.approved_up_to_transaction(tx) + return models.QuotaOrderNumber.objects.current() class QuotaOrderNumberOriginViewset(viewsets.ReadOnlyModelViewSet): @@ -101,8 +100,7 @@ class QuotaOrderNumberMixin: model = models.QuotaOrderNumber def get_queryset(self): - tx = WorkBasket.get_current_transaction(self.request) - return models.QuotaOrderNumber.objects.approved_up_to_transaction(tx) + return models.QuotaOrderNumber.objects.current() class QuotaList(QuotaOrderNumberMixin, TamatoListView): @@ -277,9 +275,7 @@ def get_result_object(self, form): object = super().get_result_object(form) existing_origins = ( - models.QuotaOrderNumberOrigin.objects.approved_up_to_transaction( - object.transaction, - ).filter( + models.QuotaOrderNumberOrigin.objects.current().filter( order_number__sid=object.sid, ) ) @@ -318,7 +314,7 @@ class QuotaOrderNumberOriginMixin: def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return models.QuotaOrderNumberOrigin.objects.approved_up_to_transaction(tx) + return models.QuotaOrderNumberOrigin.objects.current() class QuotaOrderNumberOriginUpdateMixin( @@ -458,7 +454,7 @@ class QuotaDefinitionMixin: def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return models.QuotaDefinition.objects.approved_up_to_transaction(tx) + return models.QuotaDefinition.objects.current() class QuotaDefinitionUpdateMixin( diff --git a/regulations/business_rules.py b/regulations/business_rules.py index c308a79550..e55f79d055 100644 --- a/regulations/business_rules.py +++ b/regulations/business_rules.py @@ -32,7 +32,7 @@ def validate(self, regulation): generating_regulation__regulation_id=regulation.regulation_id, generating_regulation__role_type=regulation.role_type, ) - .approved_up_to_transaction(self.transaction) + .transaction() .exclude( valid_between__contained_by=regulation.valid_between, ) diff --git a/regulations/forms.py b/regulations/forms.py index 9c37829b51..dc206d4f1b 100644 --- a/regulations/forms.py +++ b/regulations/forms.py @@ -178,11 +178,10 @@ def _get_next_part_value(self, partial_regulation_id): RegulationCreateForm._make_partial_regulation_id()).""" tx = WorkBasket.get_current_transaction(self.request) last_matching_regulation = ( - Regulation.objects.filter( + Regulation.objects.current().filter( regulation_id__startswith=partial_regulation_id, role_type=FIXED_ROLE_TYPE, ) - .approved_up_to_transaction(tx) .order_by("-regulation_id") .first() ) diff --git a/regulations/models.py b/regulations/models.py index 01880e41e6..420a3ada69 100644 --- a/regulations/models.py +++ b/regulations/models.py @@ -256,7 +256,7 @@ def used_as_terminating_regulation_or_draft_generating_and_terminating_regulatio generating_regulation__regulation_id=self.regulation_id, generating_regulation__role_type=self.role_type, ) - .approved_up_to_transaction(transaction) + .current() .exists() ) diff --git a/regulations/views.py b/regulations/views.py index 6426e0008c..f29e536bd9 100644 --- a/regulations/views.py +++ b/regulations/views.py @@ -36,7 +36,7 @@ class RegulationViewSet(viewsets.ReadOnlyModelViewSet): def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return Regulation.objects.approved_up_to_transaction(tx).select_related( + return Regulation.objects.current().select_related( "regulation_group", ) @@ -55,7 +55,7 @@ class RegulationMixin: def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return Regulation.objects.approved_up_to_transaction(tx).select_related( + return Regulation.objects.current().select_related( "regulation_group", ) @@ -180,7 +180,7 @@ class RegulationConfirmCreate(TrackedModelDetailView): def get_queryset(self): tx = WorkBasket.get_current_transaction(self.request) - return Regulation.objects.approved_up_to_transaction(tx) + return Regulation.objects.current() class RegulationUpdate( diff --git a/workbaskets/views/mixins.py b/workbaskets/views/mixins.py index 83a6263526..6713927746 100644 --- a/workbaskets/views/mixins.py +++ b/workbaskets/views/mixins.py @@ -10,9 +10,5 @@ def workbasket(self) -> WorkBasket: def get_queryset(self): qs = super().get_queryset() - transaction = None - current = self.workbasket - if current: - transaction = current.transactions.last() - return qs.approved_up_to_transaction(transaction) + return qs.current()