From f59e998cd472683d2051de6415d59462a83f1a70 Mon Sep 17 00:00:00 2001 From: Felix Wolfsteller Date: Fri, 3 Mar 2023 22:11:00 +0100 Subject: [PATCH] raise sanity exception with more info --- lib/shoplex.rb | 2 +- lib/shoplex/sanity_check.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/shoplex.rb b/lib/shoplex.rb index b72f1de..8e2e006 100644 --- a/lib/shoplex.rb +++ b/lib/shoplex.rb @@ -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]) diff --git a/lib/shoplex/sanity_check.rb b/lib/shoplex/sanity_check.rb index 2508886..d31afa9 100644 --- a/lib/shoplex/sanity_check.rb +++ b/lib/shoplex/sanity_check.rb @@ -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