From 10f09066893be24fe874fa5aa14720c748853bca Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Mon, 28 Oct 2019 13:21:28 +0000 Subject: [PATCH 1/2] Remove obsolete view, this code is now in app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml --- ..._exchange_supplied_products_form.html.haml | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 app/views/admin/order_cycles/_exchange_supplied_products_form.html.haml diff --git a/app/views/admin/order_cycles/_exchange_supplied_products_form.html.haml b/app/views/admin/order_cycles/_exchange_supplied_products_form.html.haml deleted file mode 100644 index 22b563e107..0000000000 --- a/app/views/admin/order_cycles/_exchange_supplied_products_form.html.haml +++ /dev/null @@ -1,32 +0,0 @@ -/ TODO: Unify this with exchange_distributed_products_form -%td{:colspan => 4} - .exchange-select-all-variants - %label - = check_box_tag 'order_cycle_incoming_exchange_{{ $parent.$index }}_select_all_variants', 1, 1, 'ng-model' => 'exchange.select_all_variants', 'ng-change' => 'setExchangeVariants(exchange, suppliedVariants(exchange.enterprise_id), exchange.select_all_variants)', 'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_select_all_variants' - = t('admin.select_all') - - .exchange-products - -# No need to scope product list based on permissions, because if an incoming exchange is visible, - -# then all of the variants within it should be visible. May change in the future? - .exchange-product{'ng-repeat' => 'product in enterprises[exchange.enterprise_id].supplied_products'} - - .exchange-product-details - %label - = check_box_tag 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', 1, 1, 'ng-hide' => 'product.variants.length > 0', 'ng-model' => 'exchange.variants[product.master_id]', 'ofn-sync-distributions' => '{{ product.master_id }}', 'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', - 'ng-disabled' => 'product.variants.length > 0 || !order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' - %img{'ng-src' => '{{ product.image_url }}'} - {{ product.name }} - - -# When the master variant is in the order cycle but the product has variants, we want to - -# be able to remove the master variant, since it serves no purpose. Display a checkbox to do so. - .exchange-product-variant{'ng-show' => 'exchange.variants[product.master_id] && product.variants.length > 0'} - %label - = check_box_tag 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', 1, 1, 'ng-model' => 'exchange.variants[product.master_id]', 'ofn-sync-distributions' => '{{ product.master_id }}', 'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', - 'ng-disabled' => '!order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' - = t('admin.obsolete_master') - - .exchange-product-variant{'ng-repeat' => 'variant in product.variants'} - %label - = check_box_tag 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'ofn-sync-distributions' => '{{ variant.id }}', 'id' => 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', - 'ng-disabled' => '!order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0' - {{ variant.label }} From 75dfde2552526592d750cea0013a5a8d816976e3 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Mon, 28 Oct 2019 13:42:10 +0000 Subject: [PATCH 2/2] In the Edit OC page, the list of supplied products should only include checkboxes for normal variants: removed html to display product checkbox and also master variants Two rules we can use to make this more simple: all products have variants (at least what is called the standard variant) and master variants cannot be added to OCs --- .../exchange_supplied_products.html.haml | 20 ---------------- config/locales/en.yml | 1 - spec/features/admin/order_cycles_spec.rb | 24 ------------------- 3 files changed, 45 deletions(-) diff --git a/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml b/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml index 222718c160..10950258f9 100644 --- a/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml +++ b/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml @@ -13,31 +13,11 @@ -# No need to scope product list based on permissions, because if an incoming exchange is visible, -# then all of the variants within it should be visible. May change in the future? .exchange-product{'ng-repeat' => 'product in enterprises[exchange.enterprise_id].supplied_products'} - .exchange-product-details %label - %input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', - value: 1, - 'ng-hide' => 'product.variants.length > 0', - 'ng-model' => 'exchange.variants[product.master_id]', - 'ofn-sync-distributions' => '{{ product.master_id }}', - 'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', - 'ng-disabled' => 'product.variants.length > 0 || !order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' } %img{'ng-src' => '{{ product.image_url }}'} {{ product.name }} - -# When the master variant is in the order cycle but the product has variants, we want to - -# be able to remove the master variant, since it serves no purpose. Display a checkbox to do so. - .exchange-product-variant{'ng-show' => 'exchange.variants[product.master_id] && product.variants.length > 0'} - %label - %input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', - value: 1, - 'ng-model' => 'exchange.variants[product.master_id]', - 'ofn-sync-distributions' => '{{ product.master_id }}', - 'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', - 'ng-disabled' => '!order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' } - {{ 'admin.obsolete_master' | t }} - .exchange-product-variant{'ng-repeat' => 'variant in product.variants'} %label %input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', diff --git a/config/locales/en.yml b/config/locales/en.yml index 28c9f248d2..64ca6e1482 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -331,7 +331,6 @@ en: volume: Volume items: Items select_all: Select all - obsolete_master: Obsolete master # General form elements quick_search: Quick Search diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index ab981ba6ff..95074e18d1 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -594,30 +594,6 @@ feature ' expect(occ.name).to eq "COPY OF #{oc.name}" end - scenario "removing a master variant from an order cycle when further variants have been added" do - # Given a product with a variant, with its master variant included in the order cycle - # (this usually happens when a product is added to an order cycle, then variants are added - # to the product after the fact) - s = create(:supplier_enterprise) - p = create(:simple_product, supplier: s) - v = create(:variant, product: p) - d = create(:distributor_enterprise) - oc = create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master]) - exchange_ids = oc.exchanges.pluck :id - expect(ExchangeVariant.where(exchange_id: exchange_ids, variant_id: p.master.id)).not_to be_empty - - # When I go to the order cycle page and remove the obsolete master - quick_login_as_admin - visit edit_admin_order_cycle_path(oc) - within("table.exchanges tbody tr.supplier") { page.find('td.products').click } - page.find("#order_cycle_incoming_exchange_0_variants_#{p.master.id}").click # uncheck - click_button "Update" - - # Then the master variant should have been removed from all exchanges - expect(page).to have_content "Your order cycle has been updated." - expect(ExchangeVariant.where(exchange_id: exchange_ids, variant_id: p.master.id)).to be_empty - end - describe "ensuring that hubs in order cycles have valid shipping and payment methods" do context "when they don't" do let(:hub) { create(:distributor_enterprise) }