From 13f50c0e33066dc5f92315ec9200ba996511555a Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 27 May 2021 13:43:54 +0200 Subject: [PATCH] remove references to WalletService.transactable --- app/models/payment_schedule.rb | 2 -- app/services/wallet_service.rb | 20 ++----------------- .../api/wallet/transactions.json.jbuilder | 2 +- db/structure.sql | 8 -------- test/services/wallet_service_test.rb | 6 +++--- 5 files changed, 6 insertions(+), 32 deletions(-) diff --git a/app/models/payment_schedule.rb b/app/models/payment_schedule.rb index 014b60f72..5c58dced4 100644 --- a/app/models/payment_schedule.rb +++ b/app/models/payment_schedule.rb @@ -14,8 +14,6 @@ class PaymentSchedule < PaymentDocument has_many :payment_schedule_items has_many :payment_gateway_objects, as: :item - has_one :wallet_transaction, as: :transactable - before_create :add_environment after_create :update_reference, :chain_record after_commit :generate_and_send_document, on: [:create], if: :persisted? diff --git a/app/services/wallet_service.rb b/app/services/wallet_service.rb index 43bd14a80..eaebede51 100644 --- a/app/services/wallet_service.rb +++ b/app/services/wallet_service.rb @@ -33,15 +33,14 @@ class WalletService end ## debit an amount to wallet, if debit success then return a wallet transaction - def debit(amount, transactable) + def debit(amount) ActiveRecord::Base.transaction do if @wallet.debit(amount) transaction = WalletTransaction.new( invoicing_profile: @user&.invoicing_profile, wallet: @wallet, transaction_type: 'debit', - amount: amount, - transactable: transactable + amount: amount ) return transaction if transaction.save @@ -91,19 +90,4 @@ class WalletService wallet_amount >= total ? total : wallet_amount end - - ## - # Subtract the amount of the transactable item (Subscription|Reservation) from the customer's wallet - ## - def self.debit_user_wallet(payment, user, transactable) - wallet_amount = WalletService.wallet_amount_debit(payment, user) - return unless wallet_amount.present? && wallet_amount != 0 - - amount = wallet_amount / 100.0 - wallet_transaction = WalletService.new(user: user, wallet: user.wallet).debit(amount, transactable) - # wallet debit success - raise DebitWalletError unless wallet_transaction - - payment.set_wallet_transaction(wallet_amount, wallet_transaction.id) - end end diff --git a/app/views/api/wallet/transactions.json.jbuilder b/app/views/api/wallet/transactions.json.jbuilder index ba61cf89f..e1665dacb 100644 --- a/app/views/api/wallet/transactions.json.jbuilder +++ b/app/views/api/wallet/transactions.json.jbuilder @@ -1,5 +1,5 @@ json.array!(@wallet_transactions) do |t| - json.extract! t, :id, :transaction_type, :created_at, :amount, :transactable_type + json.extract! t, :id, :transaction_type, :created_at, :amount json.user do json.id t.invoicing_profile.user_id json.full_name t.invoicing_profile.full_name diff --git a/db/structure.sql b/db/structure.sql index 4b15901d7..b19c1e543 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -5213,14 +5213,6 @@ CREATE INDEX profiles_lower_unaccent_last_name_trgm_idx ON public.profiles USING CREATE INDEX projects_search_vector_idx ON public.projects USING gin (search_vector); --- --- Name: accounting_periods accounting_periods_del_protect; Type: RULE; Schema: public; Owner: - --- - -CREATE RULE accounting_periods_del_protect AS - ON DELETE TO public.accounting_periods DO INSTEAD NOTHING; - - -- -- Name: projects projects_search_content_trigger; Type: TRIGGER; Schema: public; Owner: - -- diff --git a/test/services/wallet_service_test.rb b/test/services/wallet_service_test.rb index 15f68dace..35ecbcad3 100644 --- a/test/services/wallet_service_test.rb +++ b/test/services/wallet_service_test.rb @@ -33,7 +33,7 @@ class WalletServiceTest < ActiveSupport::TestCase test 'create a debit transaction after debit amount to wallet' do service = WalletService.new(user: @vlonchamp, wallet: @vlonchamp_wallet) expected_amount = @vlonchamp_wallet.amount - 5 - transaction = service.debit(5, nil) + transaction = service.debit(5) @vlonchamp_wallet.reload assert transaction assert_equal @vlonchamp_wallet.amount, expected_amount @@ -46,7 +46,7 @@ class WalletServiceTest < ActiveSupport::TestCase test 'dont debit amount > wallet amount' do service = WalletService.new(user: @vlonchamp, wallet: @vlonchamp_wallet) expected_amount = @vlonchamp_wallet.amount - service.debit(100, nil) + service.debit(100) @vlonchamp_wallet.reload assert_equal @vlonchamp_wallet.amount, expected_amount end @@ -54,7 +54,7 @@ class WalletServiceTest < ActiveSupport::TestCase test 'rollback debited amount if has an error when create wallet transaction' do service = WalletService.new(wallet: @vlonchamp_wallet) expected_amount = @vlonchamp_wallet.amount - transaction = service.debit(5, nil) + transaction = service.debit(5) @vlonchamp_wallet.reload assert_equal @vlonchamp_wallet.amount, expected_amount assert_not transaction