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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fa91082
Add external_billing_id field on enterprises table
pacodelaluna Nov 13, 2024
2d34ea0
Add new field on enterprise admin form
pacodelaluna Nov 13, 2024
df50a93
Deal with translations
pacodelaluna Nov 16, 2024
c196acb
Handle the async action for entreprises sells field changes
pacodelaluna Nov 25, 2024
49b89d6
Move admin_only tab upper
pacodelaluna Nov 25, 2024
a16f5b2
Add unit tests for admin entreprises changes
pacodelaluna Nov 25, 2024
27fcf76
Add external_billing_id field on revenues_by_hub report
pacodelaluna Nov 28, 2024
ce7f041
Repair field placeholder translation
pacodelaluna Nov 28, 2024
d270dda
Repair specs
pacodelaluna Nov 28, 2024
dc07e5a
Put back permalink fields on primary details panel
pacodelaluna Dec 22, 2024
3d9793b
Fix spec
pacodelaluna Dec 22, 2024
77ba7e0
Add spinner
pacodelaluna Dec 23, 2024
7d37fcd
Use params value only if present
pacodelaluna Dec 26, 2024
0511fc2
Do explicit save in specs when switching tabs
pacodelaluna Dec 26, 2024
129ceac
Revert "Do explicit save in specs when switching tabs"
pacodelaluna Jan 5, 2025
a6990d3
Revert "Use params value only if present"
pacodelaluna Jan 5, 2025
905f535
Revert "Add spinner"
pacodelaluna Jan 5, 2025
980c510
Revert "Fix spec"
pacodelaluna Jan 5, 2025
47b3310
Revert "Put back permalink fields on primary details panel"
pacodelaluna Jan 5, 2025
ba7db00
Remove Admin Only tab logic
pacodelaluna Jan 5, 2025
3bcca1e
Isolate into an Admin Only section
pacodelaluna Jan 6, 2025
104a6f0
Improve specs
pacodelaluna Jan 8, 2025
a15874d
Merge branch 'master' into add-external-billing-id-on-enterprises
pacodelaluna Jan 8, 2025
33f7d8d
Fix specs
pacodelaluna Jan 8, 2025
363640c
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 @@ -3213,6 +3217,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
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
9 changes: 9 additions & 0 deletions spec/serializers/api/admin/enterprise_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,13 @@
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
Copy link
Member

Choose a reason for hiding this comment

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

Actually I think we don't really need an extra test for this, we could add the expectation to the first test in this file (because we don't need to test "when there is no billing id").
Would it be ok to change that? That would help avoid growing this file too much.

end
4 changes: 4 additions & 0 deletions spec/system/admin/reports/revenues_by_hub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -89,6 +90,7 @@
"none",
"none",
"none",
"none",
dacook marked this conversation as resolved.
Show resolved Hide resolved
"[email protected]",
"none",
"10 Lovely Street",
Expand All @@ -110,6 +112,7 @@
"none",
"none",
"none",
"none",
"[email protected]",
"none",
"10 Lovely Street",
Expand All @@ -131,6 +134,7 @@
"none",
"none",
"none",
"none",
"[email protected]",
"none",
"10 Lovely Street",
Expand Down
Loading