WIP import csv p_product
This commit is contained in:
parent
c3cc3b63ca
commit
e313408aef
@ -166,4 +166,185 @@ class PProduct < ApplicationRecord
|
|||||||
self.p_product_images.order(:position).first
|
self.p_product_images.order(:position).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
acts_as_csv_import :fields => [
|
||||||
|
:gencode,
|
||||||
|
:id,
|
||||||
|
:marque,
|
||||||
|
:famille,
|
||||||
|
:reference,
|
||||||
|
:modele,
|
||||||
|
:couleur,
|
||||||
|
:color,
|
||||||
|
:connectivite,
|
||||||
|
:sim,
|
||||||
|
:taille,
|
||||||
|
:capacite,
|
||||||
|
:infos_supp,
|
||||||
|
:reference_fabricant,
|
||||||
|
:etat,
|
||||||
|
:code_hs,
|
||||||
|
:indice_reparabilite,
|
||||||
|
:duree_dispo_pces_detachees,
|
||||||
|
:das_tête,
|
||||||
|
:das_corps,
|
||||||
|
:das_membre,
|
||||||
|
:poids,
|
||||||
|
:nb_pcs_colis,
|
||||||
|
:code_om,
|
||||||
|
:dtl,
|
||||||
|
:gbh_code_971,
|
||||||
|
:gbh_code_972,
|
||||||
|
:gbh_code_973,
|
||||||
|
:code_art,
|
||||||
|
:sorecop,
|
||||||
|
:pmp_hors_sorecop,
|
||||||
|
:target_hors_sorecop,
|
||||||
|
:frs,
|
||||||
|
:date,
|
||||||
|
:spec,
|
||||||
|
:dtl_targ,
|
||||||
|
:commentaires,
|
||||||
|
:com
|
||||||
|
]
|
||||||
|
|
||||||
|
def self.custom_csv_import(list, import_csv)
|
||||||
|
# ap "*********************************************************************************************************"
|
||||||
|
# ap "*********************************************************************************************************"
|
||||||
|
ap "*********************************************************************************************************"
|
||||||
|
ap list.size
|
||||||
|
# ap list.class
|
||||||
|
# ap "*********************************************************************************************************"
|
||||||
|
# ap "*********************************************************************************************************"
|
||||||
|
# ap "*********************************************************************************************************"
|
||||||
|
# ap import_csv
|
||||||
|
# ap "*********************************************************************************************************"
|
||||||
|
# ap "*********************************************************************************************************"
|
||||||
|
# ap "*********************************************************************************************************"
|
||||||
|
|
||||||
|
list.each do |row|
|
||||||
|
next if row["marque"].blank?
|
||||||
|
|
||||||
|
n = self.new(imported: true)
|
||||||
|
|
||||||
|
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 "gencode"
|
||||||
|
|
||||||
|
when "id"
|
||||||
|
|
||||||
|
when "marque"
|
||||||
|
|
||||||
|
when "famille"
|
||||||
|
n.p_product_cat = PProductCat.find_or_create_by(name: value)
|
||||||
|
|
||||||
|
when "reference"
|
||||||
|
|
||||||
|
when "modele"
|
||||||
|
|
||||||
|
when "couleur"
|
||||||
|
|
||||||
|
when "color"
|
||||||
|
|
||||||
|
when "connectivite"
|
||||||
|
|
||||||
|
when "sim"
|
||||||
|
|
||||||
|
when "taille"
|
||||||
|
|
||||||
|
when "capacite"
|
||||||
|
|
||||||
|
when "infos_supp"
|
||||||
|
|
||||||
|
when "reference_fabricant"
|
||||||
|
|
||||||
|
when "etat"
|
||||||
|
|
||||||
|
when "code_hs"
|
||||||
|
|
||||||
|
when "indice_reparabilite"
|
||||||
|
|
||||||
|
when "duree_dispo_pces_detachees"
|
||||||
|
|
||||||
|
when "das_tête"
|
||||||
|
|
||||||
|
when "das_corps"
|
||||||
|
|
||||||
|
when "das_membre"
|
||||||
|
|
||||||
|
when "poids"
|
||||||
|
|
||||||
|
when "nb_pcs_colis"
|
||||||
|
|
||||||
|
when "code_om"
|
||||||
|
|
||||||
|
when "dtl"
|
||||||
|
|
||||||
|
when "gbh_code_971"
|
||||||
|
|
||||||
|
when "gbh_code_972"
|
||||||
|
|
||||||
|
when "gbh_code_973"
|
||||||
|
|
||||||
|
when "code_art"
|
||||||
|
|
||||||
|
when "sorecop"
|
||||||
|
|
||||||
|
when "pmp_hors_sorecop"
|
||||||
|
|
||||||
|
when "target_hors_sorecop"
|
||||||
|
|
||||||
|
when "frs"
|
||||||
|
|
||||||
|
when "date"
|
||||||
|
|
||||||
|
when "spec"
|
||||||
|
|
||||||
|
when "dtl_targ"
|
||||||
|
|
||||||
|
when "commentaires"
|
||||||
|
|
||||||
|
when "com"
|
||||||
|
|
||||||
|
else
|
||||||
|
# eval "n.#{key} = value"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# n.save
|
||||||
|
|
||||||
|
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap n
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ contact §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap contact
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.contacts §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap n.p_contacts
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.particulars §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap n.particulars
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.p_customer_ribs §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap n.p_customer_ribs
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.p_commercial §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap n.p_commercial
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
|
||||||
|
|
||||||
|
# import_csv.import_csv_elements << ImportCsvElement.new(:element => n)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user