Skip to content

Commit

Permalink
add account to memo (#104)
Browse files Browse the repository at this point in the history
* add account to memo

* fixes

* category = account if account else expense.category
  • Loading branch information
anishfyle committed Aug 8, 2024
1 parent 01ddda7 commit 22a9de9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions apps/qbd/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_transaction_date(expenses: List[Expense], date_preference: str) -> str:
return datetime.now()


def get_expense_purpose(workspace_id: str, expense: Expense) -> str:
def get_expense_purpose(workspace_id: str, expense: Expense, account: str = None) -> str:
"""
Get Expense Purpose
:param workspace_id: Workspace ID
Expand All @@ -105,11 +105,13 @@ def get_expense_purpose(workspace_id: str, expense: Expense) -> str:

expense_memo_structure = advanced_settings.expense_memo_structure

category = account if account else expense.category

details = {
'employee_name': expense.employee_name,
'employee_email': expense.employee_email,
'merchant': '{0}'.format(expense.vendor) if expense.vendor else '',
'category': '{0}'.format(expense.category) if expense.category else '',
'category': '{0}'.format(category) if category else '',
'purpose': '{0}'.format(expense.purpose) if expense.purpose else '',
'report_number': '{0}'.format(expense.claim_number),
'spent_on': '{0}'.format(expense.spent_at.date()) if expense.spent_at else '',
Expand Down Expand Up @@ -560,7 +562,7 @@ def create_credit_card_purchase_lineitems(
name=project_name,
class_name=class_name,
amount=expense.amount,
memo=get_expense_purpose(workspace_id, expense),
memo=get_expense_purpose(workspace_id, expense, account),
reimbursable_expense='No',
credit_card_purchase=credit_card_purchase,
expense=expense,
Expand Down
13 changes: 13 additions & 0 deletions scripts/python/002_add_field_mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Create field mapping for existing workspaces

from apps.workspaces.models import Workspace, FieldMapping

workspaces = Workspace.objects.exclude(fieldmapping__isnull=False)

for workspace in workspaces:
try:
FieldMapping.objects.create(workspace_id = workspace.id)
print('Field mapping created for workspace - {} with ID - {}'.format(workspace.name, workspace.id))
except Exception as e:
print('Error while creating field mapping for workspace - {} with ID - {}'.format(workspace.name, workspace.id))
print(e.__dict__)

0 comments on commit 22a9de9

Please sign in to comment.