diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 0e60be9a14..407d0a71cd 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -6,6 +6,7 @@ class Enterprise < ActiveRecord::Base preference :shopfront_closed_message, :text, default: "" preference :shopfront_taxon_order, :string, default: "" preference :shopfront_order_cycle_order, :string, default: "orders_close_at" + preference :show_customer_names_to_suppliers, :boolean, default: false # This is hopefully a temporary measure, pending the arrival of multiple named inventories # for shops. We need this here to allow hubs to restrict visible variants to only those in diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index e3024fdc46..02eff79426 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -4,8 +4,8 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer :preferred_shopfront_message, :preferred_shopfront_closed_message, :preferred_shopfront_taxon_order, :preferred_shopfront_order_cycle_order, :preferred_product_selection_from_inventory_only, - :owner, :contact, :users, :tag_groups, :default_tag_group, - :require_login, :allow_guest_orders, :allow_order_changes, + :preferred_show_customer_names_to_suppliers, :owner, :contact, :users, :tag_groups, + :default_tag_group, :require_login, :allow_guest_orders, :allow_order_changes, :logo, :promo_image has_one :owner, serializer: Api::Admin::UserSerializer diff --git a/app/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index db7f31f10c..dc71d76d86 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -30,7 +30,7 @@ module PermittedAttributes :abn, :acn, :charges_sales_tax, :display_invoice_logo, :invoice_text, :preferred_product_selection_from_inventory_only, :preferred_shopfront_message, :preferred_shopfront_closed_message, :preferred_shopfront_taxon_order, - :preferred_shopfront_order_cycle_order + :preferred_shopfront_order_cycle_order, :preferred_show_customer_names_to_suppliers ] end end diff --git a/app/views/admin/enterprises/form/_shop_preferences.html.haml b/app/views/admin/enterprises/form/_shop_preferences.html.haml index f7062ab07a..d24bb2d291 100644 --- a/app/views/admin/enterprises/form/_shop_preferences.html.haml +++ b/app/views/admin/enterprises/form/_shop_preferences.html.haml @@ -89,3 +89,16 @@ .five.columns.omega = f.radio_button :enable_subscriptions, false = f.label :enable_subscriptions, t('.enable_subscriptions_false'), value: :false + +.row + .alpha.eleven.columns + .three.columns.alpha + %label= t '.customer_names_in_reports' + %div{'ofn-with-tip' => t('.customer_names_tip')} + %a= t 'admin.whats_this' + .three.columns + = radio_button :enterprise, :preferred_show_customer_names_to_suppliers, true + = label :enterprise_preferred_show_customer_names_to_suppliers, t('.customer_names_true'), value: :true + .five.columns.omega + = radio_button :enterprise, :preferred_show_customer_names_to_suppliers, false + = label :enterprise_preferred_show_customer_names_to_suppliers, t('.customer_names_false'), value: :false diff --git a/config/locales/en.yml b/config/locales/en.yml index 3726167337..a778d3eff7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -772,6 +772,10 @@ en: enable_subscriptions_tip: "Enable subscriptions functionality?" enable_subscriptions_false: "Disabled" enable_subscriptions_true: "Enabled" + customer_names_in_reports: "Customer Names in Reports" + customer_names_tip: "Enable your suppliers to see your customers names in reports" + customer_names_false: "Disabled" + customer_names_true: "Enabled" shopfront_message: "Shopfront Message" shopfront_message_placeholder: > An optional message to welcome customers and explain how to shop with you. If text is entered here it will be displayed in a home tab when customers first arrive at your shopfront. diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index 78678e03e2..9674061f87 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -133,6 +133,15 @@ describe Admin::EnterprisesController, type: :controller do expect(distributor.users).to_not include user end + it "updates enterprise preferences" do + allow(controller).to receive_messages spree_current_user: distributor_manager + update_params = { id: distributor, enterprise: { preferred_show_customer_names_to_suppliers: "1" } } + spree_post :update, update_params + + distributor.reload + expect(distributor.preferences[:show_customer_names_to_suppliers]).to eq true + end + describe "enterprise properties" do let(:producer) { create(:enterprise) } let!(:property) { create(:property, name: "A nice name") }