mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Allow on-demand VariantOverride to track stock
We allowed this for producer stock and need to do the same for inventory stock. This will allow us to create backorders for missing, but promised stock.
This commit is contained in:
@@ -6,14 +6,14 @@
|
||||
# `count_on_hand` can either be: nil or a number
|
||||
#
|
||||
# This means that a variant override can be in six different stock states
|
||||
# but only three of them are valid.
|
||||
# but only four of them are valid.
|
||||
#
|
||||
# | on_demand | count_on_hand | stock_overridden? | use_producer_stock_settings? | valid? |
|
||||
# |-----------|---------------|-------------------|------------------------------|--------|
|
||||
# | 1 | nil | false | false | true |
|
||||
# | 0 | x | true | false | true |
|
||||
# | nil | nil | false | true | true |
|
||||
# | 1 | x | ? | ? | false |
|
||||
# | 1 | x | true | false | true |
|
||||
# | 0 | nil | ? | ? | false |
|
||||
# | nil | x | ? | ? | false |
|
||||
#
|
||||
@@ -27,7 +27,6 @@ module StockSettingsOverrideValidation
|
||||
|
||||
def require_compatible_on_demand_and_count_on_hand
|
||||
disallow_count_on_hand_if_using_producer_stock_settings
|
||||
disallow_count_on_hand_if_on_demand
|
||||
require_count_on_hand_if_limited_stock
|
||||
end
|
||||
|
||||
@@ -39,14 +38,6 @@ module StockSettingsOverrideValidation
|
||||
errors.add(:count_on_hand, error_message)
|
||||
end
|
||||
|
||||
def disallow_count_on_hand_if_on_demand
|
||||
return unless on_demand? && count_on_hand.present?
|
||||
|
||||
error_message = I18n.t("count_on_hand.on_demand_but_count_on_hand_set",
|
||||
scope: i18n_scope_for_stock_settings_override_validation_error)
|
||||
errors.add(:count_on_hand, error_message)
|
||||
end
|
||||
|
||||
def require_count_on_hand_if_limited_stock
|
||||
return unless on_demand == false && count_on_hand.blank?
|
||||
|
||||
|
||||
@@ -127,7 +127,6 @@ en:
|
||||
variant_override:
|
||||
count_on_hand:
|
||||
using_producer_stock_settings_but_count_on_hand_set: "must be blank because using producer stock settings"
|
||||
on_demand_but_count_on_hand_set: "must be blank if on demand"
|
||||
limited_stock_but_no_count_on_hand: "must be specified because forcing limited stock"
|
||||
messages:
|
||||
confirmation: "doesn't match %{attribute}"
|
||||
|
||||
@@ -56,8 +56,6 @@ RSpec.describe Spree::Variant do
|
||||
end
|
||||
|
||||
it "reduces stock when on demand" do
|
||||
pending "VariantOverride allowing stock with on_demand"
|
||||
|
||||
override.update!(on_demand: true, count_on_hand: 7)
|
||||
|
||||
expect {
|
||||
|
||||
@@ -97,11 +97,8 @@ RSpec.describe VariantOverride do
|
||||
context "when count_on_hand is set" do
|
||||
let(:count_on_hand) { 1 }
|
||||
|
||||
it "is invalid" do
|
||||
expect(variant_override).not_to be_valid
|
||||
error_message = I18n.t("on_demand_but_count_on_hand_set",
|
||||
scope: [i18n_scope_for_error, "count_on_hand"])
|
||||
expect(variant_override.errors[:count_on_hand]).to eq([error_message])
|
||||
it "is valid" do
|
||||
expect(variant_override).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -624,33 +624,6 @@ RSpec.describe "Product Import" do
|
||||
expect(page).not_to have_content "line 3: Sprouts"
|
||||
end
|
||||
|
||||
it "handles on_demand and on_hand validations with inventory - With both values set" do
|
||||
csv_data = <<~CSV
|
||||
name, distributor, producer, category, on_hand, price, units, on_demand
|
||||
Beans, Another Enterprise, User Enterprise, Vegetables, 6, 3.20, 500, 1
|
||||
Sprouts, Another Enterprise, User Enterprise, Vegetables, 6, 6.50, 500, 1
|
||||
Cabbage, Another Enterprise, User Enterprise, Vegetables, 0, 1.50, 500, 1
|
||||
CSV
|
||||
File.write('/tmp/test.csv', csv_data)
|
||||
|
||||
visit main_app.admin_product_import_path
|
||||
select 'Inventories', from: "settings_import_into"
|
||||
attach_file 'file', '/tmp/test.csv'
|
||||
click_button 'Upload'
|
||||
|
||||
proceed_to_validation
|
||||
|
||||
expect(page).to have_selector '.item-count', text: "3"
|
||||
expect(page).to have_selector '.invalid-count', text: "3"
|
||||
|
||||
find('div.header-description', text: 'Items contain errors').click
|
||||
expect(page).to have_content "line 2: Beans - Count_on_hand must be blank if on demand"
|
||||
expect(page).to have_content "line 3: Sprouts - Count_on_hand must be blank if on demand"
|
||||
expect(page).to have_content "line 4: Cabbage - Count_on_hand must be blank if on demand"
|
||||
expect(page).to have_content "Imported file contains invalid entries"
|
||||
expect(page).not_to have_selector 'input[type=submit][value="Save"]'
|
||||
end
|
||||
|
||||
it "imports lines with all allowed units" do
|
||||
csv_data = CSV.generate do |csv|
|
||||
csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
|
||||
|
||||
Reference in New Issue
Block a user