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

spree 4.1 #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ gem 'spree', github: 'spree/spree', branch: 'master'
# Provides basic authentication functionality for testing parts of your engine
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'

gem 'byebug', '~> 9.0.6'
gem 'byebug', '>= 9.0.6'
Copy link
Member

Choose a reason for hiding this comment

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

Why >= ?

Copy link
Member

Choose a reason for hiding this comment

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

move to gemspec


group :test do
gem 'rails-controller-testing', '~> 1.0.4'
end

gemspec
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Try Spree Item Returns for Spree 3-4 with direct deployment on Heroku:

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/vinsol-spree-contrib/spree-demo-heroku/tree/spree-item-returns-3-4)

Try Spree Item Returns for Spree 4-1 with direct deployment on Heroku:

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/vinsol-spree-contrib/spree-demo-heroku/tree/spree-item-returns-4-1)


## FEATURES

Expand Down
14 changes: 14 additions & 0 deletions app/assets/images/send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/javascripts/spree/return_authorization.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
//= require 'spree/backend/returns/return_item_selection'
//= require 'spree/frontend/return_item_options_selection'
//= require jquery
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Spree::FrontendHelper.class_eval do
module Spree::ReturnAuthorizationsHelper

def exchange_for_item_return?(return_item)
return_item.persisted? && return_item.exchange_variant_id?
Expand Down
3 changes: 0 additions & 3 deletions app/models/spree/app_configuration_decorator.rb

This file was deleted.

14 changes: 0 additions & 14 deletions app/models/spree/order_decorator.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/models/spree/product_decorator.rb

This file was deleted.

30 changes: 0 additions & 30 deletions app/models/spree/return_authorization_decorator.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/models/spree/user_decorator.rb

This file was deleted.

8 changes: 8 additions & 0 deletions app/models/spree_item_returns/app_configuration_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module SpreeItemReturns::AppConfigurationDecorator

def self.prepended(base)
base.preference :return_initiation_admin_mail_address, :string, default: '[email protected]'
end
end

Spree::AppConfiguration.prepend SpreeItemReturns::AppConfigurationDecorator
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Spree::LineItem.class_eval do
module SpreeItemReturns::LineItemDecorator

def is_returnable?
return false unless product.returnable?
Expand All @@ -7,3 +7,5 @@ def is_returnable?
end

end

Spree::LineItem.prepend SpreeItemReturns::LineItemDecorator
19 changes: 19 additions & 0 deletions app/models/spree_item_returns/order_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module SpreeItemReturns::OrderDecorator

SHIPPED_STATES = ['shipped', 'partial']

def self.prepended(base)
base.scope :returned, -> { where(shipment_state: SHIPPED_STATES) }
end

def has_returnable_products?
products.returnable.exists?
end

def has_returnable_line_items?
line_items.any?(&:is_returnable?)
end

end

Spree::Order.prepend SpreeItemReturns::OrderDecorator
9 changes: 9 additions & 0 deletions app/models/spree_item_returns/product_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module SpreeItemReturns::ProductDecorator

def self.prepended(base)
base.validates :return_time, numericality: { greater_than_or_equal_to: 0 }
base.scope :returnable, -> { where(returnable: true) }
end
end

Spree::Product.prepend SpreeItemReturns::ProductDecorator
34 changes: 34 additions & 0 deletions app/models/spree_item_returns/return_authorization_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module SpreeItemReturns::ReturnAuthorizationDecorator

def self.prepended(base)
stock_location_validations = base._validators[:stock_location]
if stock_location_validations.present?
stock_location_validations.reject! { |validation| validation.is_a? ActiveRecord::Validations::PresenceValidator }
end

base._validate_callbacks.each do |callback|
callback.raw_filter.attributes.delete :stock_location if callback.raw_filter.is_a?(ActiveModel::Validations::PresenceValidator)
end

base.validates :stock_location, presence: true, unless: :user_initiated?
base.validates :return_items, presence: true, if: :user_initiated?

base.after_commit :notify_admin, :notify_user, on: :create, if: :user_initiated?
end

