Skip to content

Commit

Permalink
feat(netsuite): Send tax and date columns in correct order and when n…
Browse files Browse the repository at this point in the history
…eeded
  • Loading branch information
ivannovosad committed Dec 13, 2024
1 parent 7dd8255 commit ec73b11
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
23 changes: 16 additions & 7 deletions app/services/integrations/aggregator/invoices/payloads/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +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,
'trandate' => issuing_date
'custbody_lago_invoice_link' => invoice_url
}

if 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
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_url,
'duedate' => due_date,
'trandate' => issuing_date
'duedate' => due_date
},
'lines' => [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,27 @@
}
end

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

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

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

before do
integration_customer
charge
Expand Down Expand Up @@ -259,14 +280,17 @@
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_link,
'duedate' => due_date,
'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 @@ -356,6 +380,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)
end
end

context 'when tax item is not mapped completely' do
Expand All @@ -371,14 +399,17 @@
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_link,
'duedate' => due_date,
'trandate' => issuing_date,
'nexus' => 'some_nexus'
}
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_with_nexus)
end
end
end
end
Expand All @@ -393,14 +424,17 @@
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_link,
'duedate' => due_date,
'trandate' => issuing_date
'duedate' => due_date
}
end

it 'returns payload body without 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 ec73b11

Please sign in to comment.