Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTD: Add endpoint for licences list #2235

Draft
wants to merge 24 commits into
base: dev
Choose a base branch
from
Draft

LTD: Add endpoint for licences list #2235

wants to merge 24 commits into from

Conversation

saruniitr
Copy link
Contributor

Aim

LTD-

@saruniitr saruniitr marked this pull request as ready for review October 15, 2024 14:56
name = serializers.CharField(source="*")


class SIELLicenceSerializer(serializers.ModelSerializer):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s just call this Licence for now.

from api.licences.models import Licence


class LicenceStatusSerializer(serializers.Serializer):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s not include status in this first prototype.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part of cherry-picked commit, will remove

Then there are no other licence statuses


Scenario: Issued licence is included in the extract
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have this in a separate BDD scenario file? I’d like it if each endpoint had its own scenario file.

serializer_class = SIELLicenceSerializer

def get_queryset(self):
return Licence.objects.exclude(status=LicenceStatus.DRAFT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to see a test for this somewhere. Possibly as a distinct scenario in the BDD file for the endpoint.

@saruniitr saruniitr force-pushed the LTD-stats-init branch 2 times, most recently from b92307d to ce7cbf9 Compare October 16, 2024 08:35
def unpage_data(client):
def _unpage_data(url):
unpaged_results = []
while True:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works fine and looks great, although I am surprised there's not a way of doing this using the existing libraries we have

hnryjmes
hnryjmes previously approved these changes Oct 16, 2024
Copy link
Contributor

@hnryjmes hnryjmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything looks good to me, happy to approve

@hnryjmes hnryjmes dismissed their stale review October 18, 2024 13:38

this will be a long lived branch so does not make sense to approve now

Comment on lines 4 to 17
Scenario: Check that draft licences are not included in the extract
Given a standard draft licence is created
Then the draft licence is not included in the extract

Scenario: Issued licence is included in the extract
Given a standard licence is issued
Then the issued licence is included in the extract
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that it might be nice to have at test that shows that a licence transitioning from draft to issued makes a difference.

Comment on lines 22 to 24
# When an application with all goods as NLR is finalised then the current code
# creates a licence however the goods on this licence will be empty. This
# will skew licence data hence exclude them
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A BDD test describing this NLR case would be nice to see.

Comment on lines 30 to 31
LicenceStatus.DRAFT,
LicenceStatus.CANCELLED,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we extract these statuses out into a named thing? For CaseStatus we have a range of named lists so I think it would be good to do the same here.

Comment on lines 36 to 39
case__status__status__in=[
CaseStatusEnum.FINALISED,
CaseStatusEnum.SUPERSEDED_BY_EXPORTER_EDIT,
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we come up with a named list for these statuses?

Case.objects.filter(
licences__generatedcasedocument__template_id=SIEL_TEMPLATE_ID,
licences__generatedcasedocument__visible_to_exporter=True,
licences__generatedcasedocument__safe=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this just an extra precaution? the document is generated internally so I wouldn't think this would ever not be safe=True ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

safe=True indicates no virus found

Comment on lines 26 to 39
issued_qs = Case.objects.filter(
licences__generatedcasedocument__template_id=SIEL_TEMPLATE_ID,
licences__generatedcasedocument__visible_to_exporter=True,
licences__generatedcasedocument__safe=True,
)
refused_qs = Case.objects.filter(
id__in=GeneratedCaseDocument.objects.filter(
template_id=SIEL_REFUSAL_TEMPLATE_ID,
visible_to_exporter=True,
safe=True,
).values_list("case", flat=True)
)

queryset = (issued_qs | refused_qs).distinct().order_by("-reference_code")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just a very long-winded way to do the same thing as

Case.objects.filter(
        licences__generatedcasedocument__template_id__in=[SIEL_TEMPLATE_ID, SIEL_REFUSAL_TEMPLATE_ID],
        licences__generatedcasedocument__visible_to_exporter=True,
        licences__generatedcasedocument__safe=True,
    ).distinct()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no because there won't be a licence for refused cases.
That was the initial change and as expected refusal cases were not filtered.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are both generated documents attached to the case and we could just skip the licences__ bit entirely for both?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be good to have some joined up thinking based on https://github.com/uktrade/lite-api/pull/2254/files#r1819089904 as it looks like we are diverging slightly with this particular heuristic and the future implementation.

)

def get_decision(self, case):
if case.licences.count():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this in a way that clarifies what the case.licences.count() is doing and why it's important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean just by adding a comment or annotate to a field and use that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whichever lets me know exactly why the case.licences.count matters.

Comment on lines 33 to 35
return LicenceDecisionType.ISSUED
else:
return LicenceDecisionType.REFUSED
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's mutually exclusive, but is it possible that something has been issued and then refused or vice versa?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked that, currently there are no such cases.
Because of amendments it is not possible going forward also but there is a possibility with Appeals.

kevincarrogan and others added 17 commits October 31, 2024 11:23
 - remove licence statuses endpoint for now
 - make tests work
Licence document generation date is taken for this purpose.
When all products on the application are NLR then the current code
allowed creation of a licence due a bug. This is not fixed yet so
exclude these cases as it can skew licence data.
In some case a licence is issued but subsequently application is
marked as withdrawn. Licence also should've been cancelled in this
case but we are not handling this atm so filter these cases.
As there can be multiple documents in these cases
Use Case as base object and use it to filter on the licence documents.
This avoids filtering of various case statuses, NLR products etc
Use the refusal letter generated date as the decision date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants