-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix: expense migration #176
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.1.2 on 2024-11-22 10:15 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('fyle', '0003_remove_expense_settlement_id'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='expense', | ||
name='is_posted_at_null', | ||
field=models.BooleanField(default=False, help_text='Flag check if posted at is null or not'), | ||
), | ||
] | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -104,6 +104,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: | |||||
|
||||||
# Create an empty list to store expense objects | ||||||
expense_objects = [] | ||||||
print(expenses) | ||||||
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. print pls remove 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. removed sir 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. fixed |
||||||
|
||||||
for expense in expenses: | ||||||
# Iterate through custom property fields and handle empty values | ||||||
|
@@ -145,6 +146,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: | |||||
'report_id': expense['report_id'], | ||||||
'spent_at': expense['spent_at'], | ||||||
'posted_at': expense['posted_at'], | ||||||
'is_posted_at_null': expense['is_posted_at_null'], | ||||||
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. 🛠️ Refactor suggestion Add input validation for The method assumes defaults = {
- 'is_posted_at_null': expense['is_posted_at_null'],
+ 'is_posted_at_null': bool(expense.get('is_posted_at_null', False)),
'fund_source': SOURCE_ACCOUNT_MAP[expense['source_account_type']], 📝 Committable suggestion
Suggested change
|
||||||
'fund_source': SOURCE_ACCOUNT_MAP[expense['source_account_type']], | ||||||
'verified_at': expense['verified_at'], | ||||||
'custom_properties': expense['custom_properties'], | ||||||
|
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.
Add data migration for existing records.
The migration adds the field with a default False value, but existing records should have this field populated based on their actual
posted_at
values. Consider adding a data migration to set the correct values.Would you like me to help create a data migration that:
is_posted_at_null=True
for records whereposted_at IS NULL
is_posted_at_null=False
for records whereposted_at IS NOT NULL