Remove payment method from customer account transaction

This commit is contained in:
Gaetan Craig-Riou
2026-03-06 12:58:07 +11:00
parent bd0dcd99f3
commit e7a2b7ea48
14 changed files with 12 additions and 35 deletions

View File

@@ -8,9 +8,6 @@ class CustomerAccountTransaction < ApplicationRecord
localize_number :amount
belongs_to :customer
belongs_to :payment_method, -> {
internal
}, class_name: "Spree::PaymentMethod", inverse_of: :customer_account_transactions
belongs_to :payment, class_name: "Spree::Payment", optional: true
belongs_to :created_by, class_name: "Spree::User", optional: true

View File

@@ -15,7 +15,6 @@ module Spree
default_scope -> { where(deleted_at: nil).where.not(type: INTERNAL) }
has_many :credit_cards, class_name: "Spree::CreditCard", dependent: :destroy
has_many :customer_account_transactions, dependent: :restrict_with_error
has_many :payments, class_name: "Spree::Payment", dependent: :restrict_with_error
validates :name, presence: true

View File

@@ -9,8 +9,6 @@
= t(".transaction_date")
%th.description
= t(".description")
%th.payment-method
= t(".payment_method")
%th.created-by
= t(".created_by")
%th.amount
@@ -25,8 +23,6 @@
= transaction.updated_at.strftime("%Y-%m-%d")
%td.description
= transaction.description
%td.payment-method
= transaction.payment_method.display_name
%td.created-by
= transaction.created_by&.email
%td.amount

View File

@@ -26,19 +26,15 @@
%tr
%th.order1= t(".transaction_date")
%th.order2= t(".description")
%th.order3= t(".payment_method")
%th.order4= t(".amount")
%th.order5= t(".running_balance")
%tbody.transaction-group
- data_loader.customer_account_transactions.each do |transaction|
%tr.transaction-row.even
%td.order1
- # TODO move to helper
= transaction.updated_at.strftime("%Y-%m-%d")
%td.order2
= transaction.description
%td.order3
= transaction.payment_method.display_name
%td.order4
= Spree::Money.new(transaction.amount)
%td.order5

View File

@@ -900,7 +900,6 @@ en:
available_credit: "Available credit: %{available_credit}"
transaction_date: Transaction Date
description: Description
payment_method: Payment method
amount: Amount
created_by: Created by
running_balance: Running balance
@@ -5052,7 +5051,6 @@ en:
title: Customer Transactions
credit_available: "Credit available: %{credit}"
transaction_date: Transaction Date
payment_method: Payment method
description: Description
amount: Amount
running_balance: Running balance

View File

@@ -0,0 +1,8 @@
# frozen_string_literal: true
class DeletePaymentMethodFromCustomerAccountTransactions < ActiveRecord::Migration[7.1]
def change
remove_reference :customer_account_transactions,
:payment_method, index: true, foreign_key: { to_table: :spree_payment_methods }
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2026_03_01_031845) do
ActiveRecord::Schema[7.1].define(version: 2026_03_06_015040) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
@@ -93,16 +93,14 @@ ActiveRecord::Schema[7.1].define(version: 2026_03_01_031845) do
t.decimal "amount", precision: 10, scale: 2, null: false
t.string "currency"
t.string "description"
t.bigint "payment_method_id", null: false
t.integer "payment_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.decimal "balance", precision: 10, scale: 2, default: "0.0"
t.bigint "created_by_id"
t.index ["created_by_id"], name: "index_customer_account_transactions_on_created_by_id"
t.index ["payment_id"], name: "index_customer_account_transactions_on_payment_id"
t.index ["customer_id"], name: "index_customer_account_transactions_on_customer_id"
t.index ["payment_method_id"], name: "index_customer_account_transactions_on_payment_method_id"
t.index ["payment_id"], name: "index_customer_account_transactions_on_payment_id"
end
create_table "customers", id: :serial, force: :cascade do |t|
@@ -1175,7 +1173,6 @@ ActiveRecord::Schema[7.1].define(version: 2026_03_01_031845) do
add_foreign_key "coordinator_fees", "order_cycles", name: "coordinator_fees_order_cycle_id_fk"
add_foreign_key "custom_tabs", "enterprises", on_delete: :cascade
add_foreign_key "customer_account_transactions", "customers"
add_foreign_key "customer_account_transactions", "spree_payment_methods", column: "payment_method_id"
add_foreign_key "customer_account_transactions", "spree_payments", column: "payment_id"
add_foreign_key "customer_account_transactions", "spree_users", column: "created_by_id"
add_foreign_key "customers", "enterprises", name: "customers_enterprise_id_fk"

