diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aae19bbb..e54a57877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog Fab Manager +- Fix a bug: when paying a reservation with wallet, the invoice footprint is not correctly updated + ## v3.1.0 2019 April 8 - Asynchronously generate accounting archives diff --git a/app/exceptions/invalid_footprint_error.rb b/app/exceptions/invalid_footprint_error.rb new file mode 100644 index 000000000..e44c66b9b --- /dev/null +++ b/app/exceptions/invalid_footprint_error.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +# Raised when a chained footprint is detected as wrong (invoices, invoice_items, history_values) +class InvalidFootprintError < StandardError +end diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 33aa18b68..37b697944 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -230,6 +230,15 @@ class Invoice < ActiveRecord::Base invoice_items.map(&:check_footprint).all? && footprint == compute_footprint end + def set_wallet_transaction(amount, transaction_id) + if check_footprint + update_columns(wallet_amount: amount, wallet_transaction_id: transaction_id) + chain_record + else + raise InvalidFootprintError + end + end + private def generate_and_send_invoice diff --git a/app/models/reservation.rb b/app/models/reservation.rb index 9de1fe353..fdc72f27a 100644 --- a/app/models/reservation.rb +++ b/app/models/reservation.rb @@ -486,7 +486,7 @@ class Reservation < ActiveRecord::Base # wallet debit success raise DebitWalletError unless wallet_transaction - invoice.update_columns(wallet_amount: @wallet_amount_debit, wallet_transaction_id: wallet_transaction.id) + invoice.set_wallet_transaction(@wallet_amount_debit, wallet_transaction.id) end # this function only use for compute total of reservation before save diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 000000000..acfebafa8 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +Spring.after_fork do + if ENV['DEBUGGER_STORED_RUBYLIB'] + starter = ENV['BUNDLER_ORIG_RUBYOPT'][2..-1] + load(starter + '.rb') + end +end