Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external billing id on enterprises #12980

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
772f1f8
Add external_billing_id field on enterprises table
pacodelaluna Nov 13, 2024
14334b0
Add new field on enterprise admin form
pacodelaluna Nov 13, 2024
30dfae7
Deal with translations
pacodelaluna Nov 16, 2024
6030d7e
Handle the async action for entreprises sells field changes
pacodelaluna Nov 25, 2024
57c237c
Move admin_only tab upper
pacodelaluna Nov 25, 2024
e378818
Add unit tests for admin entreprises changes
pacodelaluna Nov 25, 2024
6ae3c8b
Add external_billing_id field on revenues_by_hub report
pacodelaluna Nov 28, 2024
657df9e
Repair field placeholder translation
pacodelaluna Nov 28, 2024
3c7c02d
Repair specs
pacodelaluna Nov 28, 2024
9dc3649
Put back permalink fields on primary details panel
pacodelaluna Dec 22, 2024
d6faa23
Fix spec
pacodelaluna Dec 22, 2024
cd38e02
Add spinner
pacodelaluna Dec 23, 2024
0f77d1b
Use params value only if present
pacodelaluna Dec 26, 2024
0b0b6a0
Do explicit save in specs when switching tabs
pacodelaluna Dec 26, 2024
f9f5d0e
Revert "Do explicit save in specs when switching tabs"
pacodelaluna Jan 5, 2025
9cd3bbf
Revert "Use params value only if present"
pacodelaluna Jan 5, 2025
1e3f866
Revert "Add spinner"
pacodelaluna Jan 5, 2025
983e3e7
Revert "Fix spec"
pacodelaluna Jan 5, 2025
a007fda
Revert "Put back permalink fields on primary details panel"
pacodelaluna Jan 5, 2025
3ef5b41
Remove Admin Only tab logic
pacodelaluna Jan 5, 2025
e946b50
Isolate into an Admin Only section
pacodelaluna Jan 6, 2025
9c153c6
Improve specs
pacodelaluna Jan 8, 2025
96c7c82
Fix specs
pacodelaluna Jan 8, 2025
244e052
Re-instate check for external_billing_id
dacook Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put the limit at 128 chars as it seems enough, but it can be of course changed in case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I agree that there shouldn't be more than 128 chars in this field.
Scanning schema.rb, I see that most fields are set to 255 🤷 Probably it doesn't matter.

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@email.com') }
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",
dacook marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -110,6 +112,7 @@
"none",
"none",
"none",
"none",
"email@email.com",
"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
Loading