Refactor debit and credit registrar to include pricelist id #2741

This commit is contained in:
Martin Lensment 2015-07-13 17:39:54 +03:00
parent 9fd38f161a
commit 75a6c27221
11 changed files with 80 additions and 123 deletions

View file

@ -23,10 +23,10 @@ class Pricelist < ActiveRecord::Base
end
class << self
def price_for(zone, operation, period)
def pricelist_for(zone, operation, period)
lists = valid.where(category: zone, operation_category: operation, duration: period)
return lists.first.price if lists.count == 1
lists.where('valid_to IS NOT NULL').order(valid_from: :desc).first.price
return lists.first if lists.count == 1
lists.where('valid_to IS NOT NULL').order(valid_from: :desc).first
end
end
end