Skip to content

Commit

Permalink
CR remarks && migration/controller/view changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Przemek Kosakowski committed Oct 17, 2019
1 parent 5df79df commit fa5ddf6
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 21 deletions.
20 changes: 11 additions & 9 deletions app/controllers/spree/admin/avalara_entity_use_codes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ def edit; end

def update
if @use_code.update(entity_use_codes_params)
flash[:notice] = t('spree_avatax_official.entity_use_code_updated')
redirect_to admin_avalara_entity_use_codes_path
redirect_to admin_avalara_entity_use_codes_path, success: t('spree_avatax_official.entity_use_code_updated')
else
redirect_to edit_admin_avalara_entity_use_code_path(@use_code), error: @use_code.errors.full_messages.to_sentence
end
end

def create
@use_code = SpreeAvataxOfficial::EntityUseCode.new(entity_use_codes_params)
if @use_code.save
flash[:notice] = t('spree_avatax_official.entity_use_code_created')
redirect_to admin_avalara_entity_use_codes_path
redirect_to admin_avalara_entity_use_codes_path, success: t('spree_avatax_official.entity_use_code_created')
else
flash[:error] = @use_code.errors.full_messages.to_sentence
redirect_to new_admin_avalara_entity_use_code_path
redirect_to new_admin_avalara_entity_use_code_path, error: @use_code.errors.full_messages.to_sentence
end
end

def destroy
if @use_code.destroy
flash[:notice] = t('spree_avatax_official.entity_use_code_removed')
redirect_to admin_avalara_entity_use_codes_path
flash[:success] = t('spree_avatax_official.entity_use_code_removed')
else
flash[:error] = @use_code.errors.full_messages.to_sentence
redirect_to admin_avalara_entity_use_codes_path
end

respond_with(@use_code) do |format|
format.html { redirect_to admin_avalara_entity_use_codes_path }
format.js { render_js_for_destroy }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/users_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def load_use_codes
end

def user_params
params.require(:user).permit(:spree_avatax_official_entity_use_codes_id, :exemption_number, :vat_id)
params.require(:user).permit(:avatax_entity_use_code_id, :exemption_number, :vat_id)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree_avatax_official/spree/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module SpreeAvataxOfficial
module Spree
module UserDecorator
def self.prepended(base)
base.has_one :avatax_entity_use_code, class_name: 'SpreeAvataxOfficial::EntityUseCode'
base.belongs_to :avatax_entity_use_code, class_name: 'SpreeAvataxOfficial::EntityUseCode'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/overrides/spree/admin/sidebar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<<~HTML
<li>
<%= link_to_with_icon 'money',
Spree.t('spree_avatax_official.information_url'),
t('spree_avatax_official.information_url'),
avalara_information_admin_user_path(@user),
class: "nav-link" %>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def company_code
end

def entity_use_code
user.try(:spree_avatax_official_entity_use_codes_id)
user.avatax_entity_use_code.try(:code)
end

def formatted_date(date)
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/admin/users/avalara_information.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<div data-hook="admin_user_edit_form">
<%= form_for [:admin, @user], method: :put do |f| %>
<div class="form-group">
<%= label_tag :spree_avatax_official_entity_use_codes_id, Spree.t(:avalara_entity_use_code) %><br />
<%= f.select(:spree_avatax_official_entity_use_codes_id, @use_codes, { include_blank: false }, class: 'form-control' ) %>
<%= label_tag :avatax_entity_use_code_id, Spree.t(:avalara_entity_use_code) %><br />
<%= f.select(:avatax_entity_use_code_id, @use_codes, { include_blank: false }, class: 'form-control' ) %>
</div>

<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ en:
connection_rejected: Avatax rejected connection
entity_use_code_created: Entity use code created
entity_use_code_updated: Entity use code updated
use_code_removed: Entity use code removed
entity_use_code_removed: Entity use code removed
information_url: Avalara Information
avalara_entity_use_code: Avalara Entity Use Code
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def change
t.timestamps
end

add_reference :spree_users, :spree_avatax_official_entity_use_codes, type: :integer, index: true
return if column_exists?(:spree_users, :avatax_entity_use_code_id)

change_table :spree_users do |t|
t.integer :avatax_entity_use_code_id, index: { unique: true }, foreign_key: true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@

expect(page).to have_content(avalara_entity_use_code.code)

page.accept_confirm do
click_on('Delete')
within("tr#entity_use_code_#{avalara_entity_use_code.id}") do
page.accept_alert do
click_on('Delete')
end

expect(page.document).to have_content('Entity use code removed')
end

visit spree.admin_avalara_entity_use_codes_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
discount: 0.0,
currencyCode: order.currency,
purchaseOrderNo: order.number,
entityUseCode: order.try(:user).try(:spree_avatax_official_entity_use_codes_id)
entityUseCode: order.try(:user).avatax_entity_use_code.try(:code)
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
lines: [SpreeAvataxOfficial::ItemPresenter.new(item: line_item, custom_quantity: quantity, custom_amount: amount).to_json],
commit: true,
discount: 0.0,
entityUseCode: order.try(:user).try(:spree_avatax_official_entity_use_codes_id),
entityUseCode: order.try(:user).avatax_entity_use_code.try(:code),
currencyCode: order.currency,
purchaseOrderNo: order.number,
taxOverride: {
Expand Down

0 comments on commit fa5ddf6

Please sign in to comment.