1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

remove references to WalletService.transactable

This commit is contained in:
Sylvain 2021-05-27 13:43:54 +02:00
parent 16df7f9506
commit 13f50c0e33
5 changed files with 6 additions and 32 deletions

View File

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

View File

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

View File

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

View File

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

View File

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