WIP Import
This commit is contained in:
parent
6ce208d553
commit
2de306d5e6
@ -167,6 +167,7 @@ class PProduct < ApplicationRecord
|
||||
end
|
||||
|
||||
acts_as_csv_import :fields => [
|
||||
:identifiant,
|
||||
:gencode,
|
||||
:id,
|
||||
:marque,
|
||||
@ -185,7 +186,7 @@ class PProduct < ApplicationRecord
|
||||
:code_hs,
|
||||
:indice_reparabilite,
|
||||
:duree_dispo_pces_detachees,
|
||||
:das_tête,
|
||||
:das_tete,
|
||||
:das_corps,
|
||||
:das_membre,
|
||||
:poids,
|
||||
@ -211,7 +212,7 @@ class PProduct < ApplicationRecord
|
||||
# ap "*********************************************************************************************************"
|
||||
# ap "*********************************************************************************************************"
|
||||
ap "*********************************************************************************************************"
|
||||
ap list.size
|
||||
# ap list.size
|
||||
# ap list.class
|
||||
# ap "*********************************************************************************************************"
|
||||
# ap "*********************************************************************************************************"
|
||||
@ -220,96 +221,151 @@ class PProduct < ApplicationRecord
|
||||
# ap "*********************************************************************************************************"
|
||||
# ap "*********************************************************************************************************"
|
||||
# ap "*********************************************************************************************************"
|
||||
soreco_cat_hash = {
|
||||
"Smartphone" => "Smartphones & Téléphones mobiles",
|
||||
"Tablette" => "Tablettes média et tablette PC",
|
||||
"MP4" => "Baladeur MP4"
|
||||
}
|
||||
|
||||
list.each do |row|
|
||||
next if row["marque"].blank?
|
||||
|
||||
n = self.new(imported: true)
|
||||
ref = PProductRef.find_or_initialize_by(p_product: n, description: row["identifiant"])
|
||||
|
||||
row.each do |key, value|
|
||||
if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal
|
||||
eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')"
|
||||
else
|
||||
case key
|
||||
when "identifiant"
|
||||
ref.description = value
|
||||
when "gencode"
|
||||
|
||||
n.genecode = value
|
||||
when "id"
|
||||
|
||||
when "marque"
|
||||
n.s_brand = SBrand.find_or_create_by(name: value)
|
||||
|
||||
when "famille"
|
||||
n.p_product_cat = PProductCat.find_or_create_by(name: value)
|
||||
|
||||
when "reference"
|
||||
n.name = value
|
||||
|
||||
when "modele"
|
||||
ref.ct_sub_name = value if value.present?
|
||||
|
||||
when "couleur"
|
||||
ref.p_product_color = PProductColor.find_or_create_by(name: value)
|
||||
|
||||
when "color"
|
||||
|
||||
if ref.p_product_color.nil?
|
||||
ref.p_product_color = PProductColor.find_or_create_by(color: value)
|
||||
end
|
||||
when "connectivite"
|
||||
arr = []
|
||||
cellular = [ "5G", "3G", "3G+", "4G", "4G+", "2G", "wifi", "BT"]
|
||||
video = ["4K","HD" ]
|
||||
power = ["5W", "12W", "18W", "20W", "96W", "40W", "10W", "40W"]
|
||||
mix = ["<87W/4K", "5G/4K", "wifi/BT" ]
|
||||
geoloc = [ "GPS" ]
|
||||
|
||||
if mix.include?(value)
|
||||
arr = value.split('/')
|
||||
else
|
||||
arr << value
|
||||
end
|
||||
|
||||
arr.each do |value|
|
||||
spec = nil
|
||||
if cellular.include?(value)
|
||||
spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Connectivité"), p_spec_value: PSpecValue.find_or_create_by(value: value))
|
||||
elsif video.include?(value)
|
||||
spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Résolution"), p_spec_value: PSpecValue.find_or_create_by(value: value))
|
||||
elsif power.include?(value)
|
||||
PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Puissance éléctrique"), p_spec_value: PSpecValue.find_or_create_by(value: value.gsub('W', ''), unit: "W"))
|
||||
elsif geoloc.include?(value)
|
||||
spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Géolocalisation"), p_spec_value: PSpecValue.find_or_create_by(value: value))
|
||||
else
|
||||
spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Autre"), p_spec_value: PSpecValue.find_or_create_by(value: value))
|
||||
end
|
||||
import_csv.import_csv_elements << ImportCsvElement.new(:element => spec)
|
||||
end
|
||||
|
||||
when "sim"
|
||||
if ["DS", "SS"].include?(value)
|
||||
PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Sim"), p_spec_value: PSpecValue.find_or_create_by(value: value))
|
||||
elsif value == "4G"
|
||||
PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Connectivité"), p_spec_value: PSpecValue.find_or_create_by(value: value))
|
||||
end
|
||||
|
||||
when "taille"
|
||||
PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Taille"), p_spec_value: PSpecValue.find_or_create_by(value: value.to_s))
|
||||
|
||||
when "capacite"
|
||||
|
||||
unit = value.match(/\D+/)
|
||||
num = value.match(/\d+/)
|
||||
spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Stockage"), p_spec_value: PSpecValue.find_or_create_by(value: num.to_s, unit: unit.to_s))
|
||||
import_csv.import_csv_elements << ImportCsvElement.new(:element => spec)
|
||||
when "infos_supp"
|
||||
|
||||
spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Autre"), p_spec_value: PSpecValue.find_or_create_by(value: value))
|
||||
import_csv.import_csv_elements << ImportCsvElement.new(:element => spec)
|
||||
when "reference_fabricant"
|
||||
|
||||
ref.manufacturer_ref = value
|
||||
when "etat"
|
||||
|
||||
ref.used_state = value
|
||||
when "code_hs"
|
||||
|
||||
ref.i_code_hs = value
|
||||
when "indice_reparabilite"
|
||||
|
||||
ref.prepair_score = value
|
||||
when "duree_dispo_pces_detachees"
|
||||
|
||||
when "das_tête"
|
||||
|
||||
ref.part_delay = value
|
||||
when "das_tete"
|
||||
ref.das_head = value
|
||||
when "das_corps"
|
||||
|
||||
ref.das_body = value
|
||||
when "das_membre"
|
||||
|
||||
ref.das_membre = value
|
||||
when "poids"
|
||||
|
||||
ref.weight = value
|
||||
when "nb_pcs_colis"
|
||||
|
||||
ref.nb_pcs_colis = value
|
||||
when "code_om"
|
||||
|
||||
when "dtl"
|
||||
|
||||
ref.code_om = value
|
||||
when "gbh_code_971"
|
||||
|
||||
ref.gbh_code_971 = value
|
||||
when "gbh_code_972"
|
||||
|
||||
ref.gbh_code_972 = value
|
||||
when "gbh_code_973"
|
||||
|
||||
ref.gbh_code_973 = value
|
||||
when "code_art"
|
||||
|
||||
ref.code_art = value
|
||||
when "sorecop"
|
||||
|
||||
ref.p_product.sorecop_cat = SorecopCat.find_by(name: soreco_cat_hash[row["famille"]])
|
||||
if ref.sorecop.kind_of?(String)
|
||||
ref.ct_sorecop = value
|
||||
end
|
||||
when "pmp_hors_sorecop"
|
||||
|
||||
ref.i_pmp_hors_sorecop = value
|
||||
when "target_hors_sorecop"
|
||||
|
||||
ref.i_target_hors_sorecop = value
|
||||
when "frs"
|
||||
|
||||
when "date"
|
||||
|
||||
ref.fournisseur_id = PFournisseur.find_or_create_by(name: value)
|
||||
when "spec"
|
||||
|
||||
when "dtl_targ"
|
||||
|
||||
spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Version ROM"), p_spec_value: PSpecValue.find_or_create_by(value: value))
|
||||
import_csv.import_csv_elements << ImportCsvElement.new(:element => spec)
|
||||
when "commentaires"
|
||||
|
||||
ref.i_comment = value
|
||||
# champs ignorés
|
||||
when "date"
|
||||
# colonne vide
|
||||
when "dtl_targ"
|
||||
when "dtl"
|
||||
when "com"
|
||||
|
||||
else
|
||||
# eval "n.#{key} = value"
|
||||
eval "n.#{key} = value"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -317,14 +373,14 @@ class PProduct < ApplicationRecord
|
||||
# n.save
|
||||
|
||||
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
# ap n
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ contact §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
# ap contact
|
||||
ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
ap n
|
||||
ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.ref §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
ap n.ref
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.contacts §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
@ -344,7 +400,7 @@ class PProduct < ApplicationRecord
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||
|
||||
# import_csv.import_csv_elements << ImportCsvElement.new(:element => n)
|
||||
import_csv.import_csv_elements << ImportCsvElement.new(:element => n)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user