Skip to content

Commit

Permalink
Add support for accounts payable (#198)
Browse files Browse the repository at this point in the history
* Add support for accounts payable

* move the export_settings
  • Loading branch information
Hrishabh17 committed Jun 25, 2024
1 parent 39ef4c1 commit cdef2d3
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.1.2 on 2024-06-25 05:00

from django.db import migrations
import sage_desktop_api.models.fields


class Migration(migrations.Migration):

dependencies = [
('accounting_exports', '0002_initial'),
]

operations = [
migrations.AlterField(
model_name='accountingexport',
name='type',
field=sage_desktop_api.models.fields.StringOptionsField(choices=[('PURCHASE_INVOICE', 'PURCHASE_INVOICE'), ('DIRECT_COST', 'DIRECT_COST'), ('FETCHING_REIMBURSABLE_EXPENSES', 'FETCHING_REIMBURSABLE_EXPENSES'), ('FETCHING_CREDIT_CARD_EXPENENSES', 'FETCHING_CREDIT_CARD_EXPENENSES')], default='', help_text='Task type', max_length=255, null=True),
),
]
27 changes: 24 additions & 3 deletions apps/sage300/exports/purchase_invoice/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from apps.sage300.exports.base_model import BaseExportModel
from apps.accounting_exports.models import AccountingExport
from apps.workspaces.models import AdvancedSetting
from apps.workspaces.models import AdvancedSetting, ExportSetting
from apps.fyle.models import Expense, DependentFieldSetting


Expand Down Expand Up @@ -65,7 +65,8 @@ class PurchaseInvoiceLineitems(BaseExportModel):
Purchase Invoice Lineitem Model
"""

accounts_payable_account_id = StringNullField(help_text='destination id of accounts payable account')
accounts_payable_id = StringNullField(help_text='destination id of accounts payable account')
expense_account_id = StringNullField(help_text='destination id of accounts expense account')
purchase_invoice = models.ForeignKey(PurchaseInvoice, on_delete=models.PROTECT, help_text='Reference to PurchaseInvoice')
expense = models.OneToOneField(Expense, on_delete=models.PROTECT, help_text='Reference to Expense')
amount = FloatNullField(help_text='Amount of the invoice')
Expand Down Expand Up @@ -94,6 +95,7 @@ def create_or_update_object(self, accounting_export: AccountingExport, advance_s
expenses = accounting_export.expenses.all()
purchase_invoice = PurchaseInvoice.objects.get(accounting_export=accounting_export)
dependent_field_setting = DependentFieldSetting.objects.filter(workspace_id=accounting_export.workspace_id).first()
export_setting = ExportSetting.objects.filter(workspace_id=purchase_invoice.workspace.id).first()

cost_category_id = None
cost_code_id = None
Expand All @@ -111,6 +113,12 @@ def create_or_update_object(self, accounting_export: AccountingExport, advance_s
workspace_id=accounting_export.workspace_id
).first()

accounts_payable_id = self.get_account_payable_id(
export_setting = export_setting,
fund_source = lineitem.fund_source,
expense_account_id = account.destination_account.destination_id
)

job_id = self.get_job_id(accounting_export, lineitem)
standard_category_id = self.get_standard_category_id(accounting_export, lineitem)
standard_cost_code_id = self.get_standard_cost_code_id(accounting_export, lineitem)
Expand Down Expand Up @@ -144,7 +152,8 @@ def create_or_update_object(self, accounting_export: AccountingExport, advance_s
expense_id=lineitem.id,
defaults={
'amount': round(lineitem.amount, 2),
'accounts_payable_account_id': account.destination_account.destination_id,
'expense_account_id': account.destination_account.destination_id,
'accounts_payable_id': accounts_payable_id,
'job_id': job_id,
'commitment_id': commitment_id,
'commitment_item_id': commitment_item_id,
Expand All @@ -159,3 +168,15 @@ def create_or_update_object(self, accounting_export: AccountingExport, advance_s
purchase_invoice_lineitem_objects.append(purchase_invoice_lineitem_object)

return purchase_invoice_lineitem_objects

def get_account_payable_id(export_setting: ExportSetting, fund_source: str, expense_account_id: str = None):
"""
Get the account_payable_id
:param workspace_id: workspace_id
"""
if fund_source == 'CCC' and export_setting.default_ccc_account_payable_id:
return export_setting.default_ccc_account_payable_id
elif fund_source == 'PERSONAL' and export_setting.default_reimbursable_account_payable_id:
return export_setting.default_reimbursable_account_payable_id
else:
return expense_account_id
4 changes: 2 additions & 2 deletions apps/sage300/exports/purchase_invoice/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def __construct_purchase_invoice(self, body: PurchaseInvoice, lineitems: List[Pu
purchase_invoice_lineitem_payload = []
for lineitem in lineitems:
expense = {
"AccountsPayableAccountId": lineitem.accounts_payable_account_id,
"AccountsPayableAccountId": lineitem.accounts_payable_id,
"Amount": lineitem.amount,
"CategoryId": lineitem.category_id,
"CostCodeId": lineitem.cost_code_id,
"Description": lineitem.description[0:30],
"ExpenseAccountId": lineitem.accounts_payable_account_id,
"ExpenseAccountId": lineitem.expense_account_id,
"JobId": lineitem.job_id,
"StandardCategoryId": lineitem.standard_category_id,
"StandardCostCodeId": lineitem.standard_cost_code_id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.2 on 2024-06-25 05:00

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('sage300', '0003_costcategory_is_imported'),
]

operations = [
migrations.RenameField(
model_name='purchaseinvoicelineitems',
old_name='accounts_payable_account_id',
new_name='expense_account_id',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.1.2 on 2024-06-25 05:13

from django.db import migrations
import sage_desktop_api.models.fields


class Migration(migrations.Migration):

dependencies = [
('sage300', '0004_rename_accounts_payable_account_id_purchaseinvoicelineitems_expense_account_id'),
]

operations = [
migrations.AddField(
model_name='purchaseinvoicelineitems',
name='accounts_payable_id',
field=sage_desktop_api.models.fields.StringNullField(help_text='destination id of accounts payable account', max_length=255, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.1.2 on 2024-06-25 05:00

from django.db import migrations
import sage_desktop_api.models.fields


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0004_remove_advancedsetting_add_commitment_details_and_more'),
]

operations = [
migrations.AddField(
model_name='exportsetting',
name='default_ccc_account_payable_id',
field=sage_desktop_api.models.fields.StringNullField(help_text='CCC Credit Card Account Payable ID', max_length=255, null=True),
),
migrations.AddField(
model_name='exportsetting',
name='default_ccc_account_payable_name',
field=sage_desktop_api.models.fields.StringNullField(help_text='CCC Credit card account payable name', max_length=255, null=True),
),
migrations.AddField(
model_name='exportsetting',
name='default_reimbursable_account_payable_id',
field=sage_desktop_api.models.fields.StringNullField(help_text='Reimbursable account payable id', max_length=255, null=True),
),
migrations.AddField(
model_name='exportsetting',
name='default_reimbursable_account_payable_name',
field=sage_desktop_api.models.fields.StringNullField(help_text='Reimbursable account payable name', max_length=255, null=True),
),
]
4 changes: 4 additions & 0 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ class ExportSetting(BaseModel):
default_vendor_name = StringNullField(help_text='default Vendor Name')
default_vendor_id = StringNullField(help_text='default Vendor Id')
auto_map_employees = BooleanTrueField(help_text='Auto map employees')
default_reimbursable_account_payable_name = StringNullField(help_text='Reimbursable account payable name')
default_reimbursable_account_payable_id = StringNullField(help_text='Reimbursable account payable id')
default_ccc_account_payable_name = StringNullField(help_text='CCC Credit card account payable name')
default_ccc_account_payable_id = StringNullField(help_text='CCC Credit Card Account Payable ID')

class Meta:
db_table = 'export_settings'
Expand Down

0 comments on commit cdef2d3

Please sign in to comment.