mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Allow reset of "on demand" for variant overrides
Change the UI control for "on demand" in the Inventory page from a checkbox to a SELECT field with three options: nil, true, and false. This resolves the following issues: * There is no way to tell between nil and false - both are represented by an unticked checkbox. * There is no way to go back to nil.
This commit is contained in:
@@ -13,6 +13,10 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl",
|
||||
$scope.RequestMonitor = RequestMonitor
|
||||
$scope.selectView = Views.selectView
|
||||
$scope.currentView = -> Views.currentView
|
||||
$scope.onDemandOptions = [
|
||||
{ description: t('js.yes'), value: true },
|
||||
{ description: t('js.no'), value: false }
|
||||
]
|
||||
|
||||
$scope.views = Views.setViews
|
||||
inventory: { name: t('js.variant_overrides.inventory_products'), visible: true }
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
%td.on_hand{ ng: { show: 'columns.on_hand.visible' } }
|
||||
%input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: {model: 'variantOverrides[hub_id][variant.id].count_on_hand'}, placeholder: '{{ variant.on_hand }}', 'ofn-track-variant-override' => 'count_on_hand'}
|
||||
%td.on_demand{ ng: { show: 'columns.on_demand.visible' } }
|
||||
%input.field{ :type => 'checkbox', name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand' }, 'ofn-track-variant-override' => 'on_demand' }
|
||||
%select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' }
|
||||
%option{ value: '' }= t(".on_demand.use_producer_settings")
|
||||
%td.reset{ ng: { show: 'columns.reset.visible' } }
|
||||
%input{name: 'variant-overrides-{{ variant.id }}-resettable', type: 'checkbox', ng: {model: 'variantOverrides[hub_id][variant.id].resettable'}, placeholder: '{{ variant.resettable }}', 'ofn-track-variant-override' => 'resettable'}
|
||||
%td.reset{ ng: { show: 'columns.reset.visible' } }
|
||||
@@ -24,4 +25,4 @@
|
||||
%button.icon-remove.hide.fullwidth{ :type => 'button', ng: { click: "setVisibility(hub_id,variant.id,false)" } }
|
||||
= t('admin.variant_overrides.index.hide')
|
||||
%td.import_date{ ng: { show: 'columns.import_date.visible' } }
|
||||
%span {{variantOverrides[hub_id][variant.id].import_date | date:"MMMM dd, yyyy HH:mm"}}
|
||||
%span {{variantOverrides[hub_id][variant.id].import_date | date:"MMMM dd, yyyy HH:mm"}}
|
||||
|
||||
@@ -623,6 +623,9 @@ en:
|
||||
new_powertip: These products are available to be added to your inventory. Click 'Add' to add a product to your inventory, or 'Hide' to hide it from view. You can always change your mind later!
|
||||
controls:
|
||||
back_to_my_inventory: Back to my inventory
|
||||
products_variants:
|
||||
on_demand:
|
||||
use_producer_settings: "Use producer settings"
|
||||
orders:
|
||||
invoice_email_sent: 'Invoice email has been sent'
|
||||
order_email_resent: 'Order email has been resent'
|
||||
@@ -2445,6 +2448,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
pending: Pending
|
||||
shipped: Shipped
|
||||
js:
|
||||
"yes": "Yes"
|
||||
"no": "No"
|
||||
saving: 'Saving...'
|
||||
changes_saved: 'Changes saved.'
|
||||
save_changes_first: Save changes first.
|
||||
|
||||
@@ -141,7 +141,7 @@ feature %q{
|
||||
fill_in "variant-overrides-#{variant.id}-sku", with: 'NEWSKU'
|
||||
fill_in "variant-overrides-#{variant.id}-price", with: '777.77'
|
||||
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123'
|
||||
check "variant-overrides-#{variant.id}-on_demand"
|
||||
select I18n.t("js.yes"), from: "variant-overrides-#{variant.id}-on_demand"
|
||||
page.should have_content "Changes to one override remain unsaved."
|
||||
|
||||
expect do
|
||||
@@ -218,7 +218,7 @@ feature %q{
|
||||
end
|
||||
|
||||
context "with overrides" do
|
||||
let!(:vo) { create(:variant_override, variant: variant, hub: hub, price: 77.77, count_on_hand: 11111, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) }
|
||||
let!(:vo) { create(:variant_override, variant: variant, hub: hub, price: 77.77, on_demand: true, count_on_hand: 11111, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) }
|
||||
let!(:vo_no_auth) { create(:variant_override, variant: variant, hub: hub2, price: 1, count_on_hand: 2) }
|
||||
let!(:product2) { create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1) }
|
||||
let!(:variant2) { create(:variant, product: product2, unit_value: 8, price: 1.00, on_hand: 12) }
|
||||
@@ -236,6 +236,7 @@ feature %q{
|
||||
it "product values are affected by overrides" do
|
||||
page.should have_input "variant-overrides-#{variant.id}-price", with: '77.77', placeholder: '1.23'
|
||||
page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: '12'
|
||||
expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.yes")
|
||||
end
|
||||
|
||||
it "updates existing overrides" do
|
||||
@@ -255,10 +256,32 @@ feature %q{
|
||||
vo.count_on_hand.should == 8888
|
||||
end
|
||||
|
||||
it "updates on_demand settings" do
|
||||
select I18n.t("js.no"), from: "variant-overrides-#{variant.id}-on_demand"
|
||||
click_button I18n.t("save_changes")
|
||||
expect(page).to have_content I18n.t("js.changes_saved")
|
||||
|
||||
vo.reload
|
||||
expect(vo.on_demand).to eq(false)
|
||||
|
||||
select I18n.t("js.yes"), from: "variant-overrides-#{variant.id}-on_demand"
|
||||
click_button I18n.t("save_changes")
|
||||
expect(page).to have_content I18n.t("js.changes_saved")
|
||||
|
||||
vo.reload
|
||||
expect(vo.on_demand).to eq(true)
|
||||
|
||||
select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand"
|
||||
click_button I18n.t("save_changes")
|
||||
expect(page).to have_content I18n.t("js.changes_saved")
|
||||
|
||||
vo.reload
|
||||
expect(vo.on_demand).to be_nil
|
||||
end
|
||||
|
||||
# Any new fields added to the VO model need to be added to this test
|
||||
it "deletes overrides when values are cleared" do
|
||||
first("div#columns-dropdown", :text => "COLUMNS").click
|
||||
first("div#columns-dropdown div.menu div.menu_item", text: "On Demand").click
|
||||
first("div#columns-dropdown div.menu div.menu_item", text: "Enable Stock Reset?").click
|
||||
first("div#columns-dropdown div.menu div.menu_item", text: "Tags").click
|
||||
first("div#columns-dropdown", :text => "COLUMNS").click
|
||||
@@ -272,6 +295,7 @@ feature %q{
|
||||
# Clearing values manually
|
||||
fill_in "variant-overrides-#{variant.id}-price", with: ''
|
||||
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: ''
|
||||
select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand"
|
||||
fill_in "variant-overrides-#{variant.id}-default_stock", with: ''
|
||||
within "tr#v_#{variant.id}" do
|
||||
vo.tag_list.each do |tag|
|
||||
|
||||
Reference in New Issue
Block a user