Skip to content

Commit

Permalink
Merge pull request #12980 from pacodelaluna/add-external-billing-id-o…
Browse files Browse the repository at this point in the history
…n-enterprises

Add external billing id on enterprises
  • Loading branch information
RachL authored Jan 13, 2025
2 parents e2bc86f + 244e052 commit 92c4508
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/serializers/api/admin/enterprise_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EnterpriseSerializer < ActiveModel::Serializer
: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
Expand Down
2 changes: 1 addition & 1 deletion app/services/permitted_attributes/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def self.basic_permitted_attributes
:preferred_invoice_order_by_supplier,
:preferred_product_low_stock_display,
:hide_ofn_navigation, :white_label_logo, :white_label_logo_link,
:hide_groups_tab
:hide_groups_tab, :external_billing_id,
]
end
end
Expand Down
44 changes: 27 additions & 17 deletions app/views/admin/enterprises/form/_primary_details.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,8 @@
%label= t('.primary_producer')
= render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.primary_producer_tip')}
.five.columns.omega
= f.check_box :is_primary_producer, data: { action: "change->primary-details#primaryProducerChanged" }
= f.check_box :is_primary_producer, data: { action: "change->primary-details#primaryProducerChanged" }
= f.label :is_primary_producer, t('.producer')
- if spree_current_user.admin?
.row
.three.columns.alpha
= f.label :sells, t('.sells')
= render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')}
.two.columns
= f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
= f.label :sells, t('.none'), value: "none"
.two.columns
= f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
= f.label :sells, t('.own'), value: "own"
.four.columns.omega
= f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
= f.label :sells, t('.any'), value: "any"
%span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } }
= render partial: "components/admin_spinner"
.row
.three.columns.alpha
%label= t('.visible_in_search')
Expand All @@ -49,3 +33,29 @@
= f.label :visible, t('.hidden'), value: 'hidden'

= render partial: 'admin/enterprises/form/permalink'

- if spree_current_user.admin?
.row
%fieldset.alpha.no-border-bottom
%legend= t('.admin_only_legend')
.row
.three.columns.alpha
= f.label :sells, t('.sells')
= render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')}
.two.columns
= f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
= f.label :sells, t('.none'), value: "none"
.two.columns
= f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
= f.label :sells, t('.own'), value: "own"
.four.columns.omega
= f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
= f.label :sells, t('.any'), value: "any"
%span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } }
= render partial: "components/admin_spinner"
.row
.three.columns.alpha
= f.label :external_billing_id, t('.external_billing_id')
= render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.external_billing_id_tip')}
.four.columns
= f.text_field :external_billing_id, { placeholder: t('.external_billing_id_placeholder') }
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1284,11 +1284,15 @@ en:
own: Own
sells: Sells
sells_tip: "None - enterprise does not sell to customers directly.<br />Own - Enterprise sells own products to customers.<br />Any - Enterprise can sell own or other enterprises products.<br />"
external_billing_id: External Billing ID
external_billing_id_placeholder: eg. INV-2024-123456
external_billing_id_tip: "This is the ID used by the external billing system to identify this enterprise."
visible_in_search: Visible in search?
visible_in_search_tip: "Shops can be <br />1. publicly visible, appearing on the OFN map and listings. <br />2. Hidden on maps and listings but referenced by other shops and linked in their profile. <br />3. Completely hidden."
visible: Public
not_visible: Hidden
hidden: Hide all references
admin_only_legend: Admin only
properties:
legend: "Properties"
permalink:
Expand Down Expand Up @@ -3193,6 +3197,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"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddExternalBillingIdOnEnterprises < ActiveRecord::Migration[7.0]
def change
add_column :enterprises, :external_billing_id, :string, limit: 128
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_11_12_230401) do
ActiveRecord::Schema[7.0].define(version: 2024_11_13_185651) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
Expand Down Expand Up @@ -229,6 +229,7 @@
t.boolean "hide_ofn_navigation", default: false, null: false
t.text "white_label_logo_link"
t.boolean "hide_groups_tab", default: false
t.string "external_billing_id", limit: 128
t.index ["address_id"], name: "index_enterprises_on_address_id"
t.index ["is_primary_producer", "sells"], name: "index_enterprises_on_is_primary_producer_and_sells"
t.index ["name"], name: "index_enterprises_on_name", unique: true
Expand Down
1 change: 1 addition & 0 deletions lib/reporting/reports/revenues_by_hub/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def columns # rubocop:disable Metrics/AbcSize
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 },
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/admin/enterprises_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,16 @@
distributor.reload
expect(distributor.users).to include user
end

it "allows 'external_billing_id' to be changed" do
allow(controller).to receive_messages spree_current_user: admin_user
enterprise_params =
{ id: profile_enterprise, enterprise: { external_billing_id: 'INV123456' } }

spree_put :update, enterprise_params
profile_enterprise.reload
expect(profile_enterprise.external_billing_id).to eq 'INV123456'
end
end

context "geocoding" do
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/api/v0/enterprises_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@

let(:enterprise) { create(:distributor_enterprise) }

context "as an admin user" do
let(:admin) { create(:admin_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
{
external_billing_id: 'INV123456'
}
end

it "changes the external_billing_id field" do
api_put :update, id: enterprise.id, enterprise: 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) }
Expand Down
3 changes: 2 additions & 1 deletion spec/serializers/api/admin/enterprise_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
RSpec.describe Api::Admin::EnterpriseSerializer do
include FileHelper

let(:enterprise) { create(:distributor_enterprise) }
let(:enterprise) { create(:distributor_enterprise, external_billing_id: 'INV123456') }
it "serializes an enterprise" do
serializer = Api::Admin::EnterpriseSerializer.new enterprise
expect(serializer.to_json).to match enterprise.name
expect(serializer.as_json[:external_billing_id]).to eq('INV123456')
end

context "for logo" do
Expand Down
8 changes: 6 additions & 2 deletions spec/system/admin/reports/revenues_by_hub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
tax_rate_name: "Tax 1"
)
end
let(:distributor1) { create(:enterprise, name: "Hub 1", owner:) }
let(:distributor1) { create(:enterprise, name: "Hub 1", owner:, external_billing_id: 'INV1234') }
let(:distributor2) { create(:enterprise, name: "Hub 2", owner:) }
let(:distributor3) { create(:enterprise, name: "Hub 3", owner:) }
let(:distributor3) { create(:enterprise, name: "Hub 3", owner:, external_billing_id: 'INV4321') }
let(:owner) { create(:user, email: '[email protected]') }
let(:order_cycle) { create(:simple_order_cycle) }
let(:product) { create(:product) }
Expand All @@ -64,6 +64,7 @@
"Hub",
"Hub ID",
"Hub Business Number",
"Hub External Billing Id",
"Hub Legal Name",
"Hub Contact Name",
"Hub Public Email",
Expand All @@ -86,6 +87,7 @@
"Hub 1",
order.distributor.id,
"none",
"INV1234",
"none",
"none",
"none",
Expand All @@ -110,6 +112,7 @@
"none",
"none",
"none",
"none",
"[email protected]",
"none",
"10 Lovely Street",
Expand All @@ -128,6 +131,7 @@
"Hub 3",
order_with_voucher_tax_excluded.distributor.id,
"none",
"INV4321",
"none",
"none",
"none",
Expand Down

0 comments on commit 92c4508

Please sign in to comment.