From da172351902b1a50c91538d91714d54ef3984333 Mon Sep 17 00:00:00 2001 From: Anish Kr Singh <116036738+anishfyle@users.noreply.github.com> Date: Mon, 18 Nov 2024 14:36:10 +0530 Subject: [PATCH] feat: handle posted at (#661) * handle posted at * migrations, reset db, conftest * feat: auto enable accounting period (#668) * feat: auto enable accounting period * reset db * platform connector ver --- .../0034_expense_is_posted_at_null.py | 18 ++++++ apps/fyle/models.py | 1 + ..._configuration_change_accounting_period.py | 18 ++++++ apps/workspaces/models.py | 2 +- requirements.txt | 2 +- .../reset_db_fixtures/reset_db.sql | 61 ++++++++++--------- tests/test_netsuite/conftest.py | 4 +- 7 files changed, 75 insertions(+), 31 deletions(-) create mode 100644 apps/fyle/migrations/0034_expense_is_posted_at_null.py create mode 100644 apps/workspaces/migrations/0040_alter_configuration_change_accounting_period.py diff --git a/apps/fyle/migrations/0034_expense_is_posted_at_null.py b/apps/fyle/migrations/0034_expense_is_posted_at_null.py new file mode 100644 index 00000000..e19df8e9 --- /dev/null +++ b/apps/fyle/migrations/0034_expense_is_posted_at_null.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.14 on 2024-11-17 20:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fyle', '0033_expense_paid_on_fyle'), + ] + + 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'), + ), + ] diff --git a/apps/fyle/models.py b/apps/fyle/models.py index 9eb1ff6a..3227c774 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -107,6 +107,7 @@ class Expense(models.Model): 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') + is_posted_at_null = models.BooleanField(default=False, help_text='Flag check if posted at is null or not') expense_created_at = models.DateTimeField(help_text='Expense created at') expense_updated_at = models.DateTimeField(help_text='Expense created at') created_at = models.DateTimeField(auto_now_add=True, help_text='Created at') diff --git a/apps/workspaces/migrations/0040_alter_configuration_change_accounting_period.py b/apps/workspaces/migrations/0040_alter_configuration_change_accounting_period.py new file mode 100644 index 00000000..5cb0cd39 --- /dev/null +++ b/apps/workspaces/migrations/0040_alter_configuration_change_accounting_period.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.14 on 2024-11-18 02:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0039_configuration_je_single_credit_line'), + ] + + operations = [ + migrations.AlterField( + model_name='configuration', + name='change_accounting_period', + field=models.BooleanField(default=True, help_text='Change the accounting period'), + ), + ] diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index 606f4931..cef4474a 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -155,7 +155,7 @@ class Configuration(models.Model): import_projects = models.BooleanField(default=False, help_text='Auto import projects to Fyle') import_vendors_as_merchants = models.BooleanField(default=False, help_text='Auto import vendors from netsuite as merchants to Fyle') import_netsuite_employees = models.BooleanField(default=False, help_text='Auto import employees from netsuite as employees to Fyle') - change_accounting_period = models.BooleanField(default=False, help_text='Change the accounting period') + change_accounting_period = models.BooleanField(default=True, help_text='Change the accounting period') sync_fyle_to_netsuite_payments = models.BooleanField( default=False, help_text='Auto Sync Payments from Fyle to Netsuite' ) diff --git a/requirements.txt b/requirements.txt index 7eacc432..56b036ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,7 @@ enum34==1.1.10 future==0.18.2 fyle==0.37.0 fyle-accounting-mappings==1.34.8 -fyle-integrations-platform-connector==1.38.4 +fyle-integrations-platform-connector==1.39.3 fyle-rest-auth==1.7.2 gunicorn==20.1.0 gevent==23.9.1 diff --git a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql index f899ec84..55889c0f 100644 --- a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql +++ b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 15.7 (Debian 15.7-1.pgdg120+1) --- Dumped by pg_dump version 15.8 (Debian 15.8-1.pgdg120+1) +-- Dumped from database version 15.9 (Debian 15.9-1.pgdg120+1) +-- Dumped by pg_dump version 15.9 (Debian 15.9-1.pgdg120+1) SET statement_timeout = 0; SET lock_timeout = 0; @@ -1148,7 +1148,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, + is_posted_at_null boolean NOT NULL ); @@ -7986,6 +7987,9 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin; 198 netsuite 0027_auto_20240924_0820 2024-09-24 08:24:35.223017+00 199 fyle_accounting_mappings 0026_destinationattribute_code 2024-10-01 08:54:06.770864+00 200 workspaces 0039_configuration_je_single_credit_line 2024-10-11 13:43:49.169823+00 +201 fyle 0034_expense_is_posted_at_null 2024-11-17 20:37:53.17847+00 +202 tasks 0012_alter_tasklog_expense_group 2024-11-17 20:37:53.213044+00 +203 workspaces 0040_alter_configuration_change_accounting_period 2024-11-18 04:28:36.094429+00 \. @@ -11627,15 +11631,15 @@ COPY public.expense_reports (id, account_id, entity_id, currency, department_id, -- 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, paid_on_netsuite, billable, org_id, tax_amount, tax_group_id, project_id, file_ids, corporate_card_id, is_skipped, report_title, employee_name, posted_at, accounting_export_summary, previous_export_state, workspace_id, paid_on_fyle) FROM stdin; -1 ashwin.t@fyle.in Accounts Payable Accounts Payable \N txjvDntD9ZXR E/2021/11/T/11 C/2021/11/R/5 50 USD \N \N set6GUp6tcEEp t PAYMENT_PROCESSING \N Treasury \N rpuN3bgphxbK 2021-11-15 00:00:00+00 2021-11-15 00:00:00+00 2021-11-15 10:27:53.649+00 2021-11-15 10:28:46.775+00 2021-11-15 10:29:07.597095+00 2021-11-15 10:29:07.597111+00 PERSONAL {"Team": "", "Class": "", "Klass": "", "Team 2": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": ""} \N f \N or79Cob97KSh \N \N \N \N \N f \N \N \N {} \N \N f -2 ashwin.t@fyle.in Accounts Payable Accounts Payable \N txy6folbrG2j E/2021/11/T/12 C/2021/11/R/6 100 USD \N \N setNVTcPkZ6on f PAYMENT_PROCESSING Ashwin Vendor \N \N rpHLA9Dfp9hN 2021-11-15 00:00:00+00 2021-11-15 00:00:00+00 2021-11-15 13:11:22.304+00 2021-11-15 13:11:58.032+00 2021-11-15 13:12:12.250613+00 2021-11-15 13:12:12.250638+00 CCC {"Team": "", "Class": "", "Klass": "Klass", "Team 2": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": ""} \N f \N or79Cob97KSh \N \N \N \N \N f \N \N \N {} \N \N f -3 ashwin.t@fyle.in Accounts Payable Accounts Payable \N txeLau9Rdu4X E/2021/11/T/1 C/2021/11/R/2 80 USD \N \N setqgvGQnsAya t PAYMENT_PROCESSING \N \N \N rpu5W0LYrk6e 2021-11-16 00:00:00+00 2021-11-16 00:00:00+00 2021-11-16 04:24:18.688+00 2021-11-16 04:25:21.996+00 2021-11-16 04:25:49.174565+00 2021-11-16 04:25:49.174584+00 PERSONAL {"Klass": "Klass", "Device Type": "", "Fyle Category": ""} \N f \N oraWFQlEpjbb 4.53 tg31j9m4PoEO \N \N \N f \N \N \N {} \N \N f -4 ashwin.t@fyle.in Accounts Payable Accounts Payable \N txMLGb6Xy8m8 E/2021/11/T/2 C/2021/11/R/1 100 USD \N \N setqgvGQnsAya f PAYMENT_PROCESSING \N \N \N rprqDvARHUnv 2021-11-16 00:00:00+00 2021-11-16 00:00:00+00 2021-11-16 04:24:38.141+00 2021-11-16 04:25:21.996+00 2021-11-16 04:25:49.192351+00 2021-11-16 04:25:49.192367+00 CCC {"Device Type": "", "Fyle Category": ""} \N f \N oraWFQlEpjbb 16.67 tgSYjXsBCviv \N \N \N f \N \N \N {} \N \N f -173 admin1@fyleforintacct.in Food Food Project 2 tx7A5QpesrV5 E/2021/12/T/1 C/2021/12/R/1 120 USD \N \N set15sMvtRIiS t PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85N 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:30.076+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.685597+00 2021-12-03 11:26:58.685616+00 PERSONAL {} \N f \N orHe8CpW2hyN \N \N \N \N \N f \N \N \N {} \N \N f -174 admin1@fyleforintacct.in Food Food Project 2 txcKVVELn1Vl E/2021/12/T/2 C/2021/12/R/1 130 USD \N \N set15sMvtRIiS f PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85N 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:49.51+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.702183+00 2021-12-03 11:26:58.702209+00 CCC {} \N f \N orHe8CpW2hyN \N \N \N \N \N f \N \N \N {} \N \N f -600 jhonsnoww@fyle.in Food Food Project 2 txcKVVELn1Vlkill E/2021/12/T/298 C/2021/12/R/198 130 USD \N \N set15sMvtRIiSkill f PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85Nkill 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:49.51+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.702183+00 2021-12-03 11:26:58.702209+00 CCC {} \N f \N or79Cob97KSh \N \N \N \N \N t \N \N \N {} \N \N f -601 jhonsnoww@fyle.in Food Food Project 2 txcKVVELn1Vlgon E/2021/12/T/299 C/2021/12/R/199 130 USD \N \N set15sMvtRIiSgon f PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85Ngon 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:49.51+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.702183+00 2021-12-03 11:26:58.702209+00 CCC {} \N f \N or79Cob97KSh \N \N \N \N \N t \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, paid_on_netsuite, billable, org_id, tax_amount, tax_group_id, project_id, file_ids, corporate_card_id, is_skipped, report_title, employee_name, posted_at, accounting_export_summary, previous_export_state, workspace_id, paid_on_fyle, is_posted_at_null) FROM stdin; +1 ashwin.t@fyle.in Accounts Payable Accounts Payable \N txjvDntD9ZXR E/2021/11/T/11 C/2021/11/R/5 50 USD \N \N set6GUp6tcEEp t PAYMENT_PROCESSING \N Treasury \N rpuN3bgphxbK 2021-11-15 00:00:00+00 2021-11-15 00:00:00+00 2021-11-15 10:27:53.649+00 2021-11-15 10:28:46.775+00 2021-11-15 10:29:07.597095+00 2021-11-15 10:29:07.597111+00 PERSONAL {"Team": "", "Class": "", "Klass": "", "Team 2": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": ""} \N f \N or79Cob97KSh \N \N \N \N \N f \N \N \N {} \N \N f f +2 ashwin.t@fyle.in Accounts Payable Accounts Payable \N txy6folbrG2j E/2021/11/T/12 C/2021/11/R/6 100 USD \N \N setNVTcPkZ6on f PAYMENT_PROCESSING Ashwin Vendor \N \N rpHLA9Dfp9hN 2021-11-15 00:00:00+00 2021-11-15 00:00:00+00 2021-11-15 13:11:22.304+00 2021-11-15 13:11:58.032+00 2021-11-15 13:12:12.250613+00 2021-11-15 13:12:12.250638+00 CCC {"Team": "", "Class": "", "Klass": "Klass", "Team 2": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": ""} \N f \N or79Cob97KSh \N \N \N \N \N f \N \N \N {} \N \N f f +3 ashwin.t@fyle.in Accounts Payable Accounts Payable \N txeLau9Rdu4X E/2021/11/T/1 C/2021/11/R/2 80 USD \N \N setqgvGQnsAya t PAYMENT_PROCESSING \N \N \N rpu5W0LYrk6e 2021-11-16 00:00:00+00 2021-11-16 00:00:00+00 2021-11-16 04:24:18.688+00 2021-11-16 04:25:21.996+00 2021-11-16 04:25:49.174565+00 2021-11-16 04:25:49.174584+00 PERSONAL {"Klass": "Klass", "Device Type": "", "Fyle Category": ""} \N f \N oraWFQlEpjbb 4.53 tg31j9m4PoEO \N \N \N f \N \N \N {} \N \N f f +4 ashwin.t@fyle.in Accounts Payable Accounts Payable \N txMLGb6Xy8m8 E/2021/11/T/2 C/2021/11/R/1 100 USD \N \N setqgvGQnsAya f PAYMENT_PROCESSING \N \N \N rprqDvARHUnv 2021-11-16 00:00:00+00 2021-11-16 00:00:00+00 2021-11-16 04:24:38.141+00 2021-11-16 04:25:21.996+00 2021-11-16 04:25:49.192351+00 2021-11-16 04:25:49.192367+00 CCC {"Device Type": "", "Fyle Category": ""} \N f \N oraWFQlEpjbb 16.67 tgSYjXsBCviv \N \N \N f \N \N \N {} \N \N f f +173 admin1@fyleforintacct.in Food Food Project 2 tx7A5QpesrV5 E/2021/12/T/1 C/2021/12/R/1 120 USD \N \N set15sMvtRIiS t PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85N 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:30.076+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.685597+00 2021-12-03 11:26:58.685616+00 PERSONAL {} \N f \N orHe8CpW2hyN \N \N \N \N \N f \N \N \N {} \N \N f f +174 admin1@fyleforintacct.in Food Food Project 2 txcKVVELn1Vl E/2021/12/T/2 C/2021/12/R/1 130 USD \N \N set15sMvtRIiS f PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85N 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:49.51+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.702183+00 2021-12-03 11:26:58.702209+00 CCC {} \N f \N orHe8CpW2hyN \N \N \N \N \N f \N \N \N {} \N \N f f +600 jhonsnoww@fyle.in Food Food Project 2 txcKVVELn1Vlkill E/2021/12/T/298 C/2021/12/R/198 130 USD \N \N set15sMvtRIiSkill f PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85Nkill 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:49.51+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.702183+00 2021-12-03 11:26:58.702209+00 CCC {} \N f \N or79Cob97KSh \N \N \N \N \N t \N \N \N {} \N \N f f +601 jhonsnoww@fyle.in Food Food Project 2 txcKVVELn1Vlgon E/2021/12/T/299 C/2021/12/R/199 130 USD \N \N set15sMvtRIiSgon f PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85Ngon 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:49.51+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.702183+00 2021-12-03 11:26:58.702209+00 CCC {} \N f \N or79Cob97KSh \N \N \N \N \N t \N \N \N {} \N \N f f \. @@ -11897,7 +11901,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 47, true); -- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres -- -SELECT pg_catalog.setval('public.django_migrations_id_seq', 200, true); +SELECT pg_catalog.setval('public.django_migrations_id_seq', 203, true); -- @@ -12721,6 +12725,14 @@ ALTER TABLE ONLY public.subsidiary_mappings ADD CONSTRAINT subsidiary_mappings_workspace_id_d2d83a94_uniq UNIQUE (workspace_id); +-- +-- Name: task_logs task_logs_expense_group_id_f19c75f9_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.task_logs + ADD CONSTRAINT task_logs_expense_group_id_f19c75f9_uniq UNIQUE (expense_group_id); + + -- -- Name: task_logs tasks_tasklog_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- @@ -13210,13 +13222,6 @@ CREATE INDEX reimbursements_workspace_id_084805e4 ON public.reimbursements USING CREATE INDEX task_log_bill_id_30283abe ON public.task_logs USING btree (bill_id); --- --- Name: task_log_expense_group_id_241da11b; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX task_log_expense_group_id_241da11b ON public.task_logs USING btree (expense_group_id); - - -- -- Name: task_log_expense_report_id_74a8817f; Type: INDEX; Schema: public; Owner: postgres -- @@ -13726,14 +13731,6 @@ ALTER TABLE ONLY public.task_logs ADD CONSTRAINT task_log_bill_id_30283abe_fk_bills_id FOREIGN KEY (bill_id) REFERENCES public.bills(id) DEFERRABLE INITIALLY DEFERRED; --- --- Name: task_logs task_log_expense_group_id_241da11b_fk_expense_groups_id; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.task_logs - ADD CONSTRAINT task_log_expense_group_id_241da11b_fk_expense_groups_id FOREIGN KEY (expense_group_id) REFERENCES public.expense_groups(id) DEFERRABLE INITIALLY DEFERRED; - - -- -- Name: task_logs task_log_expense_report_id_74a8817f_fk_expense_reports_id; Type: FK CONSTRAINT; Schema: public; Owner: postgres -- @@ -13774,6 +13771,14 @@ ALTER TABLE ONLY public.task_logs ADD CONSTRAINT task_logs_credit_card_charge_i_078401a1_fk_credit_ca FOREIGN KEY (credit_card_charge_id) REFERENCES public.credit_card_charges(id) DEFERRABLE INITIALLY DEFERRED; +-- +-- Name: task_logs task_logs_expense_group_id_f19c75f9_fk_expense_groups_id; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.task_logs + ADD CONSTRAINT task_logs_expense_group_id_f19c75f9_fk_expense_groups_id FOREIGN KEY (expense_group_id) REFERENCES public.expense_groups(id) DEFERRABLE INITIALLY DEFERRED; + + -- -- Name: vendor_payment_lineitems vendor_payment_linei_expense_group_id_abfd0a4c_fk_expense_g; Type: FK CONSTRAINT; Schema: public; Owner: postgres -- diff --git a/tests/test_netsuite/conftest.py b/tests/test_netsuite/conftest.py index 1a7cd222..9c0f4dbc 100644 --- a/tests/test_netsuite/conftest.py +++ b/tests/test_netsuite/conftest.py @@ -62,7 +62,9 @@ def create_task_logs(db): @pytest.fixture def create_expense_report(db, add_netsuite_credentials, add_fyle_credentials): - + # Clear existing TaskLogs for this expense group + TaskLog.objects.filter(expense_group_id=1).delete() + TaskLog.objects.update_or_create( workspace_id=2, expense_group_id=1,