mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Add shortcut to order's exchange
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user