Skip to content

Commit

Permalink
Intacct: Handle Split Expense (#522)
Browse files Browse the repository at this point in the history
* Intacct: Handle Split Expense

* Split expense with tests

* bump version
  • Loading branch information
anishfyle authored Jul 9, 2024
1 parent 82b106c commit 8a540f6
Show file tree
Hide file tree
Showing 12 changed files with 558 additions and 15 deletions.
24 changes: 24 additions & 0 deletions apps/fyle/migrations/0032_auto_20240703_1818.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.14 on 2024-07-03 18:18

import apps.fyle.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('fyle', '0031_expense_paid_on_fyle'),
]

operations = [
migrations.AddField(
model_name='expense',
name='bank_transaction_id',
field=models.CharField(blank=True, help_text='Bank Transaction ID', max_length=255, null=True),
),
migrations.AddField(
model_name='expensegroupsettings',
name='split_expense_grouping',
field=models.CharField(choices=[('SINGLE_LINE_ITEM', 'SINGLE_LINE_ITEM'), ('MULTIPLE_LINE_ITEM', 'MULTIPLE_LINE_ITEM')], default=apps.fyle.models.get_default_split_expense_grouping, help_text='specify line items for split expenses grouping', max_length=100),
),
]
13 changes: 12 additions & 1 deletion apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
('PAYMENT_PROCESSING', 'PAYMENT_PROCESSING')
)


SPLIT_EXPENSE_GROUPING = (('SINGLE_LINE_ITEM', 'SINGLE_LINE_ITEM'), ('MULTIPLE_LINE_ITEM', 'MULTIPLE_LINE_ITEM'))

