diff --git a/app/models/subscription.rb b/app/models/subscription.rb index ba09af984..91e8538dc 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -85,6 +85,12 @@ class Subscription < ApplicationRecord statistic_profile.user end + def original_payment_schedule + return payment_schedule if payment_schedule + + PaymentScheduleItem.where("cast(details->>'subscription_id' AS int) = ?", id).first&.payment_schedule + end + private def notify_member_subscribed_plan diff --git a/app/services/subscriptions/subscribe.rb b/app/services/subscriptions/subscribe.rb index 8e4bef2d9..3579fca5e 100644 --- a/app/services/subscriptions/subscribe.rb +++ b/app/services/subscriptions/subscribe.rb @@ -53,7 +53,7 @@ class Subscriptions::Subscribe expiration_date: new_expiration_date ) if new_sub.save - schedule = subscription.payment_schedule + schedule = subscription.original_payment_schedule details = Price.compute(true, new_sub.user, nil, [], plan_id: subscription.plan_id) payment = if schedule generate_schedule(subscription: new_sub, diff --git a/doc/postgresql_readme.md b/doc/postgresql_readme.md index 6ae5a2943..fac2870e1 100644 --- a/doc/postgresql_readme.md +++ b/doc/postgresql_readme.md @@ -80,3 +80,4 @@ This is currently not supported, because of some PostgreSQL specific instruction - `db/migrate/20200623141305_update_search_vector_of_projects.rb` defines a PL/pgSQL function (`fill_search_vector_for_project()`) and create an SQL trigger for this function; - `db/migrate/20200629123011_update_pg_trgm.rb` is using [ALTER EXTENSION](https://www.postgresql.org/docs/10/sql-alterextension.html); - `db/migrate/20201027101809_create_payment_schedule_items.rb` is using [jsonb](https://www.postgresql.org/docs/9.4/static/datatype-json.html); +- `app/models/subscription.rb@original_payment_schedule` is using `->>` and `cast(... AS int)` for querying a with jsonb column.