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 5681 update licence decision refusal criteria #2333

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

kevincarrogan
Copy link
Contributor

@kevincarrogan kevincarrogan commented Dec 6, 2024

Aim

This updates refusal licence decisions with the relevant refusal criteria.

This is so that the reason for refusal is directly attached to the licence decision model itself instead of being attached to the advice record.

The migration initially just uses the final advice from LU but in some cases older cases don't have this advice record so we fall back on using audit entries for this instead.

LTD-5681

@kevincarrogan kevincarrogan force-pushed the LTD-5681-update-licence-decision-refusal-criteria branch 4 times, most recently from 8f5dc3f to c4216bc Compare December 6, 2024 13:43
@kevincarrogan kevincarrogan marked this pull request as ready for review December 10, 2024 12:18
code-review-doctor[bot]

This comment was marked as resolved.

@kevincarrogan kevincarrogan force-pushed the LTD-5681-update-licence-decision-refusal-criteria branch 2 times, most recently from f57b5b8 to ee8712a Compare December 10, 2024 12:53
@kevincarrogan kevincarrogan force-pushed the LTD-5681-update-licence-decision-refusal-criteria branch from 30f198e to 624da9b Compare December 11, 2024 14:38
Comment on lines 35 to 39
for denial_reason, licence_decision_id in denial_reasons:
licence_decision = LicenceDecision.objects.get(pk=licence_decision_id)
licence_decision.denial_reasons.add(denial_reason)

updated_cases = set()
for denial_reason, licence_decision_id in denial_reasons:
licence_decision = LicenceDecision.objects.get(pk=licence_decision_id)
licence_decision.denial_reasons.add(denial_reason)
updated_cases.add(licence_decision.case.pk)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like duplicate loops..?

if not refusal_licence_decisions.exists():
continue
for licence_decision in refusal_licence_decisions:
denial_reasons = audit.payload["additional_text"].replace(".", "").replace(" ", "").split(",")
Copy link
Contributor

@currycoder currycoder Dec 12, 2024

Choose a reason for hiding this comment

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

These need to be valid DenialReason.id values, right? Is it worth checking against a list of valid ids first? Or is the thought that this will fail with an IntegrityError or similar on the set() below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It hasn't failed when running on the production-like data so far so I've not worried about this.

LICENSING_UNIT_ID = "58e77e47-42c8-499f-a58d-94f94541f8c6"


def update_licencedecision_denial_reasons(apps, schema_editor):
Copy link
Contributor

Choose a reason for hiding this comment

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

Has this been run against a recent anonymised copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been.

Comment on lines +1 to +32
import factory


def get_model_for_factory(factory_class, apps):
model_meta = factory_class._meta.model._meta

return apps.get_model(model_meta.app_label, model_meta.object_name)


def fullname(cls):
return f"{cls.__module__}.{cls.__name__}"


def generate_factory(apps, factory_class, **defaults):
for field_name, field_value in factory_class._meta.declarations.items():
if field_name in defaults:
continue
if not isinstance(field_value, factory.declarations.SubFactory):
continue
generated_factory = generate_factory(
apps,
field_value.get_factory(),
**field_value.defaults,
)
defaults[field_name] = factory.declarations.SubFactory(generated_factory)

updated_factory = factory.make_factory(
get_model_for_factory(factory_class, apps),
**defaults,
FACTORY_CLASS=factory_class,
)
return updated_factory
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this get used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't currently. I can get rid of it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you plan to use it somehow I'm ok with it staying, was just trying to work out if there was something else going on

Copy link
Contributor

@saruniitr saruniitr left a comment

Choose a reason for hiding this comment

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

with other comments addressed, it looks good to me.

@kevincarrogan kevincarrogan force-pushed the LTD-5681-update-licence-decision-refusal-criteria branch from 624da9b to 5c35e70 Compare December 12, 2024 14:22
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