Skip to content

Provide compatibility with Spree 3.0 #4

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

Open
wants to merge 4 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ So there is a migration supplied that provides a ean (European Article code, may

TO-DO
-----
* TESTS !!!!!!!!!!!!!!!!!!!!!!!!!
* Move all texts to SpreePos::Config or to locale files
* Fix creation of "At store" shipping method in seeds
* TESTS !!!
* Being able to assign a user directly to an order directly from the interface for later invoice printing.
* Do ease the mechanism for devolutions
* Refactor the view so it has the calculator prettier
Expand Down
33 changes: 14 additions & 19 deletions app/controllers/spree/admin/pos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Spree::Admin::PosController < Spree::Admin::BaseController
include Spree::Core::ControllerHelpers::Order

before_filter :get_order , :except => [:new, :report]

def get_order
Expand Down Expand Up @@ -47,9 +49,6 @@ def remove
variant = Spree::Variant.find(pid)
line_item = @order.line_items.find { |line_item| line_item.variant_id == variant.id }

fire_event('spree.cart.add')
fire_event('spree.order.contents_changed')

line_item.quantity -= 1
if line_item.quantity == 0
@order.line_items.delete line_item
Expand All @@ -63,14 +62,14 @@ def remove

def apply_coupon
@order.coupon_code = params[:coupon_code]
coupon_result = Spree::Promo::CouponApplicator.new(@order).apply
if coupon_result[:coupon_applied?]
add_notice coupon_result[:success] if coupon_result[:success].present?
redirect_to :action => :show
else
add_error coupon_result[:error]
redirect_to :action => 'show'
handler = Spree::PromotionHandler::Coupon.new(@order).apply

if handler.error.present?
add_error handler.error
elsif handler.success
add_notice handler.success
end
redirect_to :action => :show
end

def print
Expand Down Expand Up @@ -213,7 +212,7 @@ def add_error no
end

def init
@order = Spree::Order.new
@order = Spree::Order.new(pos_sell: true)
@order.associate_user!(spree_current_user)

if SpreePos::Config[:pos_ship_address]
Expand All @@ -234,15 +233,11 @@ def init
spree_user_session[:pos_order] = @order.number
end

def add_variant var , quant = 1
def add_variant variant, quantity = 1
init unless @order

# Using the same populator as OrderContoller#populate
populator = Spree::OrderPopulator.new(@order, Spree::Config[:currency])
populator.populate(variants: { var => quant})

fire_event('spree.cart.add')
fire_event('spree.order.contents_changed')
# Using the same code as OrderContoller#populate
options = (params[:options] || {}).merge(currency: current_currency)
@order.contents.add(variant, quantity, options)

self.set_shipping_method
@order.save!
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/print_coupon_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Spree::Admin::PrintCouponController < Spree::Admin::BaseController
def print
@coupon = Spree::Promotion.find_by code: params[:coupon_code]
@calculator = @coupon.actions.first.calculator
@coupon_amount = @calculator.preferred_amount
@coupon_amount = @calculator.try(:preferred_amount)
@coupon_amount = @calculator.preferred_percent unless @coupon_amount
create_barcode
end
Expand Down
18 changes: 14 additions & 4 deletions app/controllers/spree/admin/refund_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ class Spree::Admin::RefundController < Spree::Admin::BaseController
layout 'spree/admin/layouts/refund'

def select_order

@reasons = Spree::ReturnAuthorizationReason.active
@stock_locations = Spree::StockLocation.active
end

def select_items
@order = Spree::Order.find_by(number: params[:order_number])
if @order
@order.return_authorizations.select(&:can_cancel?).map(&:cancel) if @order.return_authorizations.count > 0
@return_authorization = Spree::ReturnAuthorization.create(order: @order, reason: 'POS refund')
@return_authorization = Spree::ReturnAuthorization.create(order: @order,
return_authorization_reason_id: params[:reason_id],
stock_location_id: params[:stock_location_id])

unless @return_authorization.valid?
flash[:error] = @return_authorization.errors.full_messages.join("; ")
redirect_to action: :select_order
end

if @order.state == 'complete'
@variants = @order.variants
else
Expand Down Expand Up @@ -45,19 +54,20 @@ def select_coupon
def create_coupon
amount = params[:coupon_amount].to_f
description = params[:coupon_description]
create_discount_coupon(Spree::Promotion.random_code,amount,description, 'Coupon pos')
create_discount_coupon(Spree::Promotion.random_code, amount, description, 'Coupon pos')
redirect_to "/admin/print_coupon/#{@coupon.code}"
end

protected
def create_discount_coupon(code, amount, description = nil, name = nil)
@coupon = Spree::Promotion.create(name: name,event_name: 'spree.checkout.coupon_code_added', usage_limit: 1)
@coupon = Spree::Promotion.create(name: name, usage_limit: 1)
@coupon.description = description unless description.try(&:empty?)
@coupon.code = code
action = @coupon.actions.build(type: 'Spree::Promotion::Actions::CreateAdjustment')
calculator = Spree::Calculator::FlatRate.create
action.calculator = calculator
@coupon.save!
calculator.preferred_amount = amount
calculator.save!
end
end
2 changes: 1 addition & 1 deletion app/overrides/add_pos_button.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Deface::Override.new(:virtual_path => "spree/admin/shared/_order_tabs",
:name => "add_pos_button",
:insert_after => ".sidebar",
insert_bottom: '[data-hook="admin_order_tabs"]',
:partial => "spree/admin/orders/pos_button",
:disabled => false)
2 changes: 1 addition & 1 deletion app/views/spree/admin/layouts/receipt.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<%= yield %>
</div>
<div class="footer">
Más información [email protected] o llamando al 914 20 47 78
<%= SpreePos::Config[:receipt_footer] %>
</div>
</div>
</body>
Expand Down
4 changes: 3 additions & 1 deletion app/views/spree/admin/orders/_pos_button.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<%= button_link_to("Pos", "/admin/pos/show/#{@order.number}" )%>
<li>
<%= link_to_with_icon 'file', "POS", "/admin/pos/show/#{@order.number}" %>
</li>
27 changes: 16 additions & 11 deletions app/views/spree/admin/pos/_keyboard.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@
})
});
</script>
<input id="given" type="number">
<div class="keyboard">
<% 10.times.each do |i| %>
<button data-number="<%= i %>">
<%= i %>
</button>
<% end %>
<button id="delete">BORRAR</button>
</div>
<div id="return-money">

