1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

fix extend susbcription w/ payment schedule

This commit is contained in:
Sylvain 2021-02-10 13:32:13 +01:00
parent 44030793ee
commit ecb23c02b9
3 changed files with 8 additions and 1 deletions

View File

@ -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

View File

@ -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,

View File

@ -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.