mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Convert all calls to variant.count_on_hand to variant.on_hand
This commit is contained in:
@@ -62,12 +62,12 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, $modal, $roo
|
||||
|
||||
for li in @line_items when li.quantity > 0
|
||||
if stockLevels[li.variant.id]?
|
||||
li.variant.count_on_hand = stockLevels[li.variant.id].on_hand
|
||||
if li.quantity > li.variant.count_on_hand
|
||||
li.quantity = li.variant.count_on_hand
|
||||
li.variant.on_hand = stockLevels[li.variant.id].on_hand
|
||||
if li.quantity > li.variant.on_hand
|
||||
li.quantity = li.variant.on_hand
|
||||
scope.variants.push li.variant
|
||||
if li.variant.count_on_hand == 0 && li.max_quantity > li.variant.count_on_hand
|
||||
li.max_quantity = li.variant.count_on_hand
|
||||
if li.variant.on_hand == 0 && li.max_quantity > li.variant.on_hand
|
||||
li.max_quantity = li.variant.on_hand
|
||||
scope.variants.push(li.variant) unless li.variant in scope.variants
|
||||
|
||||
if scope.variants.length > 0
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
%p{'ng-repeat' => "v in variants"}
|
||||
%em {{ v.name_to_display }} - {{ v.unit_to_display }}
|
||||
%span{'ng-if' => "v.count_on_hand == 0"}
|
||||
%span{'ng-if' => "v.on_hand == 0"}
|
||||
{{ 'js.out_of_stock.now_out_of_stock' | t }}
|
||||
%span{'ng-if' => "v.count_on_hand > 0"}
|
||||
{{ 'js.out_of_stock.only_n_remainging' | t:{ num: v.count_on_hand } }}
|
||||
%span{'ng-if' => "v.on_hand > 0"}
|
||||
{{ 'js.out_of_stock.only_n_remainging' | t:{ num: v.on_hand } }}
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
placeholder: "0",
|
||||
"ofn-disable-scroll" => true,
|
||||
"ng-model" => "variant.line_item.quantity",
|
||||
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.count_on_hand }}",
|
||||
"ng-disabled" => "!variant.on_demand && variant.count_on_hand == 0",
|
||||
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.on_hand }}",
|
||||
"ng-disabled" => "!variant.on_demand && variant.on_hand == 0",
|
||||
name: "variants[{{::variant.id}}]", id: "variants_{{::variant.id}}"}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"ng-model" => "variant.line_item.quantity",
|
||||
placeholder: "{{::'shop_variant_quantity_min' | t}}",
|
||||
"ofn-disable-scroll" => true,
|
||||
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.count_on_hand }}",
|
||||
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.on_hand }}",
|
||||
name: "variants[{{::variant.id}}]", id: "variants_{{::variant.id}}"}
|
||||
%span.bulk-input
|
||||
%input.bulk.second{type: :number,
|
||||
|
||||
@@ -214,7 +214,7 @@ module ProductImport
|
||||
object.assign_attributes(attribute => setting['value'])
|
||||
when 'overwrite_empty'
|
||||
if object.public_send(attribute).blank? ||
|
||||
((attribute == 'on_hand' || attribute == 'count_on_hand') &&
|
||||
((attribute == 'on_hand') &&
|
||||
entry.on_hand_nil)
|
||||
|
||||
object.assign_attributes(attribute => setting['value'])
|
||||
|
||||
@@ -372,7 +372,6 @@ module ProductImport
|
||||
return if entry.on_hand.present?
|
||||
|
||||
object.on_hand = 0 if object.respond_to?(:on_hand)
|
||||
object.count_on_hand = 0 if object.respond_to?(:count_on_hand)
|
||||
entry.on_hand_nil = true
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ module ProductImport
|
||||
|
||||
return 0 if enterprise_ids.blank?
|
||||
|
||||
reset_variants_count_on_hand(enterprise_variants_relation)
|
||||
reset_variants_on_hand(enterprise_variants_relation)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -29,17 +29,17 @@ module ProductImport
|
||||
relation.where('spree_variants.id NOT IN (?)', excluded_items_ids)
|
||||
end
|
||||
|
||||
def reset_variants_count_on_hand(variants)
|
||||
def reset_variants_on_hand(variants)
|
||||
updated_records_count = 0
|
||||
variants.each do |variant|
|
||||
updated_records_count += 1 if reset_variant_count_on_hand(variant)
|
||||
updated_records_count += 1 if reset_variant_on_hand(variant)
|
||||
end
|
||||
updated_records_count
|
||||
end
|
||||
|
||||
def reset_variant_count_on_hand(variant)
|
||||
variant.count_on_hand = 0
|
||||
variant.count_on_hand.zero?
|
||||
def reset_variant_on_hand(variant)
|
||||
variant.on_hand = 0
|
||||
variant.on_hand.zero?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ module ProductImport
|
||||
:distributor_id, :name, :display_name, :sku, :unit_value,
|
||||
:unit_description, :variant_unit, :variant_unit_scale,
|
||||
:variant_unit_name, :display_as, :category, :primary_taxon_id,
|
||||
:price, :on_hand, :count_on_hand, :on_demand,
|
||||
:price, :on_hand, :on_demand,
|
||||
:tax_category_id, :shipping_category_id, :description,
|
||||
:import_date, :enterprise, :enterprise_id
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Api::VariantSerializer < ActiveModel::Serializer
|
||||
attributes :id, :is_master, :count_on_hand, :name_to_display, :unit_to_display, :unit_value
|
||||
attributes :id, :is_master, :on_hand, :name_to_display, :unit_to_display, :unit_value
|
||||
attributes :options_text, :on_demand, :price, :fees, :price_with_fees, :product_name
|
||||
attributes :tag_list
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class OrderFactory
|
||||
attrs[:line_items].each do |li|
|
||||
next unless variant = Spree::Variant.find_by_id(li[:variant_id])
|
||||
scoper.scope(variant)
|
||||
li[:quantity] = stock_limited_quantity(variant.count_on_hand, li[:quantity])
|
||||
li[:quantity] = stock_limited_quantity(variant.on_hand, li[:quantity])
|
||||
li[:price] = variant.price
|
||||
build_item_from(li)
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
%div.pad-top{ "infinite-scroll" => "incrementLimit()", "infinite-scroll-distance" => "1", "infinite-scroll-disabled" => 'filteredProducts.length <= limit' }
|
||||
%product.animate-repeat{"ng-controller" => "ProductNodeCtrl", "ng-repeat" => "product in visibleProducts track by product.id", "id" => "product-{{ product.id }}"}
|
||||
= render "shop/products/summary"
|
||||
%shop-variant{variant: 'variant', "ng-repeat" => "variant in product.variants | orderBy: ['name_to_display','unit_value'] track by variant.id", "id" => "variant-{{ variant.id }}", "ng-class" => "{'out-of-stock': !variant.on_demand && variant.count_on_hand == 0}"}
|
||||
%shop-variant{variant: 'variant', "ng-repeat" => "variant in product.variants | orderBy: ['name_to_display','unit_value'] track by variant.id", "id" => "variant-{{ variant.id }}", "ng-class" => "{'out-of-stock': !variant.on_demand && variant.on_hand == 0}"}
|
||||
|
||||
%product{"ng-show" => "Products.loading"}
|
||||
.row.summary
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</ul>
|
||||
<ul class='variant-data'>
|
||||
<li class='variant-sku'><strong><%= t('admin.sku') %>:</strong> {{variant.sku}}</li>
|
||||
<li class='variant-on_hand'><strong><%= t('on_hand') %>:</strong> {{variant.count_on_hand}}</li>
|
||||
<li class='variant-on_hand'><strong><%= t('on_hand') %>:</strong> {{variant.on_hand}}</li>
|
||||
</ul>
|
||||
|
||||
{{#if variant.option_values}}
|
||||
@@ -41,7 +41,7 @@
|
||||
</colgroup>
|
||||
<thead>
|
||||
<th><%= Spree.t(:location) %></th>
|
||||
<th><%= Spree.t(:count_on_hand) %></th>
|
||||
<th><%= Spree.t(:on_hand) %></th>
|
||||
<th><%= Spree.t(:quantity) %></th>
|
||||
<th class="actions"></th>
|
||||
</thead>
|
||||
@@ -53,7 +53,7 @@
|
||||
<td>Spree.t(:on_demand)</td>
|
||||
{{else}}
|
||||
<td>
|
||||
{{variant.count_on_hand}}
|
||||
{{variant.on_hand}}
|
||||
</td>
|
||||
{{/if}}
|
||||
<td>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# overriding spree/core/app/views/spree/admin/variants/search.rabl
|
||||
#
|
||||
collection @variants
|
||||
attributes :sku, :options_text, :in_stock?, :on_demand, :count_on_hand, :id, :cost_price
|
||||
attributes :sku, :options_text, :in_stock?, :on_demand, :on_hand, :id, :cost_price
|
||||
|
||||
node(:name) do |v|
|
||||
# TODO: when products must have a unit, full_name will always be present
|
||||
|
||||
@@ -63,8 +63,8 @@ describe CartController, type: :controller do
|
||||
let!(:line_item) { create(:line_item, order: order, variant: variant_in_the_order, quantity: 2, max_quantity: 3) }
|
||||
|
||||
before do
|
||||
variant_in_the_order.count_on_hand = 4
|
||||
variant_not_in_the_order.count_on_hand = 2
|
||||
variant_in_the_order.on_hand = 4
|
||||
variant_not_in_the_order.on_hand = 2
|
||||
order_cycle.exchanges.outgoing.first.variants = [variant_in_the_order, variant_not_in_the_order]
|
||||
order.order_cycle = order_cycle
|
||||
order.distributor = hub
|
||||
|
||||
@@ -22,7 +22,7 @@ module Spree
|
||||
it "applies variant overrides" do
|
||||
spree_get :search, q: 'Prod', distributor_id: d.id.to_s
|
||||
assigns(:variants).should == [v1]
|
||||
assigns(:variants).first.count_on_hand.should == 44
|
||||
assigns(:variants).first.on_hand.should == 44
|
||||
end
|
||||
|
||||
it "filters by order cycle" do
|
||||
|
||||
@@ -602,7 +602,7 @@ FactoryBot.modify do
|
||||
|
||||
after(:create) do |variant, evaluator|
|
||||
variant.on_demand = evaluator.on_demand
|
||||
variant.count_on_hand = evaluator.on_hand
|
||||
variant.on_hand = evaluator.on_hand
|
||||
variant.save
|
||||
end
|
||||
end
|
||||
|
||||
@@ -308,11 +308,11 @@ xfeature %q{
|
||||
product2.set_property 'Organic', 'NASAA 12345'
|
||||
product1.taxons = [taxon]
|
||||
product2.taxons = [taxon]
|
||||
variant1.count_on_hand = 10
|
||||
variant1.on_hand = 10
|
||||
variant1.update_column(:sku, "sku1")
|
||||
variant2.count_on_hand = 20
|
||||
variant2.on_hand = 20
|
||||
variant2.update_column(:sku, "sku2")
|
||||
variant3.count_on_hand = 9
|
||||
variant3.on_hand = 9
|
||||
variant3.update_column(:sku, "")
|
||||
variant1.option_values = [create(:option_value, :presentation => "Test")]
|
||||
variant2.option_values = [create(:option_value, :presentation => "Something")]
|
||||
|
||||
@@ -123,7 +123,7 @@ feature "shopping with variant overrides defined", js: true, retry: 3 do
|
||||
expect do
|
||||
expect do
|
||||
complete_checkout
|
||||
end.to change { product1_variant3.reload.count_on_hand }.by(0)
|
||||
end.to change { product1_variant3.reload.on_hand }.by(0)
|
||||
end.to change { product1_variant3_override.reload.count_on_hand }.by(-2)
|
||||
end
|
||||
|
||||
@@ -134,7 +134,7 @@ feature "shopping with variant overrides defined", js: true, retry: 3 do
|
||||
expect do
|
||||
expect do
|
||||
complete_checkout
|
||||
end.to change { product3_variant2.reload.count_on_hand }.by(0)
|
||||
end.to change { product3_variant2.reload.on_hand }.by(0)
|
||||
end.to change { product3_variant2_override.reload.count_on_hand }.by(-2)
|
||||
end
|
||||
|
||||
@@ -143,12 +143,12 @@ feature "shopping with variant overrides defined", js: true, retry: 3 do
|
||||
click_checkout
|
||||
expect do
|
||||
complete_checkout
|
||||
end.to change { product1_variant1.reload.count_on_hand }.by(-2)
|
||||
end.to change { product1_variant1.reload.on_hand }.by(-2)
|
||||
product1_variant1_override.reload.count_on_hand.should be_nil
|
||||
end
|
||||
|
||||
it "does not show out of stock flags on order confirmation page" do
|
||||
product1_variant3.count_on_hand = 0
|
||||
product1_variant3.on_hand = 0
|
||||
fill_in "variants[#{product1_variant3.id}]", with: "2"
|
||||
click_checkout
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ describe "VariantOverridesCtrl", ->
|
||||
beforeEach ->
|
||||
# Ideally, count_on_hand is blank when the variant is on demand. However, this rule is not
|
||||
# enforced.
|
||||
variant = {id: 2, on_demand: true, count_on_hand: 20, on_hand: "On demand"}
|
||||
variant = {id: 2, on_demand: true, on_hand: 20, on_hand: "On demand"}
|
||||
|
||||
it "clears count_on_hand when variant override uses producer stock settings", ->
|
||||
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
|
||||
@@ -162,7 +162,7 @@ describe "VariantOverridesCtrl", ->
|
||||
beforeEach ->
|
||||
# Ideally, count_on_hand is blank when the variant is on demand. However, this rule is not
|
||||
# enforced.
|
||||
variant = {id: 2, on_demand: true, count_on_hand: 20, on_hand: t("on_demand")}
|
||||
variant = {id: 2, on_demand: true, on_hand: 20, on_hand: t("on_demand")}
|
||||
|
||||
it "is 'On demand' when variant override uses producer stock settings", ->
|
||||
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
|
||||
@@ -183,7 +183,7 @@ describe "VariantOverridesCtrl", ->
|
||||
variant = null
|
||||
|
||||
beforeEach ->
|
||||
variant = {id: 2, on_demand: false, count_on_hand: 20, on_hand: 20}
|
||||
variant = {id: 2, on_demand: false, on_hand: 20, on_hand: 20}
|
||||
|
||||
it "is variant count on hand when variant override uses producer stock settings", ->
|
||||
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
|
||||
|
||||
@@ -183,7 +183,7 @@ describe "filtering products for submission to database", ->
|
||||
shipping_category_id: null
|
||||
created_at: null
|
||||
updated_at: null
|
||||
count_on_hand: 0
|
||||
on_hand: 0
|
||||
producer_id: 5
|
||||
|
||||
group_buy: null
|
||||
|
||||
@@ -145,11 +145,11 @@ describe 'Cart service', ->
|
||||
expect(li.max_quantity).toEqual 0
|
||||
|
||||
it "resets the count on hand available", ->
|
||||
li = {variant: {id: 1, count_on_hand: 10}, quantity: 5}
|
||||
li = {variant: {id: 1, on_hand: 10}, quantity: 5}
|
||||
Cart.line_items = [li]
|
||||
stockLevels = {1: {quantity: 0, max_quantity: 0, on_hand: 0}}
|
||||
Cart.compareAndNotifyStockLevels stockLevels
|
||||
expect(li.variant.count_on_hand).toEqual 0
|
||||
expect(li.variant.on_hand).toEqual 0
|
||||
|
||||
describe "when the quantity available is less than that requested", ->
|
||||
it "reduces the quantity in the cart", ->
|
||||
@@ -172,7 +172,7 @@ describe 'Cart service', ->
|
||||
Cart.line_items = [li]
|
||||
stockLevels = {1: {quantity: 5, on_hand: 6}}
|
||||
Cart.compareAndNotifyStockLevels stockLevels
|
||||
expect(li.variant.count_on_hand).toEqual 6
|
||||
expect(li.variant.on_hand).toEqual 6
|
||||
|
||||
describe "when the client-side quantity has been increased during the request", ->
|
||||
it "does not reset the quantity", ->
|
||||
|
||||
@@ -76,9 +76,9 @@ describe SubscriptionPlacementJob do
|
||||
|
||||
context "and insufficient stock exists to fulfil the order for some items" do
|
||||
before do
|
||||
variant1.update_attribute(:count_on_hand, 5)
|
||||
variant2.update_attribute(:count_on_hand, 2)
|
||||
variant3.update_attribute(:count_on_hand, 0)
|
||||
variant1.update_attribute(:on_hand, 5)
|
||||
variant2.update_attribute(:on_hand, 2)
|
||||
variant3.update_attribute(:on_hand, 0)
|
||||
end
|
||||
|
||||
xit "caps quantity at the stock level for stock-limited items, and reports the change" do
|
||||
@@ -98,9 +98,9 @@ describe SubscriptionPlacementJob do
|
||||
|
||||
context "and insufficient stock exists to fulfil the order for some items" do
|
||||
before do
|
||||
variant1.update_attribute(:count_on_hand, 5)
|
||||
variant2.update_attribute(:count_on_hand, 2)
|
||||
variant3.update_attribute(:count_on_hand, 0)
|
||||
variant1.update_attribute(:on_hand, 5)
|
||||
variant2.update_attribute(:on_hand, 2)
|
||||
variant3.update_attribute(:on_hand, 0)
|
||||
end
|
||||
|
||||
xit "sets quantity to 0 for unavailable items, and reports the change" do
|
||||
|
||||
@@ -50,7 +50,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
it "only available items" do
|
||||
variant.count_on_hand = 0
|
||||
variant.on_hand = 0
|
||||
report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3, variant4]) }
|
||||
report.table.count.should eq 3
|
||||
end
|
||||
|
||||
@@ -50,7 +50,7 @@ module OpenFoodNetwork
|
||||
|
||||
it "doesn't return products not in stock" do
|
||||
variant.update_attribute(:on_demand, false)
|
||||
variant.update_attribute(:count_on_hand, 0)
|
||||
variant.update_attribute(:on_hand, 0)
|
||||
pr.products_json.should_not include product.name
|
||||
end
|
||||
|
||||
|
||||
@@ -39,12 +39,12 @@ module OpenFoodNetwork
|
||||
it "returns the overridden stock level when one is present" do
|
||||
vo
|
||||
scoper.scope v
|
||||
v.count_on_hand.should == 2
|
||||
v.on_hand.should == 2
|
||||
end
|
||||
|
||||
it "returns the variant's stock level otherwise" do
|
||||
scoper.scope v
|
||||
v.count_on_hand.should == 1
|
||||
v.on_hand.should == 1
|
||||
end
|
||||
|
||||
describe "overriding stock on an on_demand variant" do
|
||||
@@ -131,7 +131,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
context "when variant out of stock" do
|
||||
before { v.count_on_hand = 0 }
|
||||
before { v.on_hand = 0 }
|
||||
|
||||
it "returns true if VO in stock" do
|
||||
scoper.scope v
|
||||
@@ -153,7 +153,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
it "returns false if variant out of stock" do
|
||||
v.count_on_hand = 0
|
||||
v.on_hand = 0
|
||||
scoper.scope v
|
||||
expect(v.in_stock?).to eq(false)
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ describe ProductImport::ProductsResetStrategy do
|
||||
let(:enterprise) { product.supplier }
|
||||
let(:variant) { product.variants.first }
|
||||
|
||||
before { variant.count_on_hand = 2 }
|
||||
before { variant.on_hand = 2 }
|
||||
|
||||
context 'when there are excluded_items_ids' do
|
||||
let(:excluded_items_ids) { [variant.id] }
|
||||
@@ -17,35 +17,35 @@ describe ProductImport::ProductsResetStrategy do
|
||||
context 'and supplier_ids is []' do
|
||||
let(:supplier_ids) { [] }
|
||||
|
||||
it 'does not reset the variant.count_on_hand' do
|
||||
it 'does not reset the variant.on_hand' do
|
||||
products_reset.reset(supplier_ids)
|
||||
expect(variant.reload.count_on_hand).to eq(2)
|
||||
expect(variant.reload.on_hand).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'and supplier_ids is nil' do
|
||||
let(:supplier_ids) { nil }
|
||||
|
||||
it 'does not reset the variant.count_on_hand' do
|
||||
it 'does not reset the variant.on_hand' do
|
||||
products_reset.reset(supplier_ids)
|
||||
expect(variant.reload.count_on_hand).to eq(2)
|
||||
expect(variant.reload.on_hand).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'and supplier_ids is set' do
|
||||
it 'does not update the count_on_hand of the excluded items' do
|
||||
it 'does not update the on_hand of the excluded items' do
|
||||
products_reset.reset(supplier_ids)
|
||||
expect(variant.reload.count_on_hand).to eq(2)
|
||||
expect(variant.reload.on_hand).to eq(2)
|
||||
end
|
||||
|
||||
it 'updates the count_on_hand of the non-excluded items' do
|
||||
it 'updates the on_hand of the non-excluded items' do
|
||||
non_excluded_variant = create(
|
||||
:variant,
|
||||
product: variant.product
|
||||
)
|
||||
non_excluded_variant.count_on_hand = 3
|
||||
non_excluded_variant.on_hand = 3
|
||||
products_reset.reset(supplier_ids)
|
||||
expect(non_excluded_variant.reload.count_on_hand).to eq(0)
|
||||
expect(non_excluded_variant.reload.on_hand).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -56,31 +56,31 @@ describe ProductImport::ProductsResetStrategy do
|
||||
context 'and supplier_ids is []' do
|
||||
let(:supplier_ids) { [] }
|
||||
|
||||
it 'does not reset the variant.count_on_hand' do
|
||||
it 'does not reset the variant.on_hand' do
|
||||
products_reset.reset(supplier_ids)
|
||||
expect(variant.reload.count_on_hand).to eq(2)
|
||||
expect(variant.reload.on_hand).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'and supplier_ids is nil' do
|
||||
let(:supplier_ids) { nil }
|
||||
|
||||
it 'does not reset the variant.count_on_hand' do
|
||||
it 'does not reset the variant.on_hand' do
|
||||
products_reset.reset(supplier_ids)
|
||||
expect(variant.reload.count_on_hand).to eq(2)
|
||||
expect(variant.reload.on_hand).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'and supplier_ids is not nil' do
|
||||
it 'sets all count_on_hand to 0' do
|
||||
it 'sets all on_hand to 0' do
|
||||
updated_records_count = products_reset.reset(supplier_ids)
|
||||
expect(variant.reload.count_on_hand).to eq(0)
|
||||
expect(variant.reload.on_hand).to eq(0)
|
||||
expect(updated_records_count).to eq(1)
|
||||
end
|
||||
|
||||
context 'and there is an unresetable variant' do
|
||||
before do
|
||||
variant.stock_items = [] # this makes variant.count_on_hand raise an error
|
||||
variant.stock_items = [] # this makes variant.on_hand raise an error
|
||||
end
|
||||
|
||||
it 'returns correct number of resetted variants' do
|
||||
@@ -96,24 +96,24 @@ describe ProductImport::ProductsResetStrategy do
|
||||
context 'and supplier_ids is []' do
|
||||
let(:supplier_ids) { [] }
|
||||
|
||||
it 'does not reset the variant.count_on_hand' do
|
||||
it 'does not reset the variant.on_hand' do
|
||||
products_reset.reset(supplier_ids)
|
||||
expect(variant.reload.count_on_hand).to eq(2)
|
||||
expect(variant.reload.on_hand).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'and supplier_ids is nil' do
|
||||
let(:supplier_ids) { nil }
|
||||
it 'does not reset the variant.count_on_hand' do
|
||||
it 'does not reset the variant.on_hand' do
|
||||
products_reset.reset(supplier_ids)
|
||||
expect(variant.reload.count_on_hand).to eq(2)
|
||||
expect(variant.reload.on_hand).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'and supplier_ids is nil' do
|
||||
it 'sets all count_on_hand to 0' do
|
||||
it 'sets all on_hand to 0' do
|
||||
products_reset.reset(supplier_ids)
|
||||
expect(variant.reload.count_on_hand).to eq(0)
|
||||
expect(variant.reload.on_hand).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -634,14 +634,14 @@ module Spree
|
||||
describe "stock filtering" do
|
||||
it "considers products that are on_demand as being in stock" do
|
||||
product = create(:simple_product, on_demand: true)
|
||||
product.master.update_attribute(:count_on_hand, 0)
|
||||
product.master.update_attribute(:on_hand, 0)
|
||||
product.has_stock?.should == true
|
||||
end
|
||||
|
||||
describe "finding products in stock for a particular distribution" do
|
||||
it "returns on-demand products" do
|
||||
p = create(:simple_product, on_demand: true)
|
||||
p.variants.first.update_attributes!(count_on_hand: 0, on_demand: true)
|
||||
p.variants.first.update_attributes!(on_hand: 0, on_demand: true)
|
||||
d = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, distributors: [d])
|
||||
oc.exchanges.outgoing.first.variants << p.variants.first
|
||||
@@ -652,7 +652,7 @@ module Spree
|
||||
it "returns products with in-stock variants" do
|
||||
p = create(:simple_product)
|
||||
v = create(:variant, product: p)
|
||||
v.update_attribute(:count_on_hand, 1)
|
||||
v.update_attribute(:on_hand, 1)
|
||||
d = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, distributors: [d])
|
||||
oc.exchanges.outgoing.first.variants << v
|
||||
@@ -663,7 +663,7 @@ module Spree
|
||||
it "returns products with on-demand variants" do
|
||||
p = create(:simple_product)
|
||||
v = create(:variant, product: p, on_demand: true)
|
||||
v.update_attribute(:count_on_hand, 0)
|
||||
v.update_attribute(:on_hand, 0)
|
||||
d = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, distributors: [d])
|
||||
oc.exchanges.outgoing.first.variants << v
|
||||
@@ -673,7 +673,7 @@ module Spree
|
||||
|
||||
it "does not return products that have stock not in the distribution" do
|
||||
p = create(:simple_product)
|
||||
p.master.update_attribute(:count_on_hand, 1)
|
||||
p.master.update_attribute(:on_hand, 1)
|
||||
d = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, distributors: [d])
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@ describe "Shop API", type: :request do
|
||||
before do
|
||||
set_order order
|
||||
|
||||
v61.update_attribute(:count_on_hand, 1)
|
||||
v61.update_attribute(:on_hand, 1)
|
||||
p6.delete
|
||||
v71.update_attribute(:count_on_hand, 1)
|
||||
v41.update_attribute(:count_on_hand, 1)
|
||||
v42.update_attribute(:count_on_hand, 0)
|
||||
v43.update_attribute(:count_on_hand, 0)
|
||||
v51.update_attribute(:count_on_hand, 1)
|
||||
v52.update_attribute(:count_on_hand, 0)
|
||||
v71.update_attribute(:count_on_hand, 1)
|
||||
v71.update_attribute(:on_hand, 1)
|
||||
v41.update_attribute(:on_hand, 1)
|
||||
v42.update_attribute(:on_hand, 0)
|
||||
v43.update_attribute(:on_hand, 0)
|
||||
v51.update_attribute(:on_hand, 1)
|
||||
v52.update_attribute(:on_hand, 0)
|
||||
v71.update_attribute(:on_hand, 1)
|
||||
v71.update_attribute(:deleted_at, Time.zone.now)
|
||||
exchange = Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id)
|
||||
exchange.update_attribute :pickup_time, "frogs"
|
||||
|
||||
@@ -10,7 +10,7 @@ describe Api::VariantSerializer do
|
||||
:id,
|
||||
:name_to_display,
|
||||
:is_master,
|
||||
:count_on_hand,
|
||||
:on_hand,
|
||||
:name_to_display,
|
||||
:unit_to_display,
|
||||
:unit_value,
|
||||
|
||||
@@ -55,7 +55,7 @@ describe OrderFactory do
|
||||
context "when requested quantity is greater than available stock" do
|
||||
context "when no override is present" do
|
||||
before do
|
||||
variant1.update_attribute(:count_on_hand, 2)
|
||||
variant1.update_attribute(:on_hand, 2)
|
||||
attrs[:line_items].first[:quantity] = 5
|
||||
end
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ describe OrderSyncer do
|
||||
let(:sli) { subscription.subscription_line_items.first }
|
||||
let(:variant) { sli.variant }
|
||||
|
||||
before { variant.update_attribute(:count_on_hand, 2) }
|
||||
before { variant.update_attribute(:on_hand, 2) }
|
||||
|
||||
context "when quantity is within available stock" do
|
||||
let(:params) { { subscription_line_items_attributes: [{ id: sli.id, quantity: 2}] } }
|
||||
@@ -327,7 +327,7 @@ describe OrderSyncer do
|
||||
let(:syncer) { OrderSyncer.new(subscription) }
|
||||
let(:changed_line_item) { order.line_items.find_by_variant_id(sli.variant_id) }
|
||||
|
||||
before { variant.update_attribute(:count_on_hand, 3) }
|
||||
before { variant.update_attribute(:on_hand, 3) }
|
||||
|
||||
context "when the changed line_item quantity matches the new quantity on the subscription line item" do
|
||||
before { changed_line_item.update_attributes(quantity: 3) }
|
||||
|
||||
@@ -12,8 +12,8 @@ describe VariantsStockLevels do
|
||||
let(:variant_stock_levels) { VariantsStockLevels.new }
|
||||
|
||||
before do
|
||||
variant_in_the_order.count_on_hand = 4
|
||||
variant_not_in_the_order.count_on_hand = 2
|
||||
variant_in_the_order.on_hand = 4
|
||||
variant_not_in_the_order.on_hand = 2
|
||||
order.reload
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ describe VariantsStockLevels do
|
||||
describe "encoding Infinity" do
|
||||
let!(:variant_in_the_order) { create(:variant, on_demand: true) }
|
||||
|
||||
before { variant_in_the_order.count_on_hand = 0 }
|
||||
before { variant_in_the_order.on_hand = 0 }
|
||||
|
||||
it "encodes Infinity as a large, finite integer" do
|
||||
expect(variant_stock_levels.call(order, [variant_in_the_order.id])).to eq(
|
||||
|
||||
Reference in New Issue
Block a user