Skip to content

Commit

Permalink
qa fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshumishra31 committed Aug 23, 2018
1 parent 253d1a8 commit f5bc1ec
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
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 @@ -8,7 +8,7 @@ def import_store_credits
create_store_credit_updater
redirect_to admin_users_path, notice: Spree.t(:email_sent, filename: @store_credit_updater.data_file_file_name)
rescue
redirect_to admin_users_path, notice: "Invalid CSV file format."
redirect_to admin_users_path, notice: Spree.t(:invalid_format)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/mailers/spree/store_credit_updater_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def update_admin(status_csv, admin_email, filename, total_records, successfull_r
@failed_records = total_records - successfull_records
attachments['stock_items.csv'] = status_csv
subject = "#{Spree::Store.current.name} import of #{ filename } has finished"
mail(to: admin_email, from: from_address, subject: subject)
mail(to: '[email protected]', from: from_address, subject: subject)
end
end
end
16 changes: 9 additions & 7 deletions app/services/notify_store_credit_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'csv'
class NotifyStoreCreditService
CSV_HEADERS = { 'Email': :Email, 'Store_Credit': :Store_Credit, 'Memo': :Memo, 'Category_ID': :Category_ID, 'Status': :Status }
CSV_HEADERS = { 'Email': :Email, 'Store_Credit': :Store_Credit, 'Memo': :Memo, 'Status': :Status }

def initialize(store_credit_updater_id, admin_email)
@store_credit_updater = Spree::BulkStoreCreditUpdater.find_by(id: store_credit_updater_id)
Expand All @@ -22,10 +22,10 @@ def update_store_credits
@total_records += 1
@row = row
@user = find_user
if @user
update_stocks_with_csv_values
if @user && @row['Store_Credit'].scan(/\D/).empty?
update_store_credits_with_csv_values
else
@error = Spree.t(:user_not_found)
@error = @user ? Spree.t(:store_credit_not_integer) : Spree.t(:user_not_found)
end
csv << set_row
end
Expand All @@ -50,13 +50,15 @@ def create_csv_row(key, value)
end

def error_message
@error ? @error : 'Successfully Updated'
@error ? @error : Spree.t(:successfull_update)
end

def update_stocks_with_csv_values
def update_store_credits_with_csv_values
admin = Spree::User.admin.first
store_credit = Spree::StoreCredit.new(amount: @row['Store_Credit'].to_f, created_by_id: admin.id, currency: "USD", category_id: @row['Category_ID'], memo: @row['Memo'])
category = Spree::StoreCreditCategory.first
store_credit = Spree::StoreCredit.new(amount: @row['Store_Credit'].to_f, created_by_id: admin.id, currency: "USD", category_id: category.try(:id), memo: @row['Memo'])
@user.store_credits << store_credit
@error = store_credit.valid? ? nil : store_credit.errors.full_messages.join(',')
@successfull_records += 1
end

Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ en:
example: Download Sample File
email_sent: "%{filename} has been successfully imported. Details will be sent shortly to you over an email."
user_not_found: User with this email Not found
store_credit_not_integer: Amount not integer
invalid_format: Invalid CSV file format.
successfull_update: Successfully Updated
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateSpreeBulkStoreCreditUpdater < ActiveRecord::Migration[4.2]
def change
create_table :spree_bulk_store_credit_updaters do |t|
t.boolean :job_executed, default: false
t.boolean :job_executed, default: false, null: false
t.attachment :data_file
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sample_csv/bulk_store_credits_example.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Email,Store_Credit,Memo,Category_ID
[email protected],10,Order benefit,1
Email,Store_Credit,Memo
[email protected],10,Order benefit

0 comments on commit f5bc1ec

Please sign in to comment.