Merge pull request #13049 from mkllnk/dfc-wholesale-stock

Calculate stock from DFC wholesale variants
This commit is contained in:
Maikel
2025-01-08 12:32:44 +11:00
committed by GitHub
10 changed files with 169 additions and 73 deletions

View File

@@ -14,13 +14,14 @@ RSpec.describe CompleteBackorderJob do
let(:orderer) { FdcBackorderer.new(user, urls) }
let(:order) {
backorder = orderer.find_or_build_order(ofn_order)
broker = FdcOfferBroker.new(user, urls.catalog_url)
catalog = DfcCatalog.load(user, urls.catalog_url)
broker = FdcOfferBroker.new(catalog)
bean_offer = broker.best_offer(product_link).offer
bean_line = orderer.find_or_build_order_line(backorder, bean_offer)
bean_line.quantity = 3
chia = broker.catalog_item(chia_seed_retail_link)
chia = catalog.item(chia_seed_retail_link)
chia_offer = broker.offer_of(chia)
chia_line = orderer.find_or_build_order_line(backorder, chia_offer)
chia_line.quantity = 5

View File

@@ -31,9 +31,9 @@ RSpec.describe FdcBackorderer do
expect(backorder.lines).to eq []
# Add items and place the new order:
catalog = FdcOfferBroker.load_catalog(order.distributor.owner, urls.catalog_url)
product = catalog.find { |i| i.semanticType == "dfc-b:SuppliedProduct" }
offer = FdcOfferBroker.new(nil, nil).offer_of(product)
catalog = DfcCatalog.load(order.distributor.owner, urls.catalog_url)
product = catalog.products.first
offer = FdcOfferBroker.new(nil).offer_of(product)
line = subject.find_or_build_order_line(backorder, offer)
line.quantity = 3
placed_order = subject.send_order(backorder)
@@ -74,15 +74,14 @@ RSpec.describe FdcBackorderer do
describe "#find_or_build_order_line" do
it "add quantity to an existing line item", vcr: true do
catalog = FdcOfferBroker.load_catalog(order.distributor.owner, urls.catalog_url)
catalog = DfcCatalog.load(order.distributor.owner, urls.catalog_url)
backorder = subject.find_or_build_order(order)
expect(backorder.lines.count).to eq 0
# Add new item to the new order:
catalog = FdcOfferBroker.load_catalog(order.distributor.owner, urls.catalog_url)
product = catalog.find { |i| i.semanticType == "dfc-b:SuppliedProduct" }
offer = FdcOfferBroker.new(nil, nil).offer_of(product)
product = catalog.products.first
offer = FdcOfferBroker.new(nil).offer_of(product)
line = subject.find_or_build_order_line(backorder, offer)
expect(backorder.lines.count).to eq 1

View File

@@ -3,9 +3,11 @@
require 'spec_helper'
RSpec.describe FdcOfferBroker do
subject { FdcOfferBroker.new(user, catalog_url) }
subject { FdcOfferBroker.new(catalog) }
let(:catalog) {
VCR.use_cassette(:fdc_catalog) { subject.catalog }
VCR.use_cassette(:fdc_catalog) {
DfcCatalog.load(user, catalog_url)
}
}
let(:catalog_url) {
"https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts"
@@ -15,7 +17,7 @@ RSpec.describe FdcOfferBroker do
}
let(:user) { build(:testdfc_user) }
let(:product) {
catalog.find { |item| item.semanticType == "dfc-b:SuppliedProduct" }
catalog.products.first
}
describe ".best_offer" do