From 96fee286f901108f90e75d5c76f8d716d9028577 Mon Sep 17 00:00:00 2001 From: Anish Kr Singh <116036738+anishfyle@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:04:39 +0530 Subject: [PATCH] add account to memo (#104) * add account to memo * fixes * category = account if account else expense.category --- apps/qbd/models.py | 8 +++++--- scripts/python/002_add_field_mapping.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 scripts/python/002_add_field_mapping.py diff --git a/apps/qbd/models.py b/apps/qbd/models.py index fde1581..d734a34 100644 --- a/apps/qbd/models.py +++ b/apps/qbd/models.py @@ -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 @@ -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 '', @@ -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, diff --git a/scripts/python/002_add_field_mapping.py b/scripts/python/002_add_field_mapping.py new file mode 100644 index 0000000..d1fe8db --- /dev/null +++ b/scripts/python/002_add_field_mapping.py @@ -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__)