mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Changed name enable_reset to resettable in Variant Overrides table & updated views, specs accordingly
This commit is contained in:
committed by
Rob Harrington
parent
25454d3e97
commit
e423e890e0
@@ -20,7 +20,7 @@ angular.module("admin.variantOverrides").factory "VariantOverrides", (variantOve
|
||||
count_on_hand: null
|
||||
on_demand: null
|
||||
default_stock: null
|
||||
enable_reset: false
|
||||
resettable: false
|
||||
|
||||
updateIds: (updatedVos) ->
|
||||
for vo in updatedVos
|
||||
|
||||
@@ -56,7 +56,7 @@ class VariantOverride < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def reset_stock!
|
||||
if enable_reset
|
||||
if resettable
|
||||
if default_stock?
|
||||
self.attributes = { count_on_hand: default_stock }
|
||||
self.save
|
||||
|
||||
@@ -7,7 +7,7 @@ class VariantOverrideSet < ModelSet
|
||||
attrs['price'].blank? &&
|
||||
attrs['count_on_hand'].blank? &&
|
||||
attrs['default_stock'].blank? &&
|
||||
attrs['enable_reset'].blank? &&
|
||||
attrs['resettable'].blank? &&
|
||||
attrs['sku'].nil? &&
|
||||
attrs['on_demand'].nil?
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class Api::Admin::VariantOverrideSerializer < ActiveModel::Serializer
|
||||
attributes :id, :hub_id, :variant_id, :sku, :price, :count_on_hand, :on_demand, :default_stock, :enable_reset
|
||||
attributes :id, :hub_id, :variant_id, :sku, :price, :count_on_hand, :on_demand, :default_stock, :resettable
|
||||
end
|
||||
|
||||
@@ -15,6 +15,6 @@
|
||||
%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
|
||||
%input{name: 'variant-overrides-{{ variant.id }}-enable-reset', type: 'checkbox', ng: {model: 'variantOverrides[hub.id][variant.id].enable_reset'}, placeholder: '{{ variant.enable_reset }}', 'ofn-track-variant-override' => 'enable_reset'}
|
||||
%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
|
||||
%input{name: 'variant-overrides-{{ variant.id }}-default-stock', type: 'text', ng: {model: 'variantOverrides[hub.id][variant.id].default_stock'}, placeholder: '{{ variant.default_stock ? variant.default_stock : "Default stock"}}', 'ofn-track-variant-override' => 'default_stock'}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20151126235409) do
|
||||
ActiveRecord::Schema.define(:version => 20151128185900) do
|
||||
|
||||
create_table "account_invoices", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
@@ -1162,7 +1162,7 @@ ActiveRecord::Schema.define(:version => 20151126235409) do
|
||||
t.string "sku"
|
||||
t.boolean "on_demand"
|
||||
t.integer "default_stock"
|
||||
t.boolean "enable_reset"
|
||||
t.boolean "resettable"
|
||||
end
|
||||
|
||||
add_index "variant_overrides", ["variant_id", "hub_id"], :name => "index_variant_overrides_on_variant_id_and_hub_id"
|
||||
|
||||
@@ -6,8 +6,8 @@ module Admin
|
||||
let!(:hub_owner) { create :user, enterprise_limit: 2 }
|
||||
let!(:v1) { create(:variant) }
|
||||
let!(:v2) { create(:variant) }
|
||||
let!(:vo1) { create(:variant_override, hub: hub, variant: v1, price: "6.0", count_on_hand: 5, default_stock: 7, enable_reset: true) }
|
||||
let!(:vo2) { create(:variant_override, hub: hub, variant: v2, price: "6.0", count_on_hand: 2, default_stock: 1, enable_reset: false) }
|
||||
let!(:vo1) { create(:variant_override, hub: hub, variant: v1, price: "6.0", count_on_hand: 5, default_stock: 7, resettable: true) }
|
||||
let!(:vo2) { create(:variant_override, hub: hub, variant: v2, price: "6.0", count_on_hand: 2, default_stock: 1, resettable: false) }
|
||||
|
||||
before do
|
||||
controller.stub spree_current_user: hub_owner
|
||||
|
||||
@@ -95,7 +95,7 @@ FactoryGirl.define do
|
||||
price 77.77
|
||||
count_on_hand 11111
|
||||
default_stock 2000
|
||||
enable_reset false
|
||||
resettable false
|
||||
end
|
||||
|
||||
factory :enterprise, :class => Enterprise do
|
||||
|
||||
@@ -181,9 +181,11 @@ 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, enable_reset: true) }
|
||||
let!(:vo) { create(:variant_override, variant: variant, hub: hub, price: 77.77, count_on_hand: 11111, default_stock: 1000, resettable: true) }
|
||||
let!(:vo_no_auth) { create(:variant_override, variant: variant, hub: hub3, 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) }
|
||||
let!(:vo_no_reset) { create(:variant_override, variant: variant2, hub: hub, price: 3.99, count_on_hand: 40, default_stock: 100, resettable: false) }
|
||||
before do
|
||||
visit '/admin/variant_overrides'
|
||||
select2_select hub.name, from: 'hub_id'
|
||||
@@ -211,12 +213,12 @@ feature %q{
|
||||
vo.count_on_hand.should == 8888
|
||||
end
|
||||
|
||||
# This fails for me and can't find where this automatic deletion is implemented?
|
||||
# Any new fields added to the VO model need to be added to this test
|
||||
it "deletes overrides when values are cleared" do
|
||||
fill_in "variant-overrides-#{variant.id}-price", with: ''
|
||||
fill_in "variant-overrides-#{variant.id}-count-on-hand", with: ''
|
||||
fill_in "variant-overrides-#{variant.id}-default-stock", with: ''
|
||||
page.uncheck "variant-overrides-#{variant.id}-enable-reset"
|
||||
page.uncheck "variant-overrides-#{variant.id}-resettable"
|
||||
page.should have_content "Changes to one override remain unsaved."
|
||||
|
||||
expect do
|
||||
@@ -235,6 +237,14 @@ feature %q{
|
||||
vo.count_on_hand.should == 1000
|
||||
end
|
||||
|
||||
it "doesn't reset stock levels if the behaviour is disabled" do
|
||||
click_button 'Reset Stock to Defaults'
|
||||
vo_no_reset.reload
|
||||
page.should have_input "variant-overrides-#{variant2.id}-count-on-hand", with: '40', placeholder: '12'
|
||||
vo_no_reset.count_on_hand.should == 40
|
||||
end
|
||||
|
||||
|
||||
it "prompts to save changes before reset if any are pending" do
|
||||
fill_in "variant-overrides-#{variant.id}-price", with: '200'
|
||||
click_button 'Reset Stock to Defaults'
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
describe "VariantOverrides service", ->
|
||||
VariantOverrides = $httpBackend = null
|
||||
variantOverrides = [
|
||||
{id: 1, hub_id: 10, variant_id: 100, price: 1, count_on_hand: 1, default_stock: ''}
|
||||
{id: 2, hub_id: 10, variant_id: 200, price: 2, count_on_hand: 2, default_stock: ''}
|
||||
{id: 3, hub_id: 20, variant_id: 300, price: 3, count_on_hand: 3, default_stock: ''}
|
||||
{id: 1, hub_id: 10, variant_id: 100, price: 1, count_on_hand: 1, default_stock: '', resettable: false}
|
||||
{id: 2, hub_id: 10, variant_id: 200, price: 2, count_on_hand: 2, default_stock: '', resettable: false}
|
||||
{id: 3, hub_id: 20, variant_id: 300, price: 3, count_on_hand: 3, default_stock: '', resettable: false}
|
||||
]
|
||||
|
||||
beforeEach ->
|
||||
@@ -19,10 +19,10 @@ describe "VariantOverrides service", ->
|
||||
it "indexes variant overrides by hub_id -> variant_id", ->
|
||||
expect(VariantOverrides.variantOverrides).toEqual
|
||||
10:
|
||||
100: {id: 1, hub_id: 10, variant_id: 100, price: 1, count_on_hand: 1, default_stock: ''}
|
||||
200: {id: 2, hub_id: 10, variant_id: 200, price: 2, count_on_hand: 2, default_stock: ''}
|
||||
100: {id: 1, hub_id: 10, variant_id: 100, price: 1, count_on_hand: 1, default_stock: '', resettable: false}
|
||||
200: {id: 2, hub_id: 10, variant_id: 200, price: 2, count_on_hand: 2, default_stock: '', resettable: false}
|
||||
20:
|
||||
300: {id: 3, hub_id: 20, variant_id: 300, price: 3, count_on_hand: 3, default_stock: ''}
|
||||
300: {id: 3, hub_id: 20, variant_id: 300, price: 3, count_on_hand: 3, default_stock: '', resettable: false}
|
||||
|
||||
it "ensures blank data available for some products", ->
|
||||
hubs = [{id: 10}, {id: 20}, {id: 30}]
|
||||
@@ -35,32 +35,32 @@ describe "VariantOverrides service", ->
|
||||
VariantOverrides.ensureDataFor hubs, products
|
||||
expect(VariantOverrides.variantOverrides).toEqual
|
||||
10:
|
||||
100: {id: 1, hub_id: 10, variant_id: 100, price: 1, count_on_hand: 1, default_stock: ''}
|
||||
200: {id: 2, hub_id: 10, variant_id: 200, price: 2, count_on_hand: 2, default_stock: ''}
|
||||
300: { hub_id: 10, variant_id: 300, price: '', count_on_hand: '', default_stock: ''}
|
||||
400: { hub_id: 10, variant_id: 400, price: '', count_on_hand: '', default_stock: ''}
|
||||
500: { hub_id: 10, variant_id: 500, price: '', count_on_hand: '', default_stock: ''}
|
||||
100: {id: 1, hub_id: 10, variant_id: 100, price: 1, count_on_hand: 1, default_stock: '', resettable: false}
|
||||
200: {id: 2, hub_id: 10, variant_id: 200, price: 2, count_on_hand: 2, default_stock: '', resettable: false}
|
||||
300: { hub_id: 10, variant_id: 300, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
400: { hub_id: 10, variant_id: 400, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
500: { hub_id: 10, variant_id: 500, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
20:
|
||||
100: { hub_id: 20, variant_id: 100, price: '', count_on_hand: '', default_stock: ''}
|
||||
200: { hub_id: 20, variant_id: 200, price: '', count_on_hand: '', default_stock: ''}
|
||||
300: {id: 3, hub_id: 20, variant_id: 300, price: 3, count_on_hand: 3, default_stock: ''}
|
||||
400: { hub_id: 20, variant_id: 400, price: '', count_on_hand: '', default_stock: ''}
|
||||
500: { hub_id: 20, variant_id: 500, price: '', count_on_hand: '', default_stock: ''}
|
||||
100: { hub_id: 20, variant_id: 100, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
200: { hub_id: 20, variant_id: 200, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
300: {id: 3, hub_id: 20, variant_id: 300, price: 3, count_on_hand: 3, default_stock: '', resettable: false}
|
||||
400: { hub_id: 20, variant_id: 400, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
500: { hub_id: 20, variant_id: 500, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
30:
|
||||
100: { hub_id: 30, variant_id: 100, price: '', count_on_hand: '', default_stock: ''}
|
||||
200: { hub_id: 30, variant_id: 200, price: '', count_on_hand: '', default_stock: ''}
|
||||
300: { hub_id: 30, variant_id: 300, price: '', count_on_hand: '', default_stock: ''}
|
||||
400: { hub_id: 30, variant_id: 400, price: '', count_on_hand: '', default_stock: ''}
|
||||
500: { hub_id: 30, variant_id: 500, price: '', count_on_hand: '', default_stock: ''}
|
||||
100: { hub_id: 30, variant_id: 100, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
200: { hub_id: 30, variant_id: 200, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
300: { hub_id: 30, variant_id: 300, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
400: { hub_id: 30, variant_id: 400, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
500: { hub_id: 30, variant_id: 500, price: '', count_on_hand: '', default_stock: '', resettable: false}
|
||||
|
||||
it "updates the IDs of variant overrides", ->
|
||||
VariantOverrides.variantOverrides[2] = {}
|
||||
VariantOverrides.variantOverrides[2][3] = {hub_id: 2, variant_id: 3, price: "4.0", count_on_hand: 5, default_stock: ''}
|
||||
VariantOverrides.variantOverrides[2][8] = {hub_id: 2, variant_id: 8, price: "9.0", count_on_hand: 10, default_stock: ''}
|
||||
VariantOverrides.variantOverrides[2][3] = {hub_id: 2, variant_id: 3, price: "4.0", count_on_hand: 5, default_stock: '', resettable: false}
|
||||
VariantOverrides.variantOverrides[2][8] = {hub_id: 2, variant_id: 8, price: "9.0", count_on_hand: 10, default_stock: '', resettable: false}
|
||||
|
||||
updatedVos = [
|
||||
{id: 1, hub_id: 2, variant_id: 3, price: "4.0", count_on_hand: 5, default_stock: ''}
|
||||
{id: 6, hub_id: 2, variant_id: 8, price: "9.0", count_on_hand: 10, default_stock: ''}
|
||||
{id: 1, hub_id: 2, variant_id: 3, price: "4.0", count_on_hand: 5, default_stock: '', resettable: false}
|
||||
{id: 6, hub_id: 2, variant_id: 8, price: "9.0", count_on_hand: 10, default_stock: '', resettable: false}
|
||||
]
|
||||
|
||||
VariantOverrides.updateIds updatedVos
|
||||
@@ -75,14 +75,14 @@ describe "VariantOverrides service", ->
|
||||
|
||||
it "updates the variant overrides on the page with new data", ->
|
||||
VariantOverrides.variantOverrides[1] =
|
||||
3: {id: 1, hub_id: 1, variant_id: 3, price: "4.0", count_on_hand: 5, default_stock: 3}
|
||||
8: {id: 2, hub_id: 1, variant_id: 8, price: "9.0", count_on_hand: 10, default_stock: ''}
|
||||
3: {id: 1, hub_id: 1, variant_id: 3, price: "4.0", count_on_hand: 5, default_stock: 3, resettable: true}
|
||||
8: {id: 2, hub_id: 1, variant_id: 8, price: "9.0", count_on_hand: 10, default_stock: '', resettable: false}
|
||||
# Updated count on hand to 3
|
||||
updatedVos = [
|
||||
{id: 1, hub_id: 1, variant_id: 3, price: "4.0", count_on_hand: 3, default_stock: 3}
|
||||
{id: 1, hub_id: 1, variant_id: 3, price: "4.0", count_on_hand: 3, default_stock: 3, resettable: true}
|
||||
]
|
||||
|
||||
VariantOverrides.updateData(updatedVos)
|
||||
expect(VariantOverrides.variantOverrides[1]).toEqual
|
||||
3: {id: 1, hub_id: 1, variant_id: 3, price: "4.0", count_on_hand: 3, default_stock: 3}
|
||||
8: {id: 2, hub_id: 1, variant_id: 8, price: "9.0", count_on_hand: 10, default_stock: ''}
|
||||
3: {id: 1, hub_id: 1, variant_id: 3, price: "4.0", count_on_hand: 3, default_stock: 3, resettable: true}
|
||||
8: {id: 2, hub_id: 1, variant_id: 8, price: "9.0", count_on_hand: 10, default_stock: '', resettable: false}
|
||||
|
||||
@@ -89,18 +89,18 @@ describe VariantOverride do
|
||||
|
||||
describe "resetting stock levels" do
|
||||
it "resets the on hand level to the value in the default_stock field" do
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20, enable_reset: true)
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20, resettable: true)
|
||||
vo.reset_stock!
|
||||
vo.reload.count_on_hand.should == 20
|
||||
end
|
||||
it "silently logs an error if the variant override doesn't have a default stock level" do
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock:nil, enable_reset: true)
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock:nil, resettable: true)
|
||||
Bugsnag.should_receive(:notify)
|
||||
vo.reset_stock!
|
||||
vo.reload.count_on_hand.should == 12
|
||||
end
|
||||
it "doesn't reset the level if the behaviour is disabled" do
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 10, enable_reset: false)
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 10, resettable: false)
|
||||
vo.reset_stock!
|
||||
vo.reload.count_on_hand.should == 12
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user