From d9681eaf3031513204553c3b352c56f16e786488 Mon Sep 17 00:00:00 2001 From: benni Date: Tue, 11 Dec 2012 10:59:50 +0100 Subject: [PATCH] Added validation for article_price. Avoid unit_quantity of 0. --- app/models/article_price.rb | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/app/models/article_price.rb b/app/models/article_price.rb index 1769c632..e946fc92 100644 --- a/app/models/article_price.rb +++ b/app/models/article_price.rb @@ -4,21 +4,10 @@ class ArticlePrice < ActiveRecord::Base has_many :order_articles validates_presence_of :price, :tax, :deposit, :unit_quantity - - # Custom attribute setter that accepts decimal numbers using localized decimal separator. - def price=(price) - self[:price] = String.delocalized_decimal(price) - end + validates_numericality_of :price, :unit_quantity, :greater_than => 0 + validates_numericality_of :deposit, :tax - # Custom attribute setter that accepts decimal numbers using localized decimal separator. - def tax=(tax) - self[:tax] = String.delocalized_decimal(tax) - end - - # Custom attribute setter that accepts decimal numbers using localized decimal separator. - def deposit=(deposit) - self[:deposit] = String.delocalized_decimal(deposit) - end + localize_input_of :price, :tax, :deposit # The financial gross, net plus tax and deposit. def gross_price