View File

@@ -5,6 +5,5 @@ FactoryBot.define do
customer { build(:customer) }
amount { 10.00 }
currency { "AUD" }
payment_method { build(:api_customer_credit_payment_method) }
end
end

View File

@@ -9,7 +9,6 @@ RSpec.describe CustomerAccountTransaction do
it { is_expected.to belong_to(:customer) }
it { is_expected.to validate_presence_of(:amount) }
it { is_expected.to validate_presence_of(:currency) }
it { is_expected.to belong_to(:payment_method) }
it { is_expected.to belong_to(:payment).optional }
it { is_expected.to belong_to(:created_by).optional }
end

View File

@@ -7,7 +7,6 @@ RSpec.describe Spree::PaymentMethod do
describe "associations" do
subject { build(:payment_method) }
it { is_expected.to have_many(:customer_account_transactions) }
it { is_expected.to have_many(:payments) }
end

View File

@@ -20,8 +20,7 @@ RSpec.describe Orders::CustomerCreditService do
create(
:customer_account_transaction,
amount: 100.00,
customer: order.customer,
payment_method: credit_payment_method
customer: order.customer
)
subject.apply
@@ -45,7 +44,6 @@ RSpec.describe Orders::CustomerCreditService do
:customer_account_transaction,
amount: 100.00,
customer: order.customer,
payment_method: credit_payment_method
)
subject.apply
@@ -66,7 +64,6 @@ RSpec.describe Orders::CustomerCreditService do
:customer_account_transaction,
amount: 5.00,
customer: order.customer,
payment_method: credit_payment_method
)
subject.apply
@@ -82,7 +79,6 @@ RSpec.describe Orders::CustomerCreditService do
:customer_account_transaction,
amount: 5.00,
customer: order.customer,
payment_method: credit_payment_method
)
allow_any_instance_of(Spree::Payment).to receive(:internal_purchase!)
.and_raise(Spree::Core::GatewayError)
@@ -104,12 +100,10 @@ RSpec.describe Orders::CustomerCreditService do
context "when credit payment method is missing" do
before do
# Add credit
payment_method = create(:api_customer_credit_payment_method)
create(
:customer_account_transaction,
amount: 5.00,
customer: order.customer,
payment_method:
)
credit_payment_method.destroy!
end
@@ -155,7 +149,6 @@ RSpec.describe Orders::CustomerCreditService do
subject.refund(user: )
last_transaction = order.customer.customer_account_transactions.last
expect(last_transaction.payment_method).to eq(credit_payment_method)
expect(last_transaction.amount).to eq(12.00)
expect(last_transaction.created_by).to eq(user)
end

View File

@@ -352,7 +352,7 @@ RSpec.describe "As a consumer, I want to checkout my order" do
end
context "wiht customer credit" do
let(:credit_payment_method) { create(:customer_credit_payment_method) }
let!(:credit_payment_method) { create(:customer_credit_payment_method) }
let(:credit_amount) { 100.00 }
let(:customer) { create(:customer, user:, enterprise: distributor) }
@@ -364,7 +364,6 @@ RSpec.describe "As a consumer, I want to checkout my order" do
:customer_account_transaction,
amount: credit_amount,
customer: order.customer,
payment_method: credit_payment_method
)
visit checkout_step_path(:details)
fill_out_details

View File

@@ -116,7 +116,6 @@ RSpec.describe "As a consumer, I want to checkout my order" do
create(
:customer_account_transaction,
amount: 100, customer: order.customer,
payment_method: credit_payment_method
)
# Add credit payment
payment = order.payments.create!(payment_method: credit_payment_method,

View File

@@ -393,7 +393,6 @@ RSpec.describe "As a consumer, I want to checkout my order" do
:customer_account_transaction,
amount: 100,
customer: order.customer,
payment_method: credit_payment_method
)
# Add credit payment
payment = order.payments.create!(payment_method: credit_payment_method,
@@ -424,7 +423,6 @@ RSpec.describe "As a consumer, I want to checkout my order" do
visit checkout_step_path(:summary)
place_order
# TODO it should be displaying some kind indication it was paid with credit
expect(page).to have_content "PAID"
expect(page).to have_content "Paying via: Customer credit"
expect(page).to have_selector("#customer-credit", text: with_currency(-10.00))