Skip to content

Commit

Permalink
raise sanity exception with more info
Browse files Browse the repository at this point in the history
  • Loading branch information
fwolfst committed Mar 3, 2023
1 parent 45048d7 commit f59e998
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/shoplex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.process file_content
bookings = result.invoices.map do |invoice|
begin
Shoplex::ShippingSplitter::apply!(invoice:)
#Shoplex::SanityCheck::check!(invoice:)
Shoplex::SanityCheck::check!(invoice:)
Shoplex::InvoiceBookingConverter.convert(invoice:)
rescue => e
result.mark_error(maker: self, error: :unknown, obj: [e, invoice])
Expand Down
9 changes: 7 additions & 2 deletions lib/shoplex/sanity_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ module Shoplex
class SanityCheck
class GrossDoesNotMatchNet < StandardError ; end
def self.check!(invoice:)
if invoice.invoice_amount != invoice.invoice_amount_net + invoice.tax07_amount + invoice.tax19_amount
raise GrossDoesNotMatchNet
net_tax_sum = (invoice.invoice_amount_net + invoice.tax07_amount + invoice.tax19_amount).round(2)
if invoice.invoice_amount != net_tax_sum
raise GrossDoesNotMatchNet.new(
"Gross amount #{invoice.invoice_amount} does not equal net + tax sums "\
"(#{invoice.invoice_amount_net} "\
"+ #{invoice.tax07_amount} "\
"+ #{invoice.tax19_amount} == #{net_tax_sum})")
end
end
end
Expand Down

0 comments on commit f59e998

Please sign in to comment.