mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Create BackorderJob to place wholesale orders
This commit is contained in:
27
app/jobs/backorder_job.rb
Normal file
27
app/jobs/backorder_job.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class BackorderJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def self.check_stock(order)
|
||||
variants_needing_stock = order.variants.select do |variant|
|
||||
# TODO: scope variants to hub.
|
||||
# We are only supporting producer stock at the moment.
|
||||
variant.on_hand&.negative?
|
||||
end
|
||||
|
||||
linked_variants = variants_needing_stock.select do |variant|
|
||||
variant.semantic_links.present?
|
||||
end
|
||||
|
||||
linked_variants.each do |variant|
|
||||
# needed_quantity = -1 * variant.on_hand
|
||||
# create DFC Order
|
||||
# post order to endpoint
|
||||
end
|
||||
end
|
||||
|
||||
def perform(*args)
|
||||
# Do something later
|
||||
end
|
||||
end
|
||||
@@ -388,6 +388,8 @@ module Spree
|
||||
|
||||
deliver_order_confirmation_email
|
||||
|
||||
BackorderJob.check_stock(self)
|
||||
|
||||
state_changes.create(
|
||||
previous_state: 'cart',
|
||||
next_state: 'complete',
|
||||
|
||||
13
spec/jobs/backorder_job_spec.rb
Normal file
13
spec/jobs/backorder_job_spec.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe BackorderJob do
|
||||
let(:order) { create(:completed_order_with_totals) }
|
||||
|
||||
describe ".check_stock" do
|
||||
it "ignores products without semantic link" do
|
||||
BackorderJob.check_stock(order)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user