diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a9c2d4b..5115e3b45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Removed dependency to auto-ngtemplate-loader - Removed support for Universal Analytics - Updated deprecated division operators in sass +- Fix a bug: prepaid-packs purchases are reported as subscriptions in the statistics - Fix a bug: error Couldn't find the binary git during assets compilation - Fix a bug: a sentence was not linked to a translation key - Fix a bug: the version check may be scheduled at an invalid time @@ -30,6 +31,7 @@ - Fix a security issue: updated puma to 4.3.11 to fix [CVE-2022-23634](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-23634) - Fix a security issue: updated i18next-http-backend to 1.3.2 to fix [CVE-2022-0235](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-0235) - Fix a security issue: updated follow-redirects to 1.18.8 to fix [CVE-2022-0536](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-0536) +- [TODO DEPLOY] `rails fablab:maintenance:regenerate_statistics[2021,07]` - [TODO DEPLOY] `\curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/scripts/cve-2021-44228.sh | bash` - [TODO DEPLOY] migrate your Google Analytics property to GA4, see [this guide](https://support.google.com/analytics/answer/9744165) - [TODO DEPLOY] update your tracking ID in Customization > Privacy > Statistics > Google Analytics diff --git a/app/models/invoice_item.rb b/app/models/invoice_item.rb index 9d8cfe867..c9738ec8a 100644 --- a/app/models/invoice_item.rb +++ b/app/models/invoice_item.rb @@ -8,11 +8,6 @@ class InvoiceItem < Footprintable has_one :payment_gateway_object, as: :item belongs_to :object, polymorphic: true - belongs_to :reservation, foreign_type: 'Reservation', foreign_key: 'object_id' - belongs_to :subscription, foreign_type: 'Subscription', foreign_key: 'object_id' - belongs_to :wallet_transaction, foreign_type: 'WalletTransaction', foreign_key: 'object_id' - belongs_to :offer_day, foreign_type: 'OfferDay', foreign_key: 'object_id' - belongs_to :statistic_profile_prepaid_pack, foreign_type: 'StatisticProfilePrepaidPack', foreign_key: 'object_id' after_create :chain_record after_update :log_changes diff --git a/app/pdfs/pdf/invoice.rb b/app/pdfs/pdf/invoice.rb index 8036951b8..d0efe9aa8 100644 --- a/app/pdfs/pdf/invoice.rb +++ b/app/pdfs/pdf/invoice.rb @@ -97,9 +97,9 @@ class PDF::Invoice < Prawn::Document DATE: I18n.l(invoice.main_item.object.slots[0].start_at.to_date), TIME: I18n.l(invoice.main_item.object.slots[0].start_at, format: :hour_minute)) invoice.invoice_items.each do |item| - next unless item.subscription + next unless item.object_type == Subscription.name - subscription = item.subscription + subscription = item.object cancellation = invoice.is_a?(Avoir) ? I18n.t('invoices.cancellation') + ' - ' : '' object = "\n- #{object}\n- #{cancellation + subscription_verbose(subscription, name)}" break @@ -135,7 +135,7 @@ class PDF::Invoice < Prawn::Document details = invoice.is_a?(Avoir) ? I18n.t('invoices.cancellation') + ' - ' : '' if item.object_type == Subscription.name - subscription = item.subscription + subscription = item.object if invoice.main_item.object_type == 'OfferDay' details += I18n.t('invoices.subscription_extended_for_free_from_START_to_END', START: I18n.l(invoice.main_item.object.start_at.to_date), diff --git a/app/services/statistic_service.rb b/app/services/statistic_service.rb index 3ccfb1097..37965049d 100644 --- a/app/services/statistic_service.rb +++ b/app/services/statistic_service.rb @@ -129,10 +129,13 @@ class StatisticService InvoiceItem.where('invoice_items.created_at >= :start_date AND invoice_items.created_at <= :end_date', options) .eager_load(invoice: [:coupon], subscription: [:plan, statistic_profile: [:group]]).each do |i| next if i.invoice.is_a?(Avoir) + next unless i.invoice_item_type == Subscription.name - sub = i.subscription - - next unless sub + sub = if i.object_type == Subscription.name + i.object + else + i.object.subscription + end ca = i.amount.to_i cs = CouponService.new diff --git a/test/integration/reservations/create_as_admin_test.rb b/test/integration/reservations/create_as_admin_test.rb index 0af1e4a68..a4421dfcd 100644 --- a/test/integration/reservations/create_as_admin_test.rb +++ b/test/integration/reservations/create_as_admin_test.rb @@ -499,7 +499,7 @@ class Reservations::CreateAsAdminTest < ActionDispatch::IntegrationTest # invoice_items invoice_items = InvoiceItem.last(2) - assert(invoice_items.any? { |ii| ii.amount == plan.amount && !ii.subscription.nil? }) + assert(invoice_items.any? { |ii| ii.amount == plan.amount && ii.object_type == Subscription.name }) assert(invoice_items.any? { |ii| ii.amount.zero? }) # invoice assertions diff --git a/test/integration/reservations/create_test.rb b/test/integration/reservations/create_test.rb index 415b9799b..6aea7ab1f 100644 --- a/test/integration/reservations/create_test.rb +++ b/test/integration/reservations/create_test.rb @@ -622,7 +622,7 @@ class Reservations::CreateTest < ActionDispatch::IntegrationTest assert_not_nil subscription_item - subscription = subscription_item.subscription + subscription = subscription_item.object assert_equal subscription_item.amount, plan.amount assert_equal subscription.plan_id, plan.id