diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index f189e57fd0..7c29b41e70 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -15,7 +15,7 @@ module Api :terms_and_conditions_file_name, :terms_and_conditions_updated_at, :preferred_invoice_order_by_supplier, :preferred_product_low_stock_display, :visible, :hide_ofn_navigation, :white_label_logo, - :white_label_logo_link + :white_label_logo_link, :external_billing_id has_one :owner, serializer: Api::Admin::UserSerializer has_many :users, serializer: Api::Admin::UserSerializer diff --git a/config/locales/en.yml b/config/locales/en.yml index fe96d51f55..8234c52068 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3198,6 +3198,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using report_header_hub_code: Hub Code report_header_hub_id: Hub ID report_header_hub_business_number: "Hub Business Number" + report_header_hub_external_billing_id: "Hub External Billing Id" report_header_hub_legal_name: "Hub Legal Name" report_header_hub_contact_name: "Hub Contact Name" report_header_hub_email: "Hub Public Email" diff --git a/lib/reporting/reports/revenues_by_hub/base.rb b/lib/reporting/reports/revenues_by_hub/base.rb index e539c77fed..8b10386a6f 100644 --- a/lib/reporting/reports/revenues_by_hub/base.rb +++ b/lib/reporting/reports/revenues_by_hub/base.rb @@ -24,6 +24,7 @@ module Reporting hub: proc { |orders| distributor(orders).name }, hub_id: proc { |orders| distributor(orders).id }, hub_business_number: proc { |orders| distributor(orders).abn }, + hub_external_billing_id: proc { |orders| distributor(orders).external_billing_id }, hub_legal_name: proc { |orders| distributor(orders).business_address&.company }, hub_contact_name: proc { |orders| distributor(orders).contact_name }, hub_email: proc { |orders| distributor(orders).email_address }, diff --git a/spec/controllers/api/v0/enterprises_controller_spec.rb b/spec/controllers/api/v0/enterprises_controller_spec.rb index d0529f3eeb..8a74176ff0 100644 --- a/spec/controllers/api/v0/enterprises_controller_spec.rb +++ b/spec/controllers/api/v0/enterprises_controller_spec.rb @@ -7,6 +7,31 @@ RSpec.describe Api::V0::EnterprisesController, type: :controller do let(:enterprise) { create(:distributor_enterprise) } + context "as an admin user" do + let(:admin) { create(:user) } + let!(:enterprise) { create(:distributor_enterprise) } + + before do + allow(controller).to receive(:spree_current_user) { admin } + end + + describe "updating an enterprise" do + let(:enterprise_params) do + { + enterprise_id: enterprise.id, + enterprise: { external_billing_id: 'INV123456' } + } + end + + it "creates a visible=hidden enterprise" do + api_post :create, enterprise_params + expect(response.status).to eq 200 + + expect(enterprise.reload.external_billing_id).to eq('INV123456') + end + end + end + context "as an enterprise owner" do let(:enterprise_owner) { create(:user) } let!(:enterprise) { create(:distributor_enterprise, owner: enterprise_owner) } diff --git a/spec/serializers/api/admin/enterprise_serializer_spec.rb b/spec/serializers/api/admin/enterprise_serializer_spec.rb index 3f20145771..df2a86f802 100644 --- a/spec/serializers/api/admin/enterprise_serializer_spec.rb +++ b/spec/serializers/api/admin/enterprise_serializer_spec.rb @@ -73,4 +73,13 @@ RSpec.describe Api::Admin::EnterpriseSerializer do end end end + + context "when there is a external billing id" do + let(:enterprise) { create(:distributor_enterprise, external_billing_id: 'INV123456') } + + it "includes URLs of image versions" do + serializer = Api::Admin::EnterpriseSerializer.new(enterprise) + expect(serializer.as_json[:external_billing_id]).to eq('INV123456') + end + end end