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