diff --git a/app/models/product_importer.rb b/app/models/product_importer.rb index 712705d1ac..509ecabf7e 100644 --- a/app/models/product_importer.rb +++ b/app/models/product_importer.rb @@ -448,11 +448,33 @@ class ProductImporter @already_created[entry.supplier_id] = {entry.name => product.id} end + def display_in_inventory(variant_override, is_new=false) + unless is_new + existing_item = InventoryItem.where( + variant_id: variant_override.variant_id, + enterprise_id: variant_override.hub_id). + first + + if existing_item + existing_item.assign_attributes(visible: true) + existing_item.save + return + end + end + + InventoryItem.new( + variant_id: variant_override.variant_id, + enterprise_id: variant_override.hub_id, + visible: true). + save + end + def save_new_inventory_item(entry) new_item = entry.product_object assign_defaults(new_item, entry) new_item.import_date = @import_time if new_item.valid? and new_item.save + display_in_inventory(new_item, true) @inventory_created += 1 @updated_ids.push new_item.id else @@ -465,6 +487,7 @@ class ProductImporter assign_defaults(existing_item, entry) existing_item.import_date = @import_time if existing_item.valid? and existing_item.save + display_in_inventory(existing_item) @inventory_updated += 1 @updated_ids.push existing_item.id else diff --git a/app/serializers/api/admin/variant_override_serializer.rb b/app/serializers/api/admin/variant_override_serializer.rb index 68b86818a1..c63e77c068 100644 --- a/app/serializers/api/admin/variant_override_serializer.rb +++ b/app/serializers/api/admin/variant_override_serializer.rb @@ -1,6 +1,6 @@ class Api::Admin::VariantOverrideSerializer < ActiveModel::Serializer attributes :id, :hub_id, :variant_id, :sku, :price, :count_on_hand, :on_demand, :default_stock, :resettable - attributes :tag_list, :tags + attributes :tag_list, :tags, :import_date def tag_list object.tag_list.join(",") diff --git a/app/views/admin/variant_overrides/_products.html.haml b/app/views/admin/variant_overrides/_products.html.haml index 711c52f6cf..73848c5b6c 100644 --- a/app/views/admin/variant_overrides/_products.html.haml +++ b/app/views/admin/variant_overrides/_products.html.haml @@ -13,6 +13,7 @@ %col.inheritance{ width: "5%", ng: { show: 'columns.inheritance.visible' } } %col.tags{ width: "30%", ng: { show: 'columns.tags.visible' } } %col.visibility{ width: "10%", ng: { show: 'columns.visibility.visible' } } + %col.visibility{ width: "10%", ng: { show: 'columns.import_date.visible' } } %thead %tr{ ng: { controller: "ColumnsCtrl" } } %th.producer{ ng: { show: 'columns.producer.visible' } }=t('admin.producer') @@ -25,6 +26,7 @@ %th.inheritance{ ng: { show: 'columns.inheritance.visible' } }=t('admin.variant_overrides.index.inherit?') %th.tags{ ng: { show: 'columns.tags.visible' } }=t('admin.tags') %th.visibility{ ng: { show: 'columns.visibility.visible' } }=t('admin.variant_overrides.index.hide') + %th.import_date{ ng: { show: 'columns.import_date.visible' } }=t('admin.variant_overrides.index.import_date') %tbody{ ng: {repeat: 'product in filteredProducts = (products | hubPermissions:hubPermissions:hub_id | inventoryProducts:hub_id:views | attrFilter:{producer_id:producerFilter} | filter:query) | limitTo:productLimit' } } = render 'admin/variant_overrides/products_product' = render 'admin/variant_overrides/products_variants' diff --git a/app/views/admin/variant_overrides/_products_product.html.haml b/app/views/admin/variant_overrides/_products_product.html.haml index 0427333790..5f101e91a6 100644 --- a/app/views/admin/variant_overrides/_products_product.html.haml +++ b/app/views/admin/variant_overrides/_products_product.html.haml @@ -9,3 +9,4 @@ %td.inheritance{ ng: { show: 'columns.inheritance.visible' } } %td.tags{ ng: { show: 'columns.tags.visible' } } %td.visibility{ ng: { show: 'columns.visibility.visible' } } + %td.import_date{ ng: { show: 'columns.import_date.visible' } } diff --git a/app/views/admin/variant_overrides/_products_variants.html.haml b/app/views/admin/variant_overrides/_products_variants.html.haml index 94fc309798..7c530a1cb2 100644 --- a/app/views/admin/variant_overrides/_products_variants.html.haml +++ b/app/views/admin/variant_overrides/_products_variants.html.haml @@ -23,3 +23,5 @@ %td.visibility{ ng: { show: 'columns.visibility.visible' } } %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"}} \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index f8fd877c86..760d14c28d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -485,6 +485,7 @@ en: inherit?: Inherit? add: Add hide: Hide + import_date: Imported select_a_shop: Select A Shop review_now: Review Now new_products_alert_message: There are %{new_product_count} new products available to add to your inventory. diff --git a/config/locales/en_GB.yml b/config/locales/en_GB.yml index 6d073525c8..baa68f8d6d 100644 --- a/config/locales/en_GB.yml +++ b/config/locales/en_GB.yml @@ -289,6 +289,7 @@ en_GB: inherit?: Inherit? add: Add hide: Hide + import_date: Imported select_a_shop: Select A Shop review_now: Review Now new_products_alert_message: There are %{new_product_count} new products available to add to your inventory. diff --git a/lib/open_food_network/column_preference_defaults.rb b/lib/open_food_network/column_preference_defaults.rb index 409d9fe7bb..e45670869b 100644 --- a/lib/open_food_network/column_preference_defaults.rb +++ b/lib/open_food_network/column_preference_defaults.rb @@ -19,7 +19,8 @@ module OpenFoodNetwork reset: { name: I18n.t("#{node}.enable_reset?"), visible: false }, inheritance: { name: I18n.t("#{node}.inherit?"), visible: false }, tags: { name: I18n.t("admin.tags"), visible: false }, - visibility: { name: I18n.t("#{node}.hide"), visible: false } + visibility: { name: I18n.t("#{node}.hide"), visible: false }, + import_date: { name: I18n.t("#{node}.import_date"), visible: false } } end