From 0ea07de2d1cb11636828feb97abb70caa8d911fc Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 28 Jul 2015 13:08:02 +0300 Subject: [PATCH] Fix valid_to #2741 --- app/models/pricelist.rb | 2 +- app/views/admin/pricelists/edit.haml | 8 ++++++++ app/views/admin/pricelists/index.haml | 2 +- config/locales/en.yml | 2 ++ spec/models/pricelist_spec.rb | 11 +++++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/models/pricelist.rb b/app/models/pricelist.rb index bb37ad0e1..1287be9d1 100644 --- a/app/models/pricelist.rb +++ b/app/models/pricelist.rb @@ -1,7 +1,7 @@ class Pricelist < ActiveRecord::Base include Versions # version/pricelist_version.rb - scope :valid, -> { where("valid_from <= ? AND valid_to >= ? OR valid_to IS NULL", Time.zone.now, Time.zone.now) } + scope :valid, -> { where("valid_from <= ? AND valid_to >= ? OR valid_to IS NULL", Time.zone.now.end_of_day, Time.zone.now.beginning_of_day) } monetize :price_cents diff --git a/app/views/admin/pricelists/edit.haml b/app/views/admin/pricelists/edit.haml index 329f7979b..4330b6240 100644 --- a/app/views/admin/pricelists/edit.haml +++ b/app/views/admin/pricelists/edit.haml @@ -2,5 +2,13 @@ .col-sm-6 %h2.text-center-xs= "#{t(:edit)}: #{@pricelist.name}" +- if @pricelist.persisted? && @pricelist.errors.none? + %hr + - active_pricelist = Pricelist.pricelist_for(@pricelist.category, @pricelist.operation_category, @pricelist.duration) + - if active_pricelist + = t('active_price_for_this_operation_is', price: "#{active_pricelist.price.amount.to_s} #{active_pricelist.price_currency}") + - else + = t('active_price_missing_for_this_operation') + %hr = render 'form' diff --git a/app/views/admin/pricelists/index.haml b/app/views/admin/pricelists/index.haml index 15a6b9c6b..6cf83f6b8 100644 --- a/app/views/admin/pricelists/index.haml +++ b/app/views/admin/pricelists/index.haml @@ -26,7 +26,7 @@ = sort_link(@q, 'valid_to', t(:valid_to)) %th{class: 'col-xs-2'} = t(:action) - + %tbody - @pricelists.each do |pricelist| %tr diff --git a/config/locales/en.yml b/config/locales/en.yml index c4b70c2e9..636b942e2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -877,3 +877,5 @@ en: api_user_not_found: 'API user not found' domain_already_belongs_to_the_querying_registrar: 'Domain already belongs to the querying registrar' notes: Notes + active_price_for_this_operation_is: 'Active price for this operation is %{price}' + active_price_missing_for_this_operation: 'Active price missing for this operation!' diff --git a/spec/models/pricelist_spec.rb b/spec/models/pricelist_spec.rb index f2c155846..4b680312a 100644 --- a/spec/models/pricelist_spec.rb +++ b/spec/models/pricelist_spec.rb @@ -160,6 +160,17 @@ describe Pricelist do Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.10 + Fabricate.create(:pricelist, { + category: 'ee', + operation_category: 'create', + duration: '1year', + price: 2.10, + valid_from: Time.zone.now.to_date, + valid_to: Time.zone.now.to_date + }) + + Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 2.10 + Fabricate.create(:pricelist, { category: 'ee', operation_category: 'create',