EXPENSE_FILTER_RANK = (
(1, 1),
(2, 2)
Expand Down Expand Up @@ -89,6 +92,10 @@ def get_default_expense_state():
def get_default_ccc_expense_state():
return 'PAID'

def get_default_split_expense_grouping():
return 'MULTIPLE_LINE_ITEM'


class Expense(models.Model):
"""
Expense
Expand Down Expand Up @@ -117,6 +124,7 @@ class Expense(models.Model):
cost_center = models.CharField(max_length=255, null=True, blank=True, help_text='Fyle Expense Cost Center')
purpose = models.TextField(null=True, blank=True, help_text='Purpose')
report_id = models.CharField(max_length=255, help_text='Report ID')
bank_transaction_id = models.CharField(max_length=255, null=True, blank=True, help_text='Bank Transaction ID')
spent_at = models.DateTimeField(null=True, help_text='Expense spent at')
approved_at = models.DateTimeField(null=True, help_text='Expense approved at')
posted_at = models.DateTimeField(null=True, help_text='Date when the money is taken from the bank')
Expand Down Expand Up @@ -179,6 +187,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int):
'purpose': expense['purpose'],
'report_id': expense['report_id'],
'report_title': expense['report_title'],
'bank_transaction_id': expense['bank_transaction_id'],
'spent_at': expense['spent_at'],
'approved_at': expense['approved_at'],
'posted_at': expense['posted_at'],
Expand Down Expand Up @@ -221,6 +230,7 @@ class ExpenseGroupSettings(models.Model):
choices=CCC_EXPENSE_STATE, help_text='state at which the ccc expenses are fetched (APPROVED/PAID)', null=True)
reimbursable_export_date_type = models.CharField(max_length=100, default='current_date', help_text='Export Date')
ccc_export_date_type = models.CharField(max_length=100, default='current_date', help_text='CCC Export Date')
split_expense_grouping = models.CharField(max_length=100, default=get_default_split_expense_grouping, choices=SPLIT_EXPENSE_GROUPING, help_text='specify line items for split expenses grouping')
workspace = models.OneToOneField(
Workspace, on_delete=models.PROTECT,
help_text='To which workspace this expense group setting belongs to',
Expand Down Expand Up @@ -321,7 +331,8 @@ def update_expense_group_settings(expense_group_settings: Dict, workspace_id: in
'expense_state': expense_group_settings['expense_state'],
'ccc_expense_state': expense_group_settings['ccc_expense_state'],
'reimbursable_export_date_type': expense_group_settings['reimbursable_export_date_type'],
'ccc_export_date_type': expense_group_settings['ccc_export_date_type']
'ccc_export_date_type': expense_group_settings['ccc_export_date_type'],
'split_expense_grouping': expense_group_settings['split_expense_grouping']
}
)

Expand Down
4 changes: 3 additions & 1 deletion apps/workspaces/apis/export_settings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class ExpenseGroupSettingsSerializer(serializers.ModelSerializer):
corporate_credit_card_expense_group_fields = serializers.ListField(allow_null=True, required=False)
ccc_export_date_type = serializers.CharField(allow_null=True, allow_blank=True, required=False)
ccc_expense_state = serializers.CharField(allow_null=True, allow_blank=True, required=False)
split_expense_grouping = serializers.CharField(allow_null=False, allow_blank=False, required=True)

class Meta:
model = ExpenseGroupSettings
Expand All @@ -112,7 +113,8 @@ class Meta:
'expense_state',
'corporate_credit_card_expense_group_fields',
'ccc_export_date_type',
'ccc_expense_state'
'ccc_expense_state',
'split_expense_grouping'
]


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ django-sendgrid-v5==1.2.0
future==0.18.2
fyle==0.37.0
fyle-accounting-mappings==1.32.1
fyle-integrations-platform-connector==1.38.1
fyle-integrations-platform-connector==1.38.3
fyle-rest-auth==1.7.2
gevent==23.9.1
gunicorn==20.1.0
Expand Down
5 changes: 5 additions & 0 deletions scripts/sql/scripts/032-mark-split-expense-grouping.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rollback;
begin;

UPDATE expense_group_settings
SET split_expense_grouping = 'SINGLE_LINE_ITEM';
6 changes: 6 additions & 0 deletions tests/sql_fixtures/migration_fixtures/create_migration.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
echo "Current working directory: $(pwd)"

echo "Checking if file exists:"
ls -l ../../../scripts/sql/scripts/032-mark-split-expense-grouping.sql

echo "Contents of scripts directory:"
ls -l ../../../scripts/sql/scripts/
# Setting value for DB Host
export DB_HOST=db

Expand Down
21 changes: 12 additions & 9 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,8 @@ CREATE TABLE public.expense_group_settings (
updated_at timestamp with time zone NOT NULL,
workspace_id integer NOT NULL,
ccc_export_date_type character varying(100) NOT NULL,
ccc_expense_state character varying(100)
ccc_expense_state character varying(100),
split_expense_grouping character varying(100) NOT NULL
);


Expand Down Expand Up @@ -1154,7 +1155,8 @@ CREATE TABLE public.expenses (
accounting_export_summary jsonb NOT NULL,
previous_export_state character varying(255),
workspace_id integer,
paid_on_fyle boolean NOT NULL
paid_on_fyle boolean NOT NULL,
bank_transaction_id character varying(255)
);


Expand Down Expand Up @@ -4108,6 +4110,7 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin;
182 tasks 0009_tasklog_supdoc_id 2024-05-20 09:36:04.874867+00
183 fyle 0031_expense_paid_on_fyle 2024-06-05 16:26:11.775475+00
184 workspaces 0034_configuration_is_journal_credit_billable 2024-06-19 07:16:22.418147+00
185 fyle 0032_auto_20240703_1818 2024-07-03 18:29:14.061756+00
\.


Expand Down Expand Up @@ -7497,8 +7500,8 @@ COPY public.expense_filters (id, condition, operator, "values", rank, join_by, i
-- Data for Name: expense_group_settings; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.expense_group_settings (id, reimbursable_expense_group_fields, corporate_credit_card_expense_group_fields, expense_state, reimbursable_export_date_type, created_at, updated_at, workspace_id, ccc_export_date_type, ccc_expense_state) FROM stdin;
1 {employee_email,report_id,claim_number,fund_source} {employee_email,report_id,expense_id,claim_number,fund_source} PAYMENT_PROCESSING current_date 2022-09-20 08:38:03.358472+00 2022-09-20 08:39:32.022875+00 1 spent_at PAID
COPY public.expense_group_settings (id, reimbursable_expense_group_fields, corporate_credit_card_expense_group_fields, expense_state, reimbursable_export_date_type, created_at, updated_at, workspace_id, ccc_export_date_type, ccc_expense_state, split_expense_grouping) FROM stdin;
1 {employee_email,report_id,claim_number,fund_source} {employee_email,report_id,expense_id,claim_number,fund_source} PAYMENT_PROCESSING current_date 2022-09-20 08:38:03.358472+00 2022-09-20 08:39:32.022875+00 1 spent_at PAID MULTIPLE_LINE_ITEM
\.


Expand Down Expand Up @@ -7544,10 +7547,10 @@ COPY public.expense_reports (id, employee_id, description, supdoc_id, created_at
-- Data for Name: expenses; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.expenses (id, employee_email, category, sub_category, project, expense_id, expense_number, claim_number, amount, currency, foreign_amount, foreign_currency, settlement_id, reimbursable, state, vendor, cost_center, purpose, report_id, spent_at, approved_at, expense_created_at, expense_updated_at, created_at, updated_at, fund_source, custom_properties, verified_at, billable, paid_on_sage_intacct, org_id, tax_amount, tax_group_id, file_ids, payment_number, corporate_card_id, is_skipped, report_title, posted_at, employee_name, accounting_export_summary, previous_export_state, workspace_id, paid_on_fyle) FROM stdin;
1 [email protected] Food \N Aaron Abbott txR9dyrqr1Jn E/2022/09/T/21 C/2022/09/R/21 21 USD \N \N setqwcKcC9q1k t PAYMENT_PROCESSING Ashwin Marketing \N rpEZGqVCyWxQ 2022-09-20 17:00:00+00 2022-09-19 19:54:36.96+00 2022-09-19 19:54:15.870239+00 2022-09-19 19:55:58.641995+00 2022-09-20 08:48:21.737374+00 2022-09-20 08:48:21.737392+00 PERSONAL {"Team": "", "Class": "", "Klass": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "Team 2 Postman": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": "", "Custom Expense Field": null} \N \N f or79Cob97KSh \N \N {} P/2022/09/R/18 \N f \N \N \N {} \N \N f
2 [email protected] Food \N Aaron Abbott txCqLqsEnAjf E/2022/09/T/22 C/2022/09/R/22 11 USD \N \N setzhjuqQ6Pl5 f PAYMENT_PROCESSING Ashwin Marketing \N rpSTYO8AfUVA 2022-09-20 17:00:00+00 2022-09-20 08:50:48.428+00 2022-09-20 08:50:27.570399+00 2022-09-20 08:51:13.891379+00 2022-09-20 08:51:27.566571+00 2022-09-20 08:51:27.566598+00 CCC {"Team": "", "Class": "", "Klass": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "Team 2 Postman": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": "", "Custom Expense Field": null} \N t f or79Cob97KSh 2.41 tggu76WXIdjY {} P/2022/09/R/19 \N f \N \N \N {} \N \N f
3 [email protected] Taxi \N Aaron Abbott txTHfEPWOEOp E/2022/09/T/23 C/2022/09/R/23 22 USD \N \N set0SnAq66Zbq f PAYMENT_PROCESSING Ashwin Marketing \N rpBf5ibqUT6B 2022-09-20 17:00:00+00 2022-09-20 08:56:09.337+00 2022-09-20 08:55:53.246893+00 2022-09-20 08:56:40.795304+00 2022-09-20 08:56:50.117313+00 2022-09-20 08:56:50.117349+00 CCC {"Team": "", "Class": "", "Klass": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "Team 2 Postman": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": "", "Custom Expense Field": null} \N \N f or79Cob97KSh 4.81 tggu76WXIdjY {} P/2022/09/R/20 \N f \N \N \N {} \N \N f
COPY public.expenses (id, employee_email, category, sub_category, project, expense_id, expense_number, claim_number, amount, currency, foreign_amount, foreign_currency, settlement_id, reimbursable, state, vendor, cost_center, purpose, report_id, spent_at, approved_at, expense_created_at, expense_updated_at, created_at, updated_at, fund_source, custom_properties, verified_at, billable, paid_on_sage_intacct, org_id, tax_amount, tax_group_id, file_ids, payment_number, corporate_card_id, is_skipped, report_title, posted_at, employee_name, accounting_export_summary, previous_export_state, workspace_id, paid_on_fyle, bank_transaction_id) FROM stdin;
1 [email protected] Food \N Aaron Abbott txR9dyrqr1Jn E/2022/09/T/21 C/2022/09/R/21 21 USD \N \N setqwcKcC9q1k t PAYMENT_PROCESSING Ashwin Marketing \N rpEZGqVCyWxQ 2022-09-20 17:00:00+00 2022-09-19 19:54:36.96+00 2022-09-19 19:54:15.870239+00 2022-09-19 19:55:58.641995+00 2022-09-20 08:48:21.737374+00 2022-09-20 08:48:21.737392+00 PERSONAL {"Team": "", "Class": "", "Klass": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "Team 2 Postman": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": "", "Custom Expense Field": null} \N \N f or79Cob97KSh \N \N {} P/2022/09/R/18 \N f \N \N \N {} \N \N f \N
2 [email protected] Food \N Aaron Abbott txCqLqsEnAjf E/2022/09/T/22 C/2022/09/R/22 11 USD \N \N setzhjuqQ6Pl5 f PAYMENT_PROCESSING Ashwin Marketing \N rpSTYO8AfUVA 2022-09-20 17:00:00+00 2022-09-20 08:50:48.428+00 2022-09-20 08:50:27.570399+00 2022-09-20 08:51:13.891379+00 2022-09-20 08:51:27.566571+00 2022-09-20 08:51:27.566598+00 CCC {"Team": "", "Class": "", "Klass": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "Team 2 Postman": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": "", "Custom Expense Field": null} \N t f or79Cob97KSh 2.41 tggu76WXIdjY {} P/2022/09/R/19 \N f \N \N \N {} \N \N f \N
3 [email protected] Taxi \N Aaron Abbott txTHfEPWOEOp E/2022/09/T/23 C/2022/09/R/23 22 USD \N \N set0SnAq66Zbq f PAYMENT_PROCESSING Ashwin Marketing \N rpBf5ibqUT6B 2022-09-20 17:00:00+00 2022-09-20 08:56:09.337+00 2022-09-20 08:55:53.246893+00 2022-09-20 08:56:40.795304+00 2022-09-20 08:56:50.117313+00 2022-09-20 08:56:50.117349+00 CCC {"Team": "", "Class": "", "Klass": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "Team 2 Postman": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": "", "Custom Expense Field": null} \N \N f or79Cob97KSh 4.81 tggu76WXIdjY {} P/2022/09/R/20 \N f \N \N \N {} \N \N f \N
\.


Expand Down Expand Up @@ -8115,7 +8118,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 50, true);
-- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.django_migrations_id_seq', 184, true);
SELECT pg_catalog.setval('public.django_migrations_id_seq', 185, true);


--
Expand Down
Loading

0 comments on commit 8a540f6

Please sign in to comment.