-
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
PR1: add support for accounting export and expense creations #72
Conversation
|
|
apps/fyle/models.py
Outdated
) | ||
|
||
# Doing this to avoid circular import | ||
AccountingExport = import_string('apps.accounting_exports.models.AccountingExport') |
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.
this is to avoid circular import
apps/fyle/models.py
Outdated
AccountingExport = import_string('apps.accounting_exports.models.AccountingExport') | ||
|
||
# Check if an AccountingExport related to the expense object already exists | ||
if not AccountingExport.objects.filter(expenses__id=expense_object.id).first(): |
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.
expenses_with_accounting_export = Expense.objects.filter(accountingexport__isnull=False).distinct()
Try something like this
apps/accounting_exports/models.py
Outdated
@@ -50,6 +100,56 @@ class AccountingExport(BaseForeignWorkspaceModel): | |||
class Meta: | |||
db_table = 'accounting_exports' | |||
|
|||
@staticmethod | |||
def create_accounting_export_report_id(expense_objects: List[Expense], fund_source: str, workspace_id): |
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.
def create_accounting_export_report_id(expense_objects: List[Expense], fund_source: str, workspace_id): | |
def create_accounting_export(expense_objects: List[Expense], fund_source: str, workspace_id): |
apps/accounting_exports/models.py
Outdated
reimbursable_expense_date = export_setting.reimbursable_expense_date | ||
|
||
if fund_source == 'CCC': | ||
group_fields = ['report_id', 'claim_number'] if credit_card_expense_grouped_by == 'REPORT' else ['expense_id', 'expense_number'] |
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.
{
'CCC': {
'REPORT': [..],
'EXPENSE': [..]
}
}
apps/accounting_exports/models.py
Outdated
if credit_card_expense_date != 'LAST_SPENT_AT': | ||
group_fields.append(credit_card_expense_date.lower()) | ||
|
||
if fund_source == 'PERSONAL': |
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.
the group fields are same, you can merge the two condition
|
||
# Extract expense IDs from the provided expenses | ||
expense_ids = [expense.id for expense in expenses] | ||
|
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 something like
group_fields.append(fund_source)
apps/accounting_exports/models.py
Outdated
|
||
# Format date fields according to the specified format | ||
for key in expense_group: | ||
if key in ALLOWED_FORM_INPUT['export_date_type']: |
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.
ALLOWED_FORM_INPUT and all is not required
apps/accounting_exports/models.py
Outdated
expense_group_fields = ['employee_email', 'fund_source'] | ||
|
||
# Group expenses based on specified fields and fund_source | ||
expense_groups = _group_expenses(expense_objects, expense_group_fields, export_setting, fund_source) |
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.
user term accounting_exports
everywhere
remove expense_groups
completely
apps/accounting_exports/models.py
Outdated
|
||
for expense_group in expense_groups: | ||
# Determine the date field based on fund_source | ||
if fund_source == 'PERSONAL': |
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.
the conditions can be cleaned up using dictionaties
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.
data = EXPORT_SETTINGS_CONFIG[fund_source]['date_field']
apps/accounting_exports/models.py
Outdated
from apps.fyle.models import Expense | ||
|
||
|
||
ALLOWED_FIELDS = [ |
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.
remove this
|
No description provided.