<div class="col-md-6">
<p>
<input id="given" type="number" class="form-control">
</p>
<div class="keyboard">
<p>
<% 10.times.each do |i| %>
<button data-number="<%= i %>">
<%= i %>
</button>
<% end %>
<button id="delete">BORRAR</button>
</p>
</div>
<div id="return-money">
</div>
</div>
</div>
55 changes: 25 additions & 30 deletions app/views/spree/admin/pos/report.html.erb
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
<% content_for :head do %>
<%= stylesheet_link_tag 'DateTimePicker' %>
<%= javascript_include_tag 'DateTimePicker' %>
<%= javascript_tag do %>
$(document).ready(function()
{

$("#dtBox").DateTimePicker();

});
<% end %>
<% content_for :page_title do %>
<%= t('statistics') %>
<% end %>
<h3>Estadísticas</h3>
<%= search_form_for @search, :url => spree.admin_report_path do |s| %>
<div class="date-range-filter field align-center">
<%= label_tag nil, Spree.t(:start), :class => 'inline' %>
<%= s.text_field :updated_at_gt, :data => { :field => 'datetime' }, :class => 'datepicker-from', :value => datetimepicker_field_value(params[:q][:updated_at_gt]) %>

<span class="range-divider">
<i class="icon-arrow-right"></i>
</span>
<%= search_form_for @search, :url => spree.admin_report_path do |s| %>
<div class="row">
<div class="col-md-3">
<%= label_tag nil, Spree.t(:start) %>
<%= s.text_field :updated_at_gt, :data => { :field => 'datetime' }, :class => 'datepicker datepicker-from form-control', :value => datetimepicker_field_value(params[:q][:updated_at_gt]) %>
</div>

<%= s.text_field :updated_at_lt, :data => { :field => 'datetime' }, :class => 'datepicker-to', :value => datetimepicker_field_value(params[:q][:updated_at_lt]) %>
<%= label_tag nil, Spree.t(:end), :class => 'inline' %>
<div id="dtBox"></div>
<div class="col-md-3">
<%= label_tag nil, Spree.t(:end) %>
<%= s.text_field :updated_at_lt, :data => { :field => 'datetime' }, :class => 'datepicker datepicker-to form-control', :value => datetimepicker_field_value(params[:q][:updated_at_lt]) %>
</div>
</div>

<div class="actions filter-actions">

<div class="actions form-actions">
<%= label_tag nil, ' ' %>
<%= button Spree.t(:search), 'icon-search' %>
</div>
<% end %>
<hr />
<ul>
<%- @payment_methods.each do |pm,value| %>
<li><%= pm.name %>: <%= value[:total].format %></li>
<% end %>
</ul>


<div class="col-md-12">
<hr />
<ul>
<%- @payment_methods.each do |pm,value| %>
<li><%= pm.name %>: <%= value[:total].format %></li>
<% end %>
</ul>
</div>
Loading