Remove concept of master variant

from old bulk product screen. Hmm I just realised we're deleting that screen soon anyway.

But this helps clean up the spec before I refactor it further.
This commit is contained in:
David Cook
2023-10-17 16:46:14 +11:00
parent be6481dac3
commit 224b6f514b
4 changed files with 2 additions and 96 deletions

View File

@@ -248,7 +248,6 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
else
product.variant_unit = product.variant_unit_scale = null
$scope.packVariant product, product.master if product.master
if product.variants
for id, variant of product.variants
@@ -299,7 +298,6 @@ filterSubmitProducts = (productsToFilter) ->
if product.hasOwnProperty("id")
filteredProduct = {id: product.id}
filteredVariants = []
filteredMaster = null
hasUpdatableProperty = false
if product.hasOwnProperty("variants")
@@ -309,16 +307,6 @@ filterSubmitProducts = (productsToFilter) ->
variantHasUpdatableProperty = result.hasUpdatableProperty
filteredVariants.push filteredVariant if variantHasUpdatableProperty
if product.master?.hasOwnProperty("unit_value")
filteredMaster ?= { id: product.master.id }
filteredMaster.unit_value = product.master.unit_value
if product.master?.hasOwnProperty("unit_description")
filteredMaster ?= { id: product.master.id }
filteredMaster.unit_description = product.master.unit_description
if product.master?.hasOwnProperty("display_as")
filteredMaster ?= { id: product.master.id }
filteredMaster.display_as = product.master.display_as
if product.hasOwnProperty("sku")
filteredProduct.sku = product.sku
hasUpdatableProperty = true
@@ -350,9 +338,6 @@ filterSubmitProducts = (productsToFilter) ->
if product.hasOwnProperty("inherits_properties")
filteredProduct.inherits_properties = product.inherits_properties
hasUpdatableProperty = true
if filteredMaster?
filteredProduct.master_attributes = filteredMaster
hasUpdatableProperty = true
if filteredVariants.length > 0 # Note that the name of the property changes to enable mass assignment of variants attributes with rails
filteredProduct.variants_attributes = filteredVariants
hasUpdatableProperty = true

View File

@@ -59,12 +59,11 @@ module Sets
ExchangeVariantDeleter.new.delete(product) if product.saved_change_to_supplier_id?
update_product_variants(product, attributes) &&
update_product_master(product, attributes)
update_product_variants(product, attributes)
end
def update_product_only_attributes(product, attributes)
variant_related_attrs = [:id, :variants_attributes, :master_attributes]
variant_related_attrs = [:id, :variants_attributes]
product_related_attrs = attributes.except(*variant_related_attrs)
return true if product_related_attrs.blank?
@@ -94,12 +93,6 @@ module Sets
update_variants_attributes(product, attributes[:variants_attributes])
end
def update_product_master(product, attributes)
return true unless attributes[:master_attributes]
create_or_update_variant(product, attributes[:master_attributes])
end
def update_variants_attributes(product, variants_attributes)
variants_attributes.each do |attributes|
create_or_update_variant(product, attributes)

View File

@@ -195,10 +195,6 @@ describe "filtering products for submission to database", ->
producer_id: 5
group_buy: null
group_buy_unit_size: null
master:
id: 2
unit_value: 250
unit_description: "foo"
variants: [
id: 1
on_hand: 2
@@ -221,10 +217,6 @@ describe "filtering products for submission to database", ->
variant_unit: 'volume'
variant_unit_scale: 1
variant_unit_name: 'loaf'
master_attributes:
id: 2
unit_value: 250
unit_description: "foo"
variants_attributes: [
id: 1
on_hand: 2
@@ -558,17 +550,6 @@ describe "AdminProductEditCtrl", ->
variant_unit_scale: null
variant_unit_with_scale: 'items'
it "packs the master variant", ->
spyOn $scope, "packVariant"
testVariant = {id: 1}
testProduct =
id: 1
master: testVariant
$scope.packProduct(testProduct)
expect($scope.packVariant).toHaveBeenCalledWith(testProduct, testVariant)
it "packs each variant", ->
spyOn $scope, "packVariant"
testVariant = {id: 1}
@@ -986,10 +967,6 @@ describe "AdminProductEditCtrl", ->
producer_id: 5
group_buy: null
group_buy_unit_size: null
master:
id: 2
unit_value: 250
unit_description: "foo"
describe 'product has variant', ->
it 'should load the edit product variant page', ->

View File

@@ -138,55 +138,6 @@ describe Sets::ProductSet do
end
end
end
context 'when :master_attributes is passed' do
let(:master_attributes) { { sku: '123' } }
before do
collection_hash[0][:master_attributes] = master_attributes
end
context 'and the variant does exist' do
let!(:variant) { create(:variant, product:) }
before { master_attributes[:id] = variant.id }
it 'updates the attributes of the master variant' do
product_set.save
expect(variant.reload.sku).to eq('123')
end
end
context 'and the variant does not exist' do
context 'and attributes provided are valid' do
let(:master_attributes) do
attributes_for(:variant).merge(sku: '123')
end
it 'creates it with the specified attributes' do
number_of_variants = Spree::Variant.all.size
product_set.save
expect(Spree::Variant.last.sku).to eq('123')
expect(Spree::Variant.all.size).to eq number_of_variants + 1
end
end
context 'and attributes provided are not valid' do
let(:master_attributes) do
# unit_value nil makes the variant invalid
# on_hand with a value would make on_hand be updated and fail with exception
attributes_for(:variant).merge(unit_value: nil, on_hand: 1, sku: '321')
end
it 'does not create variant and notifies bugsnag still raising the exception' do
number_of_variants = Spree::Variant.all.size
expect(product_set.save).to eq(false)
expect(Spree::Variant.all.size).to eq number_of_variants
expect(Spree::Variant.last.sku).not_to eq('321')
end
end
end
end
end
end