Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(netsuite): Do not send taxes columns if tax not mapped #2369

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/services/integrations/aggregator/base_payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def account_item
end

def tax_item
@tax_item ||= collection_mapping(:tax) || fallback_item
@tax_item ||= collection_mapping(:tax)
end

def commitment_item
Expand Down
33 changes: 21 additions & 12 deletions app/services/integrations/aggregator/invoices/payloads/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@ def body
{
'type' => type,
'isDynamic' => true,
'columns' => {
'tranid' => invoice.id,
'entity' => integration_customer.external_customer_id,
'istaxable' => true,
'taxitem' => tax_item&.external_id,
'taxamountoverride' => amount(invoice.taxes_amount_cents, resource: invoice),
'otherrefnum' => invoice.number,
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_url,
'duedate' => due_date
},
'columns' => columns,
'lines' => [
{
'sublistId' => 'item',
Expand All @@ -39,6 +28,26 @@ def body

private

def columns
result = {
'tranid' => invoice.id,
'entity' => integration_customer.external_customer_id,
'istaxable' => true,
'otherrefnum' => invoice.number,
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_url,
'duedate' => due_date
}

if tax_item
result['taxitem'] = tax_item.external_id
result['taxamountoverride'] = amount(invoice.taxes_amount_cents, resource: invoice)
end

result
end

def invoice_url
url = ENV["LAGO_FRONT_URL"].presence || "https://app.getlago.com"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,7 @@
{
'type' => 'invoice',
'isDynamic' => true,
'columns' => {
'tranid' => invoice.id,
'entity' => integration_customer.external_customer_id,
'istaxable' => true,
'taxitem' => integration_collection_mapping5.external_id,
'taxamountoverride' => 2.0,
'otherrefnum' => invoice.number,
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_link,
'duedate' => due_date
},
'columns' => columns,
'lines' => [
{
'sublistId' => 'item',
Expand Down Expand Up @@ -224,7 +213,6 @@
integration_collection_mapping2
integration_collection_mapping3
integration_collection_mapping4
integration_collection_mapping5
integration_collection_mapping6
integration_mapping_add_on
integration_mapping_bm
Expand All @@ -234,8 +222,48 @@
charge_fee2
end

it 'returns payload body' do
expect(subject).to eq(body)
context 'when tax item is mapped' do
let(:columns) do
{
'tranid' => invoice.id,
'entity' => integration_customer.external_customer_id,
'istaxable' => true,
'taxitem' => integration_collection_mapping5.external_id,
'taxamountoverride' => 2.0,
'otherrefnum' => invoice.number,
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_link,
'duedate' => due_date
}
end

before do
integration_collection_mapping5
end

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

context 'when tax item is not mapped' do
let(:columns) do
{
'tranid' => invoice.id,
'entity' => integration_customer.external_customer_id,
'istaxable' => true,
'otherrefnum' => invoice.number,
'custbody_lago_id' => invoice.id,
'custbody_ava_disable_tax_calculation' => true,
'custbody_lago_invoice_link' => invoice_link,
'duedate' => due_date
}
end

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