<commit_before>Spree::Variant.class_eval do

  scope :complete_order, -> { joins(:orders).where.not(spree_orders: { completed_at: nil }) }

  def self.sales_sku
    select("spree_variants.id, spree_products.id AS product_id, spree_variants.sku, spree_products.name, spree_variants.variant_name, SUM(spree_line_items.quantity) AS quantity, SUM(spree_line_items.price) AS amount").
    joins(:product).
    complete_order.
    group("spree_variants.id, spree_products.id, spree_variants.sku, spree_products.name, spree_variants.variant_name").order("amount DESC")
  end

  def self.sales_sku_csv
    CSV.generate(col_sep: ';', encoding: 'UTF-8') do |csv|
      csv << ["Codigo/SKU", "Nombre", "Items Vendidos", "Monto sin IVA"]

      sales_sku.each do |item|
        values =[]

        values << item[:sku]
        values << (item[:variant_name] || item[:name])
        values << item[:quantity]
        values << Spree::Money.new((item[:amount] / 1.19), currency: 'CLP').to_s

        csv << values
      end
    end
  end

  def self.variant_data
    select('spree_variants.id, spree_products.id AS product_id, spree_variants.sku, spree_variants.deleted_at, spree_products.available_on, spree_products.deleted_at AS product_deleted_at, ARRAY_AGG(spree_taxons.name) AS taxons, spree_products.description, spree_product_properties.value AS brand').
    joins(product: [:taxons, :properties]).
    where(spree_properties: { name: 'brand' }).
    group('spree_variants.id, spree_products.id, spree_variants.sku, spree_variants.deleted_at, spree_products.description, spree_product_properties.value, spree_products.available_on, spree_products.deleted_at')
  end

  def self.variant_data_csv
    CSV.generate(col_sep: ';', encoding: 'UTF-8') do |csv|
      csv << ["Codigo/SKU", "Categoría", "Descripción", "Marca", "Estado"]

      variant_data.each do |item|
        values =[]

        values << item[:sku]
        values << item[:taxons].join(', ')
        values << ActionController::Base.helpers.strip_tags(item[:description])
        values << item[:brand]
        values << Spree.t("available.#{!(item[:available_on].nil? || item[:available_on].future?) && item[:deleted_at].nil? && item[:product_deleted_at].nil?}")

        csv << values
      end
    end
  end
end
<commit_msg>Not display variants with nil sku<commit_after>Spree::Variant.class_eval do

  scope :complete_order, -> { joins(:orders).where.not(spree_orders: { completed_at: nil }) }

  def self.sales_sku
    select("spree_variants.id, spree_products.id AS product_id, spree_variants.sku, spree_products.name, spree_variants.variant_name, SUM(spree_line_items.quantity) AS quantity, SUM(spree_line_items.price) AS amount").
    joins(:product).
    where.not(spree_variants: { sku: nil }).
    complete_order.
    group("spree_variants.id, spree_products.id, spree_variants.sku, spree_products.name, spree_variants.variant_name").order("amount DESC")
  end

  def self.sales_sku_csv
    CSV.generate(col_sep: ';', encoding: 'UTF-8') do |csv|
      csv << ["Codigo/SKU", "Nombre", "Items Vendidos", "Monto sin IVA"]

      sales_sku.each do |item|
        values =[]

        values << item[:sku]
        values << (item[:variant_name] || item[:name])
        values << item[:quantity]
        values << Spree::Money.new((item[:amount] / 1.19), currency: 'CLP').to_s

        csv << values
      end
    end
  end

  def self.variant_data
    select("spree_variants.id, spree_products.id AS product_id, spree_variants.sku, spree_variants.deleted_at, spree_products.available_on, spree_products.deleted_at AS product_deleted_at, ARRAY_AGG(spree_taxons.name) AS taxons, spree_products.description, spree_product_properties.value AS brand").
    joins(product: [:taxons, :properties]).
    where.not(spree_variants: { sku: nil }).
    where(spree_properties: { name: 'brand' }).
    group("spree_variants.id, spree_products.id, spree_variants.sku, spree_variants.deleted_at, spree_products.description, spree_product_properties.value, spree_products.available_on, spree_products.deleted_at")
  end

  def self.variant_data_csv
    CSV.generate(col_sep: ';', encoding: 'UTF-8') do |csv|
      csv << ["Codigo/SKU", "Categoría", "Descripción", "Marca", "Estado"]

      variant_data.each do |item|
        values =[]

        values << item[:sku]
        values << item[:taxons].join(', ')
        values << ActionController::Base.helpers.strip_tags(item[:description])
        values << item[:brand]
        values << Spree.t("available.#{!(item[:available_on].nil? || item[:available_on].future?) && item[:deleted_at].nil? && item[:product_deleted_at].nil?}")

        csv << values
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1423076923076923, 'fraction_numerical': 0.002136752136752137, 'mean_word_length': 4.055075593952484, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 5, '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': '6871610', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1612, 'n_words': 285}