Skip to content

Commit 4692781

Browse files
authored
Merge pull request #25 from SubandiK/add-tax_calculation_method-ITEM_BASED
add tax_calculation_method :ITEM_BASED which changes tax amount validation to item based
2 parents 2bfe84f + d547895 commit 4692781

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/secretariat/invoice.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ def valid?
113113
@errors << "Base amount and summed tax base amount deviate: #{basis} / #{summed_tax_base_amount}"
114114
return false
115115
end
116-
if tax_calculation_method != :NONE
116+
if tax_calculation_method == :ITEM_BASED
117+
line_items_tax_amount = line_items.sum(&:tax_amount)
118+
if tax_amount != line_items_tax_amount
119+
@errors << "Tax amount #{tax_amount} and summed up item tax amounts #{line_items_tax_amount} deviate"
120+
end
121+
elsif tax_calculation_method != :NONE
117122
taxes.each do |tax|
118123
calc_tax = tax.base_amount * BigDecimal(tax.tax_percent) / BigDecimal(100)
119124
calc_tax = calc_tax.round(2)

0 commit comments

Comments
 (0)