mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Move tax_category dropdown in edit pages
This commit is contained in:
committed by
Maikel Linke
parent
b12c130e02
commit
a52516bcbf
@@ -7,6 +7,8 @@ module Spree
|
||||
class VariantsController < ::Admin::ResourceController
|
||||
belongs_to 'spree/product'
|
||||
|
||||
before_action :load_data, only: [:new, :edit]
|
||||
|
||||
def index
|
||||
@url_filters = ::ProductFilters.new.extract(request.query_parameters)
|
||||
end
|
||||
@@ -107,6 +109,12 @@ module Spree
|
||||
:include_out_of_stock
|
||||
).to_h.with_indifferent_access
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_data
|
||||
@tax_categories = TaxCategory.order(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,11 +43,6 @@
|
||||
= f.collection_select(:shipping_category_id, @shipping_categories, :id, :name, {}, { :class => 'select2' })
|
||||
= f.error_message_on :shipping_category
|
||||
|
||||
= f.field_container :tax_category do
|
||||
= f.label :tax_category_id, t(:tax_category)
|
||||
= f.collection_select(:tax_category_id, @tax_categories, :id, :name, { :include_blank => t(:none) }, { :class => 'select2' })
|
||||
= f.error_message_on :tax_category
|
||||
|
||||
.clear
|
||||
|
||||
%div
|
||||
|
||||
@@ -64,4 +64,8 @@
|
||||
- value = number_with_precision(@variant.send(field), precision: 2)
|
||||
= f.number_field field, value: value, class: 'fullwidth', step: 0.01
|
||||
|
||||
.field
|
||||
= f.label :tax_category_id, t(:tax_category)
|
||||
= f.collection_select(:tax_category_id, @tax_categories, :id, :name, { include_blank: t(:none) }, { class: 'select2 fullwidth' })
|
||||
|
||||
.clear
|
||||
|
||||
@@ -296,7 +296,6 @@ describe '
|
||||
visit spree.edit_admin_product_path product
|
||||
|
||||
select 'Permitted Supplier', from: 'product_supplier_id'
|
||||
select tax_category.name, from: 'product_tax_category_id'
|
||||
click_button 'Update'
|
||||
expect(flash_message).to eq('Product "a product" has been successfully updated!')
|
||||
product.reload
|
||||
|
||||
@@ -290,53 +290,56 @@ describe '
|
||||
expect(variant.reload.deleted_at).not_to be_nil
|
||||
end
|
||||
|
||||
it "editing display name for a variant" do
|
||||
product = create(:simple_product)
|
||||
variant = product.variants.first
|
||||
describe "editing variant attributes" do
|
||||
let!(:variant) { create(:variant) }
|
||||
let(:product) { variant.product }
|
||||
let!(:tax_category) { create(:tax_category) }
|
||||
|
||||
# When I view the variant
|
||||
login_as_admin
|
||||
visit spree.admin_product_variants_path product
|
||||
page.find('table.index .icon-edit').click
|
||||
before do
|
||||
login_as_admin
|
||||
visit spree.edit_admin_product_variant_path product, variant
|
||||
end
|
||||
|
||||
# It should allow the display name to be changed
|
||||
expect(page).to have_field "variant_display_name"
|
||||
expect(page).to have_field "variant_display_as"
|
||||
it "editing display name for a variant" do
|
||||
# It should allow the display name to be changed
|
||||
expect(page).to have_field "variant_display_name"
|
||||
expect(page).to have_field "variant_display_as"
|
||||
|
||||
# When I update the fields and save the variant
|
||||
fill_in "variant_display_name", with: "Display Name"
|
||||
fill_in "variant_display_as", with: "Display As This"
|
||||
click_button 'Update'
|
||||
expect(page).to have_content %(Variant "#{product.name}" has been successfully updated!)
|
||||
# When I update the fields and save the variant
|
||||
fill_in "variant_display_name", with: "Display Name"
|
||||
fill_in "variant_display_as", with: "Display As This"
|
||||
click_button 'Update'
|
||||
expect(page).to have_content %(Variant "#{product.name}" has been successfully updated!)
|
||||
|
||||
# Then the displayed values should have been saved
|
||||
expect(variant.reload.display_name).to eq("Display Name")
|
||||
expect(variant.display_as).to eq("Display As This")
|
||||
end
|
||||
# Then the displayed values should have been saved
|
||||
expect(variant.reload.display_name).to eq("Display Name")
|
||||
expect(variant.display_as).to eq("Display As This")
|
||||
end
|
||||
|
||||
it "editing weight for a variant" do
|
||||
product = create(:simple_product)
|
||||
variant = product.variants.first
|
||||
it "editing weight for a variant" do
|
||||
# It should allow the weight to be changed
|
||||
expect(page).to have_field "unit_value_human"
|
||||
|
||||
# When I view the variant
|
||||
login_as_admin
|
||||
visit spree.admin_product_variants_path product
|
||||
# When I update the fields and save the variant with invalid value
|
||||
fill_in "unit_value_human", with: "1.234"
|
||||
click_button 'Update'
|
||||
expect(page).not_to have_content %(Variant "#{product.name}" has been successfully updated!)
|
||||
|
||||
page.find('table.index .icon-edit').click
|
||||
fill_in "unit_value_human", with: "1.23"
|
||||
click_button 'Update'
|
||||
expect(page).not_to have_content %(Variant "#{product.name}" has been successfully updated!)
|
||||
|
||||
# It should allow the weight to be changed
|
||||
expect(page).to have_field "unit_value_human"
|
||||
# Then the displayed values should have been saved
|
||||
expect(variant.reload.unit_value).to eq(1.23)
|
||||
end
|
||||
|
||||
# When I update the fields and save the variant with invalid value
|
||||
fill_in "unit_value_human", with: "1.234"
|
||||
click_button 'Update'
|
||||
expect(page).not_to have_content %(Variant "#{product.name}" has been successfully updated!)
|
||||
context "editing variant tax category" do
|
||||
it "editing variant tax category" do
|
||||
select2_select tax_category.name, from: 'variant_tax_category_id'
|
||||
click_button 'Update'
|
||||
|
||||
fill_in "unit_value_human", with: "1.23"
|
||||
click_button 'Update'
|
||||
expect(page).not_to have_content %(Variant "#{product.name}" has been successfully updated!)
|
||||
|
||||
# Then the displayed values should have been saved
|
||||
expect(variant.reload.unit_value).to eq(1.23)
|
||||
expect(variant.reload.tax_category).to eq tax_category
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user