Skip to content
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
4 changes: 2 additions & 2 deletions lib/secretariat/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ def valid?
@errors = []
tax = BigDecimal(tax_amount)
basis = BigDecimal(basis_amount)
summed_tax_amount = taxes.sum(&:tax_amount)
summed_tax_amount = taxes.sum(&:tax_amount).round(2)
if tax != summed_tax_amount
@errors << "Tax amount and summed tax amounts deviate: #{tax_amount} / #{summed_tax_amount}"
return false
end
summed_tax_base_amount = taxes.sum(&:base_amount)
summed_tax_base_amount = taxes.sum(&:base_amount).round(2)
if basis != summed_tax_base_amount
@errors << "Base amount and summed tax base amount deviate: #{basis} / #{summed_tax_base_amount}"
return false
Expand Down
2 changes: 1 addition & 1 deletion lib/secretariat/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def valid?
gross_price = BigDecimal(gross_amount)
charge_price = BigDecimal(charge_amount)
tax = BigDecimal(tax_amount)
unit_price = net_price * BigDecimal(billed_quantity.abs)
unit_price = (net_price * BigDecimal(billed_quantity.abs)).round(2)

if charge_price != unit_price
@errors << "charge price and gross price times quantity deviate: #{charge_price} / #{unit_price}"
Expand Down
24 changes: 24 additions & 0 deletions test/invoice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -791,5 +791,29 @@ def test_invoice_object_extensions
assert_match(/<ram:PaymentReference>#{invoice.payment_reference}<\/ram:PaymentReference>/, xml)
assert_match(%r{<ram:DefinedTradeContact>\s*<ram:PersonName>Max Mustermann</ram:PersonName>\s*</ram:DefinedTradeContact>}, xml)
end

def test_invoice_with_quantity_causing_sub_cent_amounts
errors = []

invoice = make_de_invoice
invoice.tax_calculation_method = :ITEM_BASED
invoice.line_items.first.net_amount = BigDecimal('10.12')
invoice.line_items.first.gross_amount = BigDecimal('10.12')
invoice.line_items.first.discount_amount = BigDecimal('0')
invoice.line_items.first.billed_quantity = BigDecimal('0.1')
invoice.line_items.first.charge_amount = BigDecimal('1.01')
invoice.line_items.first.tax_amount = BigDecimal('0.19')
invoice.basis_amount = BigDecimal('1.01') # 1.012 rounded
invoice.tax_amount = BigDecimal('0.19')
invoice.grand_total_amount = BigDecimal('1.2')

begin
invoice.to_xml(version: 2)
rescue ValidationError => e
errors = e.errors
pp e.errors
end
assert_equal [], errors
end
end
end