File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -121,12 +121,12 @@ def valid?
121121 @errors = [ ]
122122 tax = BigDecimal ( tax_amount )
123123 basis = BigDecimal ( basis_amount )
124- summed_tax_amount = taxes . sum ( &:tax_amount )
124+ summed_tax_amount = taxes . sum ( &:tax_amount ) . round ( 2 )
125125 if tax != summed_tax_amount
126126 @errors << "Tax amount and summed tax amounts deviate: #{ tax_amount } / #{ summed_tax_amount } "
127127 return false
128128 end
129- summed_tax_base_amount = taxes . sum ( &:base_amount )
129+ summed_tax_base_amount = taxes . sum ( &:base_amount ) . round ( 2 )
130130 if basis != summed_tax_base_amount
131131 @errors << "Base amount and summed tax base amount deviate: #{ basis } / #{ summed_tax_base_amount } "
132132 return false
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ def valid?
7474 gross_price = BigDecimal ( gross_amount )
7575 charge_price = BigDecimal ( charge_amount )
7676 tax = BigDecimal ( tax_amount )
77- unit_price = net_price * BigDecimal ( billed_quantity . abs )
77+ unit_price = ( net_price * BigDecimal ( billed_quantity . abs ) ) . round ( 2 )
7878
7979 if charge_price != unit_price
8080 @errors << "charge price and gross price times quantity deviate: #{ charge_price } / #{ unit_price } "
Original file line number Diff line number Diff line change @@ -791,5 +791,29 @@ def test_invoice_object_extensions
791791 assert_match ( /<ram:PaymentReference>#{ invoice . payment_reference } <\/ ram:PaymentReference>/ , xml )
792792 assert_match ( %r{<ram:DefinedTradeContact>\s *<ram:PersonName>Max Mustermann</ram:PersonName>\s *</ram:DefinedTradeContact>} , xml )
793793 end
794+
795+ def test_invoice_with_quantity_causing_sub_cent_amounts
796+ errors = [ ]
797+
798+ invoice = make_de_invoice
799+ invoice . tax_calculation_method = :ITEM_BASED
800+ invoice . line_items . first . net_amount = BigDecimal ( '10.12' )
801+ invoice . line_items . first . gross_amount = BigDecimal ( '10.12' )
802+ invoice . line_items . first . discount_amount = BigDecimal ( '0' )
803+ invoice . line_items . first . billed_quantity = BigDecimal ( '0.1' )
804+ invoice . line_items . first . charge_amount = BigDecimal ( '1.01' )
805+ invoice . line_items . first . tax_amount = BigDecimal ( '0.19' )
806+ invoice . basis_amount = BigDecimal ( '1.01' ) # 1.012 rounded
807+ invoice . tax_amount = BigDecimal ( '0.19' )
808+ invoice . grand_total_amount = BigDecimal ( '1.2' )
809+
810+ begin
811+ invoice . to_xml ( version : 2 )
812+ rescue ValidationError => e
813+ errors = e . errors
814+ pp e . errors
815+ end
816+ assert_equal [ ] , errors
817+ end
794818 end
795819end
You can’t perform that action at this time.
0 commit comments