<commit_before>module Spree
  module Admin
    class DashboardController < Spree::Admin::BaseController

      def index
        days_tracking_sales = 90
        @days_on_hand_minimum_days = 45
        vendorlist = Hash.new { |hash, key| hash[key] = {} }
        Spree::Vendor.all.each do |vendor|
          Spree::PurchasingVariant.where(:vendor_id => vendor.id).each do |pv|
            unless pv.po_line_items.where("received_amount < quantity").any? #Preventing items which are already on order from showing up
              sold = 0
              Spree::LineItem.where(:variant_id => pv.variant.id).where("created_at > ?", (Date.today - days_tracking_sales)).each do |li|
                sold += li.quantity
              end
              #If you're using assemblies, we should count those sales as well
              Spree::AssembliesPart.where(:part_id => pv.variant.id).each do |ap|
                #Because assemblies only provides a product id, I need to get the
                #variant ID. Also, I need to account for assemblies that have
                #multiple variants.
                unless ap.assembly.variants.empty?
                  id = ap.assembly.variants
                else
                  id = ap.assembly.master
                end
                id.each do |variant|
                  Spree::LineItem.where(:variant_id => variant.id).where("created_at > ?", (Date.today - days_tracking_sales)).each do |as|
                    sold += (as.quantity * ap.count)
                  end
                end
              end
              if sold > 0
                count_on_hand = pv.variant.count_on_hand
                sold_daily = sold.to_f / days_tracking_sales
                delivery_time = pv.delivery_time
                delivery_time ||= 0
                days_on_hand = ((count_on_hand / sold_daily) - delivery_time).round
                if days_on_hand < @days_on_hand_minimum_days
                  vendorlist[vendor.id][pv.variant.id] = days_on_hand
                end
              end
            end
          end
          @vendorlist = vendorlist
        end

      end

      def create
        po = Spree::PurchaseOrder.new
        vendor = Spree::Vendor.find(params[:dashboard][:vendor_id])<commit_msg>Fixing assemblies kit parts being added to sales total in case of variants<commit_after>module Spree
  module Admin
    class DashboardController < Spree::Admin::BaseController

      def index
        days_tracking_sales = 90
        @days_on_hand_minimum_days = 45
        vendorlist = Hash.new { |hash, key| hash[key] = {} }
        Spree::Vendor.all.each do |vendor|
          Spree::PurchasingVariant.where(:vendor_id => vendor.id).each do |pv|
            unless pv.po_line_items.where("received_amount < quantity").any? #Preventing items which are already on order from showing up
              sold = 0
              Spree::LineItem.where(:variant_id => pv.variant.id).where("created_at > ?", (Date.today - days_tracking_sales)).each do |li|
                sold += li.quantity
              end
              #If you're using assemblies, we should count those sales as well
              Spree::AssembliesPart.where(:part_id => pv.variant.id).each do |ap|
                #Because assemblies only provides a product id, I need to get the
                #variant ID. Also, I need to account for assemblies that have
                #multiple variants.
                unless ap.assembly.variants.empty?
                  id = ap.assembly.variants
                  id.each do |variant|
                    Spree::LineItem.where(:variant_id => variant.id).where("created_at > ?", (Date.today - days_tracking_sales)).each do |as|
                      sold += (as.quantity * ap.count)
                    end
                  end
                else
                  Spree::LineItem.where(:variant_id => ap.assembly.master.id).where("created_at > ?", (Date.today - days_tracking_sales)).each do |as|
                    sold += (as.quantity * ap.count)
                  end
                end

              end
              if sold > 0
                count_on_hand = pv.variant.count_on_hand
                sold_daily = sold.to_f / days_tracking_sales
                delivery_time = pv.delivery_time
                delivery_time ||= 0
                days_on_hand = ((count_on_hand / sold_daily) - delivery_time).round
                if days_on_hand < @days_on_hand_minimum_days
                  vendorlist[vendor.id][pv.variant.id] = days_on_hand
                end
              end
            end
          end
          @vendorlist = vendorlist
        end

      end

      def create
        po = Spree::PurchaseOrder.new
        vendor = Spree::Vendor.find(params[:dashboard][:vendor_id])
{'fraction_non_alphanumeric': 0.08790288823775638, 'fraction_numerical': 0.0029300962745918793, 'mean_word_length': 1.6743144935646335, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '3395668', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1260, 'n_words': 313}