lib/polish_invoicer/validator.rb in polish_invoicer-0.0.23 vs lib/polish_invoicer/validator.rb in polish_invoicer-0.0.24
- old
+ new
@@ -13,10 +13,11 @@
check_not_nil
check_dates
check_arrays
check_booleans
check_price
+ check_price_paid
check_vat
check_proforma
check_create_and_payment_date
check_currency
@errors.empty?
@@ -77,9 +78,19 @@
def check_price
if @invoice.price.is_a?(Numeric)
@errors[:price] = 'Cena musi być liczbą dodatnią' unless @invoice.price > 0
else
@errors[:price] = 'Cena musi być liczbą'
+ end
+ end
+
+ def check_price_paid
+ return if @invoice.price.nil?
+ if @invoice.price_paid.is_a?(Numeric)
+ @errors[:price_paid] = 'Kwota zapłacona musi być liczbą dodatnią' unless @invoice.price_paid >= 0
+ @errors[:price_paid] = 'Kwota zapłacona musi być mniejsza lub równa cenie' unless @invoice.price_paid <= @invoice.price
+ else
+ @errors[:price_paid] = 'Kwota zapłacona musi być liczbą'
end
end
def check_vat
if Vat.valid?(@invoice.vat)