Skip to content

Commit

Permalink
feat(netsuite): add issuing date to NetSuite trandate payload (#2899)
Browse files Browse the repository at this point in the history
## Roadmap Task

👉  https://getlago.canny.io/feature-requests/p/{{FEATURE_SLUG}}

## Context

Include relevant motivation and context.

## Description

Describe your changes in detail.

List any dependencies that are required.

---------

Co-authored-by: Raffi Sarkissian <raffisarkissian@Raffis-MacBook-Pro.local>
Co-authored-by: Ivan Novosad <ivan@getlago.com>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent d1d1527 commit 59aa574
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
26 changes: 20 additions & 6 deletions app/services/integrations/aggregator/invoices/payloads/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,29 @@ def body
def columns
result = {
'tranid' => invoice.number,
'entity' => integration_customer.external_customer_id,
'taxregoverride' => true,
'taxdetailsoverride' => true,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_url,
'custbody_lago_id' => invoice.id,
'duedate' => due_date
'custbody_lago_invoice_link' => invoice_url
}

unless tax_item_complete?
result['trandate'] = issuing_date
end

result = result.merge(
{
'duedate' => due_date,
'taxdetailsoverride' => true,
'custbody_lago_id' => invoice.id,
'entity' => integration_customer.external_customer_id
}
)

if tax_item&.tax_nexus.present?
result['nexus'] = tax_item.tax_nexus
end

result['taxregoverride'] = true

result
end

Expand Down Expand Up @@ -81,6 +91,10 @@ def due_date
invoice.payment_due_date&.strftime("%-m/%-d/%Y")
end

def issuing_date
invoice.issuing_date&.strftime("%-m/%-d/%Y")
end

def item(fee)
mapped_item = if fee.charge?
billable_metric_item(fee)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
end

let(:due_date) { invoice.payment_due_date.strftime("%-m/%-d/%Y") }
let(:issuing_date) { invoice.issuing_date.strftime("%-m/%-d/%Y") }

let(:params) do
{
Expand All @@ -148,6 +149,7 @@
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_url,
'trandate' => anything,
'duedate' => due_date
},
'lines' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
end

let(:due_date) { invoice.payment_due_date.strftime("%-m/%-d/%Y") }
let(:issuing_date) { invoice.issuing_date.strftime("%-m/%-d/%Y") }

let(:body) do
{
Expand Down Expand Up @@ -227,6 +228,31 @@
}
end

let(:column_keys_with_taxes) do
[
'tranid',
'custbody_ava_disable_tax_calculation',
'custbody_lago_invoice_link',
'duedate',
'taxdetailsoverride',
'custbody_lago_id',
'entity',
'taxregoverride'
]
end

let(:column_keys_with_taxes_with_nexus) do
column_keys_with_taxes.insert(7, 'nexus')
end

let(:column_keys_without_taxes) do
column_keys_with_taxes.insert(3, 'trandate')
end

let(:column_keys_without_taxes_with_nexus) do
column_keys_without_taxes.insert(8, 'nexus')
end

before do
integration_customer
charge
Expand Down Expand Up @@ -258,13 +284,18 @@
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_link,
'trandate' => issuing_date,
'duedate' => due_date
}
end

it 'returns payload body with tax columns' do
expect(subject).to eq(body)
end

it 'has the columns keys in order' do
expect(subject['columns'].keys).to eq(column_keys_without_taxes)
end
end

context 'when tax nexus is present' do
Expand Down Expand Up @@ -353,6 +384,10 @@
it 'returns payload body with tax columns' do
expect(subject).to eq(body)
end

it 'has the columns keys in order' do
expect(subject['columns'].keys).to eq(column_keys_with_taxes_with_nexus)
end
end

context 'when tax item is not mapped completely' do
Expand All @@ -367,6 +402,7 @@
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_link,
'trandate' => issuing_date,
'duedate' => due_date,
'nexus' => 'some_nexus'
}
Expand All @@ -375,6 +411,10 @@
it 'returns payload body with tax columns' do
expect(subject).to eq(body)
end

it 'has the columns keys in order' do
expect(subject['columns'].keys).to eq(column_keys_without_taxes_with_nexus)
end
end
end
end
Expand All @@ -389,13 +429,18 @@
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_link,
'trandate' => issuing_date,
'duedate' => due_date
}
end

it 'returns payload body without tax columns' do
it 'returns payload body with tax columns' do
expect(subject).to eq(body)
end

it 'has the columns keys in order' do
expect(subject['columns'].keys).to eq(column_keys_without_taxes)
end
end
end

Expand Down

0 comments on commit 59aa574

Please sign in to comment.