def allow_return_item_changes?
!customer_returned_items?
end

private
def notify_admin
Spree::ReturnAuthorizationMailer.notify_return_initialization_to_admin(number).deliver_later
end

def notify_user
Spree::ReturnAuthorizationMailer.notify_return_initialization_to_user(number).deliver_later
end

end

Spree::ReturnAuthorization.prepend SpreeItemReturns::ReturnAuthorizationDecorator
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Spree::ReturnItem.class_eval do
module SpreeItemReturns::ReturnItemDecorator

def returnable?
inventory_unit.variant.product.returnable?
Expand All @@ -7,4 +7,6 @@ def returnable?
def returned?
inventory_unit.shipped? && return_authorization.allow_return_item_changes? && !reimbursement
end
end
end

Spree::ReturnItem.prepend SpreeItemReturns::ReturnItemDecorator
8 changes: 8 additions & 0 deletions app/models/spree_item_returns/user_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module SpreeItemReturns::UserDecorator

def self.prepended(base)
base.has_many :return_authorizations, through: :orders
end
end

Spree::User.prepend SpreeItemReturns::UserDecorator
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
virtual_path: 'spree/users/show',
name: 'user_return_authorization_history_button',
insert_bottom: "[data-hook='account_my_orders'] h3",
text: "<%= link_to(spree.return_authorizations_path, class: 'btn btn-primary pull-right') do %>
<span class='glyphicon glyphicon-list-alt'></span>
text: "<%= link_to(spree.return_authorizations_path, class: 'btn btn-primary float-right') do %>
<span class='glyphicon glyphicon-list-alt'><%= icon(name: 'burger', classes: 'd-none d-xl-inline-block', width: 20, height: 20) %></span>
<%= Spree.t(:returns_history) %>
<% end %>"
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Deface::Override.new(
virtual_path: 'spree/orders/show',
name: 'user_return_authorization_initailization_button',
insert_bottom: "#order_summary h1",
insert_bottom: ".order-show-number",
text: "
<% if spree_current_user.present? && @order.shipped? && @order.has_returnable_products? && @order.has_returnable_line_items? %>
<%= link_to(spree.new_order_return_authorization_path(@order), class: 'btn btn-primary pull-right') do %>
<span class='glyphicon glyphicon-send'></span>
<%= link_to(spree.new_order_return_authorization_path(@order), class: 'btn btn-primary float-right') do %>
<span class='glyphicon glyphicon-send'><%= icon(name: 'send', classes: 'd-none d-xl-inline-block', width: 25, height: 25) %></span>
<%= Spree.t(:return_products) %>
<% end %>
<% end %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/spree/return_authorizations/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div data-hook="admin_return_authorization_form_fields">
<h3>
<%= Spree.t(:my_returns_history, scope: :return_authorization_view)%>
<%= link_to(account_path, class: 'btn btn-primary pull-right') do %>
<span class='glyphicon glyphicon-list-alt'></span>
<%= link_to(account_path, style:'float: right', class: 'btn btn-primary') do %>
<span class='glyphicon glyphicon-list-alt'><%= icon(name: 'person', classes: 'd-none d-xl-inline-block', width: 30, height: 30) %></span>
<%= Spree.t(:back_to_account) %>
<% end %>
</h3>
Expand All @@ -29,7 +29,7 @@
<td><%= (return_authorization.created_at).strftime('%v') %></td>
<td>
<%= link_to(order_return_authorization_path(order,id: return_authorization.number), class: 'btn btn-xs btn-primary') do %>
<span class='glyphicon glyphicon-plus'></span>
<span class='glyphicon glyphicon-plus'><%= icon(name: 'plus', classes: 'd-none d-xl-inline-block', width: 20, height: 20) %></span>
<%= Spree.t(:view_details) %>
<% end %>
</td>
Expand Down
15 changes: 8 additions & 7 deletions app/views/spree/return_authorizations/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<% content_for :head do %>
<%= javascript_include_tag 'spree/return_authorization' %>
<% end %>
<div class="row">
<fieldset class="col-6"><h3><%= Spree.t(:return_request, scope: :return_authorizations_view) %></h3></fieldset>
<fieldset class="col-6" style="text-align: right;">
<%= link_to Spree.t(:back_to_order, scope: :return_authorizations_view), spree.order_url(@order), class: "btn btn-primary" %> |
<%= link_to Spree.t(:back_to_return_history, scope: :return_authorizations_view), spree.return_authorizations_path, class: "btn btn-primary" %>
</fieldset>
</div>

<fieldset><h3><%= Spree.t(:return_request, scope: :return_authorizations_view) %></h3></fieldset>
<fieldset>
<%= link_to Spree.t(:back_to_order, scope: :return_authorizations_view), spree.order_url(@order) %> |
<%= link_to Spree.t(:back_to_return_history, scope: :return_authorizations_view), spree.return_authorizations_path %>
</fieldset>

<%= form_for [:admin, @order, @return_authorization] do |f| %>
<%= form_for [@order, @return_authorization] do |f| %>
<fieldset>
<%= f.field_container :amount, class: ['alert alert-info'] do %>
<%= Spree.t(:return_request_status)%> : <b><%= @return_authorization.state %></b>
Expand Down
2 changes: 1 addition & 1 deletion spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe 'Constants' do
it 'is expected to initialize SHIPPED_STATES' do
expect(SHIPPED_STATES).to eq(['shipped', 'partial'])
expect(Spree::Order::SHIPPED_STATES).to eq(['shipped', 'partial'])
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SimpleCov.start 'rails'

# Configure Rails Environment
ENV['RAILS_ENV'] = 'test'
ENV['RAILS_ENV'] ||= 'test'

require File.expand_path('../dummy/config/environment.rb', __FILE__)

Expand Down
26 changes: 13 additions & 13 deletions spree_item_returns.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_item_returns'
s.version = '3.3.0'
s.version = '3.4.0'
s.summary = 'Spree Item Returns'
s.description = '
At User-End
- User can Initate items-return process
- Can check return history
'
s.required_ruby_version = '>= 2.2.7'
s.required_ruby_version = '>= 2.5.0'

s.author = 'Anurag Bhardwaj'
s.email = '[email protected]'
Expand All @@ -21,23 +21,23 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency 'spree_core', '>= 3.2.0', '< 4.0'
s.add_dependency 'spree_extension', '~> 0.0.5'
s.add_dependency 'spree_core', '>= 4.0.0'
s.add_dependency 'spree_extension', '~> 0.0.9'

s.add_development_dependency 'appraisal'
s.add_development_dependency 'capybara', '~> 2.6'
s.add_development_dependency 'coffee-rails', '~> 4.2.1'
s.add_development_dependency 'capybara', '>= 3.30.0'
s.add_development_dependency 'coffee-rails', '~> 5.0.0'
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'factory_bot'
s.add_development_dependency 'ffaker'
s.add_development_dependency 'rails-controller-testing', '~> 1.0.1'
s.add_development_dependency 'rspec-activemodel-mocks', '~> 1.0.3'
s.add_development_dependency 'rspec-rails', '~> 3.4'
s.add_development_dependency 'sass-rails', '~> 5.0.0'
s.add_development_dependency 'rails-controller-testing', '~> 1.0.4'
s.add_development_dependency 'rspec-activemodel-mocks', '~> 1.1.0'
s.add_development_dependency 'rspec-rails', '~> 4.0.0'
s.add_development_dependency 'sass-rails', '>= 5.0.0'
s.add_development_dependency 'selenium-webdriver', '~> 3.0.8'
s.add_development_dependency 'shoulda-matchers', '~> 3.1.1'
s.add_development_dependency 'shoulda-matchers', '~> 4.3'
s.add_development_dependency 'shoulda-callback-matchers', '~> 1.1.1'
s.add_development_dependency 'simplecov', '~> 0.13.0'
s.add_development_dependency 'sqlite3', '~> 1.3.13'
s.add_development_dependency 'simplecov', '~> 0.18.0'
s.add_development_dependency 'sqlite3', '~> 1.4'

end