Reset stock for unavailable products on OC open

This commit is contained in:
Maikel Linke
2025-03-27 14:40:50 +11:00
parent 9e3ff412f9
commit 1a5b6bbc8f
2 changed files with 22 additions and 4 deletions

View File

@@ -57,6 +57,10 @@ class OpenOrderCycleJob < ApplicationJob
catalog = DfcCatalog.load(dfc_user, catalog_url)
catalog.apply_wholesale_values!
variants = Spree::Variant.where(id: catalog_links.pluck(:subject_id))
importer = DfcCatalogImporter.new(variants, catalog)
importer.reset_absent_variants
catalog_links.each do |link|
catalog_item = catalog.item(link.semantic_id)

View File

@@ -33,21 +33,34 @@ RSpec.describe OpenOrderCycleJob do
let(:enterprise) { create(:supplier_enterprise) }
let!(:variant) { create(:variant, name: "Sauce", supplier_id: enterprise.id) }
let!(:variant_discontinued) {
create(:variant, name: "Shiraz 1971", supplier_id: enterprise.id)
}
let!(:order_cycle) {
create(:simple_order_cycle, orders_open_at: now,
suppliers: [enterprise], variants: [variant])
create(
:simple_order_cycle,
orders_open_at: now,
suppliers: [enterprise],
variants: [variant, variant_discontinued]
)
}
it "synchronises products from a FDC catalog", vcr: true do
user.update!(oidc_account: build(:testdfc_account))
# One product is existing in OFN
# One current product is existing in OFN
product_id =
"https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts/44519466467635"
variant.semantic_links << SemanticLink.new(semantic_id: product_id)
# One discontinued product is existing in OFN
old_product_id =
"https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts/44519466467635-disc"
variant_discontinued.semantic_links << SemanticLink.new(semantic_id: old_product_id)
expect {
subject
variant.reload
variant_discontinued.reload
order_cycle.reload
}.to change { order_cycle.opened_at }
.and change { enterprise.supplied_products.count }.by(0) # It shouldn't add, only update
@@ -57,7 +70,8 @@ RSpec.describe OpenOrderCycleJob do
.and change { variant.price }.to(1.57)
.and change { variant.on_demand }.to(true)
.and change { variant.on_hand }.by(0)
.and query_database 46
.and change { variant_discontinued.on_hand }.to(0)
.and query_database 58
end
end