diff --git a/app/models/price_document.rb b/app/models/price_document.rb index 24fcc09..3fe9fe5 100644 --- a/app/models/price_document.rb +++ b/app/models/price_document.rb @@ -31,6 +31,7 @@ class PriceDocument < ApplicationRecord AVANCEMENT = ["0%", "25%", "50%", "75%", "100"] validates :public_fournisseur_name, :presence => true, :if => :public_fournisseur_name_needed? + acts_as_csv_import :fields => [:p_fournisseur_id, :p_product_ref] def public_fournisseur_name_needed? if self.label == "Réponse fournisseur" @@ -707,6 +708,59 @@ class PriceDocument < ApplicationRecord end + def self.custom_csv_import(list, import_csv) + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap list + ap list.class + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap import_csv + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + list.each do |row| + + n = self.new(price_document_type: PriceDocumentType.find_by_label("Catalogue fournisseur")) + # price_document = PriceDocument.new(price_document_type: PriceDocumentType.find_by_label("Catalogue fournisseur")) + contact_2 = nil + contact_3 = nil + 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(',', '.')" + # elsif key == "p_fournisseur_id" + # price_document.p_fournisseur = PFournisseur.find(key) + # elsif key == "p_contact_comment" + # contact_1.p_contact_types << PContactType.find_or_create_by(name: value) + # elsif key == "p_contact_tel" + # contact_1.tel = value + # elsif key == "p_contact_skype" + # contact_1.skype = value + # elsif key == "p_contact_email_1" + # contact_1.email = value + # elsif key == "p_contact_email_2" + # contact_2 = PContact.new(email: value) + # elsif key == "p_contact_email_3" + # contact_3 = PContact.new(email: value) + # elsif key == "p_payment_type" + # n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + else + eval "n.#{key} = value" + end + + end + # particular.organisation = self.name + # n.save + ap n + # n.p_contacts << contact_1 if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email) + # n.p_contacts << contact_2 if contact_2 + # n.p_contacts << contact_3 if contact_3 + # import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + end + end end