From a46e3ae783bd1600e1317109f5922ce4964bbfae Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 18 Jan 2022 17:12:19 +0100 Subject: [PATCH] (bug) prepaid-packs without expiration date do not work --- CHANGELOG.md | 1 + app/models/prepaid_pack.rb | 4 +++- app/models/statistic_profile_prepaid_pack.rb | 2 ++ app/services/prepaid_pack_service.rb | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd4169879..2760ceb51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fix a bug: when requesting to send the sso migration code, the email was case-sensitive - Fix a bug: the adminsys email was case-sensitive - Fix a bug: members are unable to buy prepaid-packs by wallet +- Fix a bug: prepaid-packs without expiration date do not work - [TODO DEPLOY] `rails fablab:maintenance:regenerate_statistics[2020,04]` # v5.3.1 2022 January 17 diff --git a/app/models/prepaid_pack.rb b/app/models/prepaid_pack.rb index aff5dc6c7..76f08aaa8 100644 --- a/app/models/prepaid_pack.rb +++ b/app/models/prepaid_pack.rb @@ -18,7 +18,9 @@ class PrepaidPack < ApplicationRecord validates :amount, :group_id, :priceable_id, :priceable_type, :minutes, presence: true def validity - validity_count.send(validity_interval) + return nil if validity_interval.nil? + + validity_count&.send(validity_interval) end def destroyable? diff --git a/app/models/statistic_profile_prepaid_pack.rb b/app/models/statistic_profile_prepaid_pack.rb index 913d9ccaf..eeee775bb 100644 --- a/app/models/statistic_profile_prepaid_pack.rb +++ b/app/models/statistic_profile_prepaid_pack.rb @@ -14,6 +14,8 @@ class StatisticProfilePrepaidPack < ApplicationRecord private def set_expiration_date + return unless prepaid_pack.validity + self.expires_at = DateTime.current + prepaid_pack.validity end end diff --git a/app/services/prepaid_pack_service.rb b/app/services/prepaid_pack_service.rb index 49ef7772c..c1896f85e 100644 --- a/app/services/prepaid_pack_service.rb +++ b/app/services/prepaid_pack_service.rb @@ -24,7 +24,7 @@ class PrepaidPackService .includes(:prepaid_pack) .references(:prepaid_packs) .where('statistic_profile_id = ?', user.statistic_profile.id) - .where('expires_at > ?', DateTime.current) + .where('expires_at > ? OR expires_at IS NULL', DateTime.current) .where('prepaid_packs.priceable_id = ?', priceable.id) .where('prepaid_packs.priceable_type = ?', priceable.class.name) .where('minutes_used < prepaid_packs.minutes')