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

  def new
    init
    redirect_to :action => :index
  end

  def export
    unless session[:items]
      index
      return
    end
    opt = {}
    session[:items].each do |key , item | 
      id = item.variant.ean.blank? ? item.variant.sku : item.variant.ean
      opt[id] = item.quantity
      item.variant.on_hand -= item.quantity
      item.variant.save
    end
    init  # reset this pos
    opt[:host] = Spree::Config[:pos_export] 
    opt[:controller] = "pos" 
    opt[:action] = "import" 
    redirect_to opt
  end
  
  def import
    init
    added = 0
    params.each do |id , quant |
      next if id == "action" 
      next if id == "controller" 
      v = Variant.find_by_ean id
      if v 
        add_variant(v , quant )
        added += 1
      else
        v = Variant.find_by_sku id
        if v 
          add_variant(v , quant )
          added += 1
        else
          add_error "No product found id #{id}"
        end
      end
    end
    add_notice "Added #{added} products" if added
    redirect_to :action => :index
  end
  
  def inventory
    as = params[:as]<commit_msg>improve cross recognition<commit_after>class Admin::PosController < Admin::BaseController

  def new
    init
    redirect_to :action => :index
  end

  def export
    unless session[:items]
      index
      return
    end
    missing = []
    session[:items].each do |key , item | 
      missing << item.variant.full_name if item.variant.ean.blank?
    end
    unless missing.empty?
      flash[:error] = "All items must have ean set, missing: #{missing.join(' , ')}"
      redirect_to :action => "index" 
      return
    end
    opt = {}
    session[:items].each do |key , item | 
      var = item.variant
      opt[var.ean] = item.quantity
      var.on_hand =  var.on_hand - item.quantity
      var.save!
    end
    init  # reset this pos
    opt[:host] = Spree::Config[:pos_export] 
    opt[:controller] = "pos" 
    opt[:action] = "import" 
    redirect_to opt
  end
  
  def import
    init
    added = 0
    params.each do |id , quant |
      next if id == "action" 
      next if id == "controller" 
      v = Variant.find_by_ean id
      if v 
        add_variant(v , quant )
        added += 1
      else
        v = Variant.find_by_sku id
        if v 
          add_variant(v , quant )
          added += 1
        else
          add_error "No product found for EAN #{id}     "
        end
      end
    end
    add_notice "Added #{added} products" if added
    redirect_to :action => :index
  end
  
  def inventory
    as = params[:as]
{'fraction_non_alphanumeric': 0.09988562714449103, 'fraction_numerical': 0.002287457110179184, 'mean_word_length': 1.8866886688668867, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '1773176', 'n_tokens_mistral': 854, 'n_tokens_neox': 813, 'n_words': 237}