-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: dev
Are you sure you want to change the base?
Ltd 5681 update licence decision refusal criteria #2333
Conversation
8f5dc3f
to
c4216bc
Compare
f57b5b8
to
ee8712a
Compare
api/cases/migrations/0074_update_licence_decision_denial_reasons.py
Outdated
Show resolved
Hide resolved
api/cases/migrations/0074_update_licence_decision_denial_reasons.py
Outdated
Show resolved
Hide resolved
30f198e
to
624da9b
Compare
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) |
There was a problem hiding this comment.
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(",") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
This is to ensure that the ordering of migrations are correct and that data migrations have access to all of the model fields they require
624da9b
to
5c35e70
Compare
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