Add shortcut to order's exchange

This commit is contained in:
Maikel Linke
2024-10-31 14:35:34 +11:00
parent 8098131dba
commit 4610141ed8
3 changed files with 7 additions and 3 deletions

View File

@@ -134,7 +134,6 @@ class BackorderJob < ApplicationJob
user, order.distributor, order.order_cycle, placed_order.semanticId
)
exchange = order.order_cycle.exchanges.outgoing.find_by(receiver: order.distributor)
exchange.semantic_links.create!(semantic_id: placed_order.semanticId)
order.exchange.semantic_links.create!(semantic_id: placed_order.semanticId)
end
end

View File

@@ -67,8 +67,11 @@ module Spree
class_name: 'Spree::Adjustment',
dependent: :destroy
has_many :invoices, dependent: :restrict_with_exception
belongs_to :order_cycle, optional: true
has_one :exchange, ->(order) {
outgoing.to_enterprise(order.distributor)
}, through: :order_cycle, source: :exchanges
belongs_to :distributor, class_name: 'Enterprise', optional: true
belongs_to :customer, optional: true
has_one :proxy_order, dependent: :destroy

View File

@@ -6,6 +6,8 @@ RSpec.describe Spree::Order do
let(:user) { build(:user, email: "spree@example.com") }
let(:order) { build(:order, user:) }
it { is_expected.to have_one :exchange }
describe "#errors" do
it "provides friendly error messages" do
order.ship_address = Spree::Address.new