mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Fix product lists not matching when saving changes to product unit+values fields
This commit is contained in:
@@ -259,7 +259,7 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
url: "/admin/products/bulk_update"
|
||||
data: productsToSubmit
|
||||
).success((data) ->
|
||||
if angular.toJson($scope.productsWithoutDerivedAttributes()) == angular.toJson(data)
|
||||
if angular.toJson($scope.productsWithoutDerivedAttributes($scope.products)) == angular.toJson($scope.productsWithoutDerivedAttributes(data))
|
||||
$scope.resetProducts data
|
||||
$scope.displaySuccess()
|
||||
else
|
||||
@@ -302,16 +302,17 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
variant.unit_description = match[3]
|
||||
|
||||
|
||||
$scope.productsWithoutDerivedAttributes = ->
|
||||
products = []
|
||||
if $scope.products
|
||||
products.push angular.extend {}, product for product in $scope.products
|
||||
for product in products
|
||||
$scope.productsWithoutDerivedAttributes = (products) ->
|
||||
products_filtered = []
|
||||
if products
|
||||
products_filtered.push angular.extend {}, product for product in products
|
||||
for product in products_filtered
|
||||
delete product.variant_unit_with_scale
|
||||
if product.variants
|
||||
for variant in product.variants
|
||||
delete variant.unit_value_with_description
|
||||
products
|
||||
delete variant.options_text
|
||||
products_filtered
|
||||
|
||||
$scope.setMessage = (model, text, style, timeout) ->
|
||||
model.text = text
|
||||
|
||||
@@ -17,7 +17,7 @@ class Spree::ProductSet < ModelSet
|
||||
end
|
||||
end
|
||||
|
||||
def update_variants_attributes(product,variants_attributes)
|
||||
def update_variants_attributes(product, variants_attributes)
|
||||
variants_attributes.each do |attributes|
|
||||
e = product.variants.detect { |e| e.id.to_s == attributes[:id].to_s && !e.id.nil? }
|
||||
e.update_attributes(attributes.except(:id)) if e.present?
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class MakeUnitDescriptionDefaultBlank < ActiveRecord::Migration
|
||||
def up
|
||||
execute "UPDATE spree_variants SET unit_description='' WHERE unit_description IS NULL"
|
||||
change_column :spree_variants, :unit_description, :string, default: ''
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :spree_variants, :unit_description, :string, default: nil
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20131128034556) do
|
||||
ActiveRecord::Schema.define(:version => 20140110040238) do
|
||||
|
||||
create_table "adjustment_metadata", :force => true do |t|
|
||||
t.integer "adjustment_id"
|
||||
@@ -890,7 +890,7 @@ ActiveRecord::Schema.define(:version => 20131128034556) do
|
||||
t.boolean "on_demand", :default => false
|
||||
t.string "cost_currency"
|
||||
t.float "unit_value"
|
||||
t.string "unit_description"
|
||||
t.string "unit_description", :default => ""
|
||||
end
|
||||
|
||||
add_index "spree_variants", ["product_id"], :name => "index_variants_on_product_id"
|
||||
|
||||
@@ -122,10 +122,10 @@ feature %q{
|
||||
|
||||
describe "products and inventory report" do
|
||||
it "shows products and inventory report" do
|
||||
product_1 = create(:simple_product, name: "Product Name")
|
||||
variant_1 = create(:variant, product: product_1, price: 100.0)
|
||||
variant_2 = create(:variant, product: product_1, price: 80.0)
|
||||
product_2 = create(:simple_product, name: "Product 2", price: 99.0)
|
||||
product_1 = create(:simple_product, name: "Product Name", variant_unit: nil)
|
||||
variant_1 = create(:variant, product: product_1, price: 100.0)
|
||||
variant_2 = create(:variant, product: product_1, price: 80.0)
|
||||
product_2 = create(:simple_product, name: "Product 2", price: 99.0, variant_unit: nil)
|
||||
variant_1.update_column(:count_on_hand, 10)
|
||||
variant_2.update_column(:count_on_hand, 20)
|
||||
product_2.master.update_column(:count_on_hand, 9)
|
||||
|
||||
@@ -661,10 +661,10 @@ describe "AdminBulkProductsCtrl", ->
|
||||
describe "fetching products without derived attributes", ->
|
||||
it "returns products without the variant_unit_with_scale field", ->
|
||||
scope.products = [{id: 123, variant_unit_with_scale: 'weight_1000'}]
|
||||
expect(scope.productsWithoutDerivedAttributes()).toEqual([{id: 123}])
|
||||
expect(scope.productsWithoutDerivedAttributes(scope.products)).toEqual([{id: 123}])
|
||||
|
||||
it "returns an empty array when products are undefined", ->
|
||||
expect(scope.productsWithoutDerivedAttributes()).toEqual([])
|
||||
expect(scope.productsWithoutDerivedAttributes(scope.products)).toEqual([])
|
||||
|
||||
it "does not alter original products", ->
|
||||
scope.products = [{id: 123, variant_unit_with_scale: 'weight_1000'}]
|
||||
@@ -674,7 +674,7 @@ describe "AdminBulkProductsCtrl", ->
|
||||
describe "updating variants", ->
|
||||
it "returns variants without the unit_value_with_description field", ->
|
||||
scope.products = [{id: 123, variants: [{id: 234, unit_value_with_description: 'foo'}]}]
|
||||
expect(scope.productsWithoutDerivedAttributes()).toEqual [
|
||||
expect(scope.productsWithoutDerivedAttributes(scope.products)).toEqual [
|
||||
{
|
||||
id: 123
|
||||
variants: [{id: 234}]
|
||||
|
||||
Reference in New Issue
Block a user