-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add reverse charge fields to address #6168
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
Merged
tvdeyen
merged 4 commits into
solidusio:main
from
gms-electronics:add-compliance-fields-to-address
Apr 28, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8c90ddd
Add email, vat_id and reverse_charge_status on address
JustShah 5e1bff9
Enable address API to support email, vat_id, and reverse_charge_status
JustShah 0963b8e
Add email, vat_id, and reverse_charge_status to admin address forms
JustShah f5eb41f
Provide backwards compatibility to Rails 7
JustShah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,31 @@ module Spree::Api | |
| end | ||
| end | ||
|
|
||
| context "when updating a default address with email, VAT-ID and reverse charge status" do | ||
| let(:user) { create(:user, spree_api_key: 'galleon') } | ||
| let(:changes) { | ||
| { name: "Hermione Granger", email: "[email protected]", vat_id: "AB1234567", | ||
| reverse_charge_status: "enabled", id: user.ship_address.id} | ||
| } | ||
| before do | ||
| # Create "Harry Potter" default shipping address | ||
| user.save_in_address_book(harry_address_attributes, true) | ||
| end | ||
|
|
||
| it "changes the address and marks the changed address as default" do | ||
| expect { | ||
| put "/api/users/#{user.id}/address_book", | ||
| params: { address_book: harry_address_attributes.merge(changes) }, | ||
| headers: { Authorization: 'Bearer galleon' } | ||
| }.to change { user.reload.ship_address.name }.from("Harry Potter").to("Hermione Granger") | ||
|
|
||
| expect(json_response.first["reverse_charge_status"]).to eq("enabled") | ||
| expect(json_response.first["email"]).to eq("[email protected]") | ||
| expect(json_response.first["vat_id"]).to eq("AB1234567") | ||
| expect(response.status).to eq(200) | ||
| end | ||
| end | ||
|
|
||
| context 'when creating an address' do | ||
| it 'marks the update_target' do | ||
| user = create(:user, spree_api_key: 'galleon') | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,7 +77,10 @@ module Spree::Api | |
| phone: '3014445002', | ||
| zipcode: '20814', | ||
| state_id: @state.id, | ||
| country_id: @country.id | ||
| country_id: @country.id, | ||
| email: '[email protected]', | ||
| vat_id: 'ab1235', | ||
| reverse_charge_status: 'disabled' | ||
| } | ||
| end | ||
|
|
||
|
|
@@ -95,7 +98,14 @@ module Spree::Api | |
| } } | ||
| expect(json_response['state']).to eq('delivery') | ||
| expect(json_response['bill_address']['name']).to eq('John Doe') | ||
| expect(json_response['bill_address']['email']).to eq('[email protected]') | ||
| expect(json_response['bill_address']['vat_id']).to eq('ab1235') | ||
| expect(json_response['bill_address']['reverse_charge_status']).to eq('disabled') | ||
| expect(json_response['ship_address']['name']).to eq('John Doe') | ||
| expect(json_response['ship_address']['email']).to eq('[email protected]') | ||
| expect(json_response['ship_address']['vat_id']).to eq('ab1235') | ||
| expect(json_response['ship_address']['reverse_charge_status']).to eq('disabled') | ||
|
|
||
| expect(response.status).to eq(200) | ||
| end | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
core/db/migrate/20250225051308_add_vat_id_email_and_reverse_charge_status_to_addresses.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddVatIdEmailAndReverseChargeStatusToAddresses < ActiveRecord::Migration[7.0] | ||
| def change | ||
| add_column :spree_addresses, :vat_id, :string | ||
| add_column :spree_addresses, :email, :string | ||
| add_column :spree_addresses, :reverse_charge_status, :integer, default: 0, null: false, | ||
| comment: "Enum values: 0 = disabled, 1 = enabled, 2 = not_validated" | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -294,4 +294,58 @@ | |
|
|
||
| it { is_expected.to be_require_phone } | ||
| end | ||
|
|
||
| describe 'enum reverse_charge_status' do | ||
| it 'defines the expected enum values' do | ||
| expect(Spree::Address.reverse_charge_statuses).to eq({ | ||
| 'disabled' => 0, | ||
| 'enabled' => 1, | ||
| 'not_validated' => 2 | ||
| }) | ||
| end | ||
|
|
||
| context 'allows valid values' do | ||
| it 'has not_validated value' do | ||
| address = build(:address) | ||
| # Updates the reverse_charge_status to "not_validated" | ||
| address.reverse_charge_status_not_validated! | ||
|
|
||
| expect(address).to be_valid | ||
| end | ||
|
|
||
| it 'has disabled value' do | ||
| address = build(:address) | ||
| # Updates the reverse_charge_status to "disabled" | ||
| address.reverse_charge_status_disabled! | ||
|
|
||
| expect(address).to be_valid | ||
| end | ||
|
|
||
| it 'has enabled value' do | ||
| address = build(:address) | ||
| # Updates the reverse_charge_status to "enabled" | ||
| address.reverse_charge_status_enabled! | ||
|
|
||
| expect(address).to be_valid | ||
| end | ||
| end | ||
|
|
||
| it 'raises an error for invalid values' do | ||
| expect { Spree::Address.new(reverse_charge_status: :invalid_status) }.to raise_error(ArgumentError) | ||
| end | ||
| end | ||
|
|
||
| context 'ensure fields are stored' do | ||
| let(:address) { build(:address) } | ||
|
|
||
| it 'saves email correctly' do | ||
| address.email = '[email protected]' | ||
| expect(address.save).to be true | ||
| end | ||
|
|
||
| it 'saves vat_id correctly' do | ||
| address.vat_id = 'AB123' | ||
| expect(address.save).to be true | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.