1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-30 19:52:20 +01:00

[bug] crediting a wallet w/ refund invoice prevent statistics generation (#196)

This commit is contained in:
Sylvain 2020-04-01 12:51:18 +02:00
parent 8350390db4
commit 705bedc25c
4 changed files with 33 additions and 3 deletions

View File

@ -10,6 +10,7 @@
- Updated compass-rails & compass-core
- Renamed production documentation
- Syntax improvements in scss files
- Fix a bug: crediting a wallet w/ refund invoice prevent statistics generation (#196)
- Fix a bug: invalid translation keys in closing accounting period interface
- Fix a bug: since PostgreSQL release 9.6.17, the new installations will fail to start complaining for missing password (#194)
- Fix a bug: missing translations for some error messages
@ -19,6 +20,8 @@
- Fix a security issue: updated mkdirp to fix [CVE-2020-7598](https://nvd.nist.gov/vuln/detail/CVE-2020-7598)
- Fix a security issue: updated acorn to fix [CVE-2020-7598](https://nvd.nist.gov/vuln/detail/CVE-2020-7598)
- Fix a security issue: updated actionview to fix [CVE-2020-5267](https://nvd.nist.gov/vuln/detail/CVE-2020-5267)
- [TODO DEPLOY] `rails fablab:fix:avoirs_wallet_transaction`
- [TODO DEPLOY] `rails fablab:es:generate_stats[289]` only if you had missing statistics since some date ago. You can replace 289 by the difference of days between the day you run this task and the last day you had statistics
## v4.3.2 2020 March 11

View File

@ -273,10 +273,12 @@ class StatisticService
Avoir.where('invoices.created_at >= :start_date AND invoices.created_at <= :end_date', options)
.eager_load(:invoice_items, statistic_profile: [:group])
.each do |i|
# the following line is a workaround for issue #196
profile = i.statistic_profile || i.invoiced&.wallet&.user&.statistic_profile
avoirs_ca_list.push OpenStruct.new({
date: options[:start_date].to_date,
ca: calcul_avoir_ca(i)
}.merge(user_info(i.statistic_profile)))
}.merge(user_info(profile)))
end
reservations_ca_list.concat(subscriptions_ca_list).concat(avoirs_ca_list).each do |e|
profile = StatisticProfile.find(e.statistic_profile_id)
@ -365,6 +367,8 @@ class StatisticService
end
def user_info(statistic_profile)
return {} unless statistic_profile
{
statistic_profile_id: statistic_profile.id,
user_id: statistic_profile.user_id,

View File

@ -1,3 +1,6 @@
# frozen_string_literal: true
# Provides methods to manage wallets
class WalletService
def initialize(user: nil, wallet: nil)
@user = user
@ -8,7 +11,12 @@ class WalletService
def credit(amount)
ActiveRecord::Base.transaction do
if @wallet.credit(amount)
transaction = WalletTransaction.new(invoicing_profile: @user.invoicing_profile, wallet: @wallet, transaction_type: 'credit', amount: amount)
transaction = WalletTransaction.new(
invoicing_profile: @user.invoicing_profile,
wallet: @wallet,
transaction_type: 'credit',
amount: amount
)
if transaction.save
NotificationCenter.call type: 'notify_user_wallet_is_credited',
receiver: @wallet.user,
@ -53,7 +61,8 @@ class WalletService
avoir.description = description
avoir.payment_method = 'wallet'
avoir.subscription_to_expire = false
avoir.invoicing_profile_id = wallet_transaction.wallet.user.invoicing_profile.id
avoir.invoicing_profile_id = wallet_transaction.invoicing_profile_id
avoir.statistic_profile_id = wallet_transaction.wallet.user.statistic_profile.id
avoir.total = wallet_transaction.amount * 100.0
avoir.save!

View File

@ -150,5 +150,19 @@ namespace :fablab do
name: 'theme'
)
end
desc '[release 4.3.3] add statistic_profile_id to refund invoices for WalletTransactions'
task avoirs_wallet_transaction: :environment do
Avoir.where(invoiced_type: WalletTransaction.name).each do |a|
next unless a.statistic_profile_id.nil?
begin
a.statistic_profile_id = a.invoiced.wallet.user&.statistic_profile&.id
a.save!
rescue ActiveRecord::RecordInvalid => e
printf "Unable to modify the refund invoice (id %<id>s): %<error>s\nIgnoring that record...\n", id: a.id, error: e
end
end
end
end
end