Repository navigation
Feature/3257 - Unassign transactions on report coverage change #2294
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from django.db import transaction | ||
| from django.db.transaction import atomic | ||
| from fecfiler.settings import FLAG__ENABLE_UNASSIGNED_TRANSACTIONS | ||
| from fecfiler.reports.models import Report, ReportTransaction | ||
| from fecfiler.reports.form_3.models import Form3 | ||
| from fecfiler.reports.serializers import ( | ||
|
|
@@ -62,45 +63,50 @@ def save(self, **kwargs): | |
| return super().save(**kwargs) | ||
|
|
||
| def update(self, instance, validated_data): | ||
| prior_coverage_through_date = instance.coverage_through_date | ||
| prior_coverage_from_date = instance.coverage_from_date | ||
| with atomic(): | ||
| prior_coverage_through_date = instance.coverage_through_date | ||
| prior_coverage_from_date = instance.coverage_from_date | ||
|
|
||
| transactions_outside_coverage_dates = ReportTransaction.objects.filter( | ||
| ~Q(transaction__memo_code=True), | ||
| self.get_transaction_date_outside_coverage_dates_clause(), | ||
| transaction__deleted=None, | ||
| report_id=instance.id, | ||
| ).count() | ||
| transactions_outside_coverage_dates = ReportTransaction.objects.filter( | ||
| ~Q(transaction__memo_code=True), | ||
| self.get_transaction_date_outside_coverage_dates_clause(), | ||
| transaction__deleted=None, | ||
| report_id=instance.id, | ||
| ) | ||
| if transactions_outside_coverage_dates.exists(): | ||
| if FLAG__ENABLE_UNASSIGNED_TRANSACTIONS: | ||
| transactions_outside_coverage_dates.delete() | ||
| if instance.can_unamend: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch!! |
||
| instance.can_unamend = False | ||
| else: | ||
| raise COVERAGE_DATES_EXCLUDE_EXISTING_TRANSACTIONS | ||
|
|
||
| if transactions_outside_coverage_dates > 0: | ||
| raise COVERAGE_DATES_EXCLUDE_EXISTING_TRANSACTIONS | ||
| if self.overlaps_other_f3_report( | ||
| instance.id, | ||
| instance.committee_account.id, | ||
| validated_data, | ||
| ): | ||
| raise COVERAGE_DATE_REPORT_CODE_COLLISION | ||
|
|
||
| if self.overlaps_other_f3_report( | ||
| instance.id, | ||
| instance.committee_account.id, | ||
| validated_data, | ||
| ): | ||
| raise COVERAGE_DATE_REPORT_CODE_COLLISION | ||
| form = getattr(instance, self.related_form_attr) | ||
|
|
||
| form = getattr(instance, self.related_form_attr) | ||
| for attr, value in validated_data.items(): | ||
| if attr != "id": | ||
| setattr(form, attr, value) | ||
|
|
||
| for attr, value in validated_data.items(): | ||
| if attr != "id": | ||
| setattr(form, attr, value) | ||
| form.save() | ||
|
|
||
| form.save() | ||
| updated = super().update(instance, validated_data) | ||
|
|
||
| updated = super().update(instance, validated_data) | ||
|
|
||
| coverage_from_changed = prior_coverage_from_date != updated.coverage_from_date | ||
| coverage_through_changed = ( | ||
| prior_coverage_through_date != updated.coverage_through_date | ||
| ) | ||
| coverage_from_changed = prior_coverage_from_date != updated.coverage_from_date | ||
| coverage_through_changed = ( | ||
| prior_coverage_through_date != updated.coverage_through_date | ||
| ) | ||
|
|
||
| if coverage_from_changed or coverage_through_changed: | ||
| Report.mark_calculations_dirty(Report.objects.filter(id=updated.id)) | ||
| if coverage_from_changed or coverage_through_changed: | ||
| Report.mark_calculations_dirty(Report.objects.filter(id=updated.id)) | ||
|
|
||
| return updated | ||
| return updated | ||
|
|
||
| def get_transaction_date_outside_coverage_dates_clause(self): | ||
| """Returns a clause that checks if the transaction date is outside | ||
|
|
@@ -407,7 +413,7 @@ class Form3Serializer(BaseForm3Serializer): | |
| ) | ||
|
|
||
| def create(self, validated_data: dict): | ||
| with transaction.atomic(): | ||
| with atomic(): | ||
| form_3_data = get_model_data(validated_data, Form3) | ||
| report_data = get_model_data(validated_data, Report) | ||
| form_3 = Form3.objects.create(**form_3_data) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nice clean and simple