From 205c8352a1c5d3ec41159cc5b87b019b3ca8eedf Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Tue, 6 Oct 2015 12:03:22 +0200 Subject: [PATCH] update prices fails if list price is smaller than input price --- back-office/app/models/item.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/back-office/app/models/item.rb b/back-office/app/models/item.rb index 018bd08..0bb9ad1 100644 --- a/back-office/app/models/item.rb +++ b/back-office/app/models/item.rb @@ -15,6 +15,7 @@ class Item < ActiveRecord::Base validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id, :weight, :supplier_id + validate :we_must_earn_money def self.items_to_order items_raw = Item.find_by_sql(%Q{ @@ -124,5 +125,11 @@ class Item < ActiveRecord::Base puts nonexistent_codes.join("\n") end + def we_must_earn_money + if list_price.to_f <= current_input_price.to_f + errors[:list_price] << "#{code} Ulazna cijena veca od izlazne" + end + end + end