Skip to content

Commit

Permalink
fix(netsuite-integration): limit netsuite payload rate (#2242)
Browse files Browse the repository at this point in the history
## Description

Netsuite only support decimals of to 14 digits if there is decimal
point. This PR adapts this use-case
  • Loading branch information
lovrocolic authored and ancorcruz committed Jul 7, 2024
1 parent f51d18d commit 598ed38
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Aggregator
module Invoices
module Payloads
class Netsuite < BasePayload
MAX_DECIMALS = 15

def body
{
'type' => type,
Expand Down Expand Up @@ -52,7 +54,7 @@ def item(fee)
'item' => mapped_item.external_id,
'account' => mapped_item.external_account_code,
'quantity' => fee.units,
'rate' => fee.precise_unit_amount
'rate' => limited_rate(fee.precise_unit_amount)
}
end

Expand Down Expand Up @@ -88,6 +90,18 @@ def discounts

output
end

def limited_rate(precise_unit_amount)
unit_amount_str = precise_unit_amount.to_s

return precise_unit_amount if unit_amount_str.length <= MAX_DECIMALS

decimal_position = unit_amount_str.index('.')

return precise_unit_amount unless decimal_position

precise_unit_amount.round(MAX_DECIMALS - 1 - decimal_position)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
invoice:,
charge:,
units: 2,
precise_unit_amount: 4.12,
precise_unit_amount: 4.12121212123337777,
created_at: current_time
)
end
Expand Down Expand Up @@ -161,7 +161,7 @@
'item' => 'm2',
'account' => 'm22',
'quantity' => 2,
'rate' => 4.12
'rate' => 4.1212121212334
},
{
'item' => '2',
Expand Down

0 comments on commit 598ed38

Please sign in to comment.