Skip to content

Commit

Permalink
paid_on_fyle field added to expense table (#627)
Browse files Browse the repository at this point in the history
* paid_on_fyle field added to expense table

* script to mark paid on fyle
  • Loading branch information
Ashutosh619-sudo authored Jun 19, 2024
1 parent fe98b74 commit c30ae5e
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 63 deletions.
18 changes: 18 additions & 0 deletions apps/fyle/migrations/0036_expense_paid_on_fyle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.14 on 2024-06-18 15:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('fyle', '0035_alter_expensefilter_custom_field_type'),
]

operations = [
migrations.AddField(
model_name='expense',
name='paid_on_fyle',
field=models.BooleanField(default=False, help_text='Expense Payment status on Fyle'),
),
]
1 change: 1 addition & 0 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Expense(models.Model):
previous_export_state = models.CharField(max_length=255, help_text='Previous export state', null=True)
accounting_export_summary = JSONField(default=dict)
paid_on_qbo = models.BooleanField(help_text='Expense Payment status on QBO', default=False)
paid_on_fyle = models.BooleanField(help_text='Expense Payment status on Fyle', default=False)
payment_number = models.CharField(max_length=55, help_text='Expense payment number', null=True)
is_skipped = models.BooleanField(null=True, default=False, help_text='Expense is skipped or not')
workspace = models.ForeignKey(
Expand Down
7 changes: 7 additions & 0 deletions apps/quickbooks_online/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ def process_reimbursements(workspace_id):
reimbursements = Reimbursement.objects.filter(state='PENDING', workspace_id=workspace_id).all()
reimbursement_ids = []

expenses_paid_on_fyle = []

if reimbursements:
for reimbursement in reimbursements:
expenses = Expense.objects.filter(settlement_id=reimbursement.settlement_id, fund_source='PERSONAL').all()
Expand All @@ -688,6 +690,7 @@ def process_reimbursements(workspace_id):

if all_expense_paid:
reimbursement_ids.append(reimbursement.reimbursement_id)
expenses_paid_on_fyle.extend(expenses)

if reimbursement_ids:
reimbursements_list = []
Expand All @@ -698,6 +701,10 @@ def process_reimbursements(workspace_id):
platform.reimbursements.bulk_post_reimbursements(reimbursements_list)
platform.reimbursements.sync()

for expense in expenses_paid_on_fyle:
expense.paid_on_fyle = True
expense.save()


def async_sync_accounts(workspace_id):
try:
Expand Down
9 changes: 9 additions & 0 deletions sql/scripts/025-mark-paid-on-fyle.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rollback;
begin;

update expenses e
set paid_on_fyle = 't'
from reimbursements r
where e.settlement_id = r.settlement_id
and e.paid_on_qbo = 't'
and r.state = 'COMPLETE';
Loading

0 comments on commit c30ae5e

Please sign in to comment.