<commit_before>class Admin::PosController < Admin::BaseController

  def new
    session[:items] = {}
    redirect_to :action => :index
  end

  def add
    if pid = params[:item]
      add_product Variant.find pid
    end
    redirect_to :action => :index
  end

  def remove
    if pid = params[:item]
      session[:items].delete( pid )
      flash.notice = t('product_removed') 
    end
    redirect_to :action => :index
  end

  def print
    order = Order.new
    order.email = current_user.email
    order.save!
    session[:items].each do |idd , price |
      var = Variant.find(idd)
      puts "Variant #{var.name} #{idd}"
      new_item = LineItem.new(:quantity => 1 )
      new_item.variant = var
      new_item.price = price.to_s 
      order.line_items << new_item
    end
    if id_or_name = Spree::Config[:pos_shipping]
      method = ShippingMethod.find_by_name id_or_name
      method = ShippingMethod.find_by_id(id_or_name) unless method
    end
    order.shipping_method = method || ShippingMethod.first
    order.create_shipment!
    TaxRate.all.each do |rate|
      rate.create_adjustment( rate.tax_category.description , order, order, true)
    end
    payment = Payment.new( :payment_method => PaymentMethod.find_by_type( "PaymentMethod::Check") , 
              :amount => order.total , :order_id => order.id )
    payment.save!
    payment.payment_source.capture(payment)
    order.state = "complete"
    order.completed_at = Time.now
    order.save!<commit_msg>can now print several times same pos<commit_after>class Admin::PosController < Admin::BaseController

  def new
    session[:items] = {}
    session[:pos_order] = nil
    redirect_to :action => :index
  end

  def add
    if pid = params[:item]
      add_product Variant.find pid
    end
    redirect_to :action => :index
  end

  def remove
    if pid = params[:item]
      session[:items].delete( pid )
      flash.notice = t('product_removed') 
    end
    redirect_to :action => :index
  end

  def print
    order_id = session[:pos_order]
    if order_id
      order = Order.find order_id
      order.line_items.clear
    else
      order = Order.new
      order.email = current_user.email
      order.save!
      if id_or_name = Spree::Config[:pos_shipping]
        method = ShippingMethod.find_by_name id_or_name
        method = ShippingMethod.find_by_id(id_or_name) unless method
      end
      order.shipping_method = method || ShippingMethod.first
      order.create_shipment!
      TaxRate.all.each do |rate|
        rate.create_adjustment( rate.tax_category.description , order, order, true)
      end
    end
    session[:items].each do |idd , price |
      var = Variant.find(idd)
      puts "Variant #{var.name} #{idd}"
      new_item = LineItem.new(:quantity => 1 )
      new_item.variant = var
      new_item.price = price.to_s 
      order.line_items << new_item
    end
    if order_id
      order.payment.delete
    end
    payment = Payment.new( :payment_method => PaymentMethod.find_by_type( "PaymentMethod::Check") , 
              :amount => order.total , :order_id => order.id )
    payment.save!
    payment.payment_source.capture(payment)
    order.state = "complete"
    order.completed_at = Time.now
    order.save!
    session[:pos_order] = order.id
{'fraction_non_alphanumeric': 0.10312117503059975, 'fraction_numerical': 0.0006119951040391676, 'mean_word_length': 2.7445589919816724, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5202466', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1015, 'n_words': 231}