diff --git a/README.md b/README.md index f852efa..ad8565b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/controllers/spree/admin/pos_controller.rb b/app/controllers/spree/admin/pos_controller.rb index f7de502..ec95995 100644 --- a/app/controllers/spree/admin/pos_controller.rb +++ b/app/controllers/spree/admin/pos_controller.rb @@ -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 @@ -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 @@ -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 @@ -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] @@ -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! diff --git a/app/controllers/spree/admin/print_coupon_controller.rb b/app/controllers/spree/admin/print_coupon_controller.rb index a5e193f..5708f9f 100644 --- a/app/controllers/spree/admin/print_coupon_controller.rb +++ b/app/controllers/spree/admin/print_coupon_controller.rb @@ -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 diff --git a/app/controllers/spree/admin/refund_controller.rb b/app/controllers/spree/admin/refund_controller.rb index 4548bab..4f8f7cc 100644 --- a/app/controllers/spree/admin/refund_controller.rb +++ b/app/controllers/spree/admin/refund_controller.rb @@ -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 @@ -45,13 +54,13 @@ 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') @@ -59,5 +68,6 @@ def create_discount_coupon(code, amount, description = nil, name = nil) action.calculator = calculator @coupon.save! calculator.preferred_amount = amount + calculator.save! end end \ No newline at end of file diff --git a/app/overrides/add_pos_button.rb b/app/overrides/add_pos_button.rb index 93b0bb5..87fc0e4 100644 --- a/app/overrides/add_pos_button.rb +++ b/app/overrides/add_pos_button.rb @@ -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) \ No newline at end of file diff --git a/app/views/spree/admin/layouts/receipt.html.erb b/app/views/spree/admin/layouts/receipt.html.erb index 4e3ae53..aff8652 100644 --- a/app/views/spree/admin/layouts/receipt.html.erb +++ b/app/views/spree/admin/layouts/receipt.html.erb @@ -15,7 +15,7 @@ <%= yield %> diff --git a/app/views/spree/admin/orders/_pos_button.html.erb b/app/views/spree/admin/orders/_pos_button.html.erb index a1512d7..935170c 100644 --- a/app/views/spree/admin/orders/_pos_button.html.erb +++ b/app/views/spree/admin/orders/_pos_button.html.erb @@ -1 +1,3 @@ -<%= button_link_to("Pos", "/admin/pos/show/#{@order.number}" )%> +
  • + <%= link_to_with_icon 'file', "POS", "/admin/pos/show/#{@order.number}" %> +
  • \ No newline at end of file diff --git a/app/views/spree/admin/pos/_keyboard.erb b/app/views/spree/admin/pos/_keyboard.erb index a2ccdf3..8cc7ab3 100644 --- a/app/views/spree/admin/pos/_keyboard.erb +++ b/app/views/spree/admin/pos/_keyboard.erb @@ -17,16 +17,21 @@ }) }); - -
    - <% 10.times.each do |i| %> - - <% end %> - -
    -
    - +
    +

    + +

    +
    +

    + <% 10.times.each do |i| %> + + <% end %> + +

    +
    +
    +
    \ No newline at end of file diff --git a/app/views/spree/admin/pos/report.html.erb b/app/views/spree/admin/pos/report.html.erb index b2276fb..fdf873f 100644 --- a/app/views/spree/admin/pos/report.html.erb +++ b/app/views/spree/admin/pos/report.html.erb @@ -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 %> -

    Estadísticas

    -<%= search_form_for @search, :url => spree.admin_report_path do |s| %> -
    - <%= 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]) %> - - - +<%= search_form_for @search, :url => spree.admin_report_path do |s| %> +
    +
    + <%= 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]) %> +
    - <%= 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' %> -
    +
    + <%= 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]) %> +
    - -
    + +
    + <%= label_tag nil, ' ' %> <%= button Spree.t(:search), 'icon-search' %>
    <% end %> -
    - \ No newline at end of file + + +
    +
    +
      + <%- @payment_methods.each do |pm,value| %> +
    • <%= pm.name %>: <%= value[:total].format %>
    • + <% end %> +
    +
    \ No newline at end of file diff --git a/app/views/spree/admin/pos/show.html.erb b/app/views/spree/admin/pos/show.html.erb index 219400f..3544243 100644 --- a/app/views/spree/admin/pos/show.html.erb +++ b/app/views/spree/admin/pos/show.html.erb @@ -9,61 +9,67 @@ //--> <% end %> -<% content_for :sidebar do %> -