refacto import
This commit is contained in:
parent
906e101881
commit
8f92692d79
@ -4,27 +4,27 @@ class PFournisseur < ApplicationRecord
|
||||
has_many :p_fournisseur_refs
|
||||
|
||||
acts_as_csv_import :fields => [
|
||||
:name,
|
||||
:address1,
|
||||
:nom_fournisseur,
|
||||
:address,
|
||||
:cp,
|
||||
:city,
|
||||
:country,
|
||||
:email,
|
||||
:ville,
|
||||
:pays,
|
||||
:tva_intracom,
|
||||
:delai_paiement,
|
||||
:interlocuteur,
|
||||
:fonction,
|
||||
:tel,
|
||||
:p_contact_name,
|
||||
:p_contact_comment,
|
||||
:p_contact_tel,
|
||||
:p_contact_skype,
|
||||
:p_contact_email_1,
|
||||
:p_contact_email_2,
|
||||
:p_contact_email_3,
|
||||
:bic,
|
||||
:skype,
|
||||
:email_1,
|
||||
:email_2,
|
||||
:email_3,
|
||||
:iban,
|
||||
:payment_delais,
|
||||
:tva_num,
|
||||
:p_payment_type
|
||||
:bic,
|
||||
:reglement_par
|
||||
]
|
||||
|
||||
|
||||
|
||||
def self.custom_csv_import(list, import_csv)
|
||||
# ap "*********************************************************************************************************"
|
||||
# ap "*********************************************************************************************************"
|
||||
@ -50,33 +50,86 @@ class PFournisseur < ApplicationRecord
|
||||
|
||||
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_contact_name"
|
||||
else
|
||||
case key
|
||||
when "nom_fournisseur"
|
||||
n.name = value
|
||||
when "address"
|
||||
n.address1 = value
|
||||
when "ville"
|
||||
n.city = value
|
||||
when "pays"
|
||||
n.country = value
|
||||
when "tva_intracom"
|
||||
n.tva_num = value
|
||||
when "delai_paiement"
|
||||
next if value.nil?
|
||||
case value
|
||||
when "A la commande"
|
||||
n.payment_delais = 0
|
||||
when "A réception"
|
||||
n.payment_delais = 0
|
||||
when "7 jours net"
|
||||
n.payment_delais = 7
|
||||
when "21 jours net"
|
||||
n.payment_delais = 21
|
||||
when "30 jours"
|
||||
n.payment_delais = 30
|
||||
when "30 jours net"
|
||||
n.payment_delais = 30
|
||||
when "30 jours fin de mois"
|
||||
n.payment_delais = 30
|
||||
when "35 jours net"
|
||||
n.payment_delais = 35
|
||||
when "40 jours net"
|
||||
n.payment_delais = 40
|
||||
when "60 jours net"
|
||||
n.payment_delais = 60
|
||||
when "60 jours fin de mois"
|
||||
n.payment_delais = 60
|
||||
else
|
||||
n.payment_delais = value
|
||||
end
|
||||
when "interlocuteur"
|
||||
contact_1.name = value
|
||||
elsif key == "p_contact_comment"
|
||||
when "fonction"
|
||||
contact_1.p_contact_types << PContactType.find_or_create_by(name: value)
|
||||
elsif key == "p_contact_tel"
|
||||
when "tel"
|
||||
contact_1.tel = value
|
||||
elsif key == "p_contact_skype"
|
||||
when "skype"
|
||||
contact_1.skype = value
|
||||
elsif key == "p_contact_email_1"
|
||||
when "email_1"
|
||||
contact_1.email = value
|
||||
elsif key == "p_contact_email_2"
|
||||
when "email_2"
|
||||
contact_2 = PContact.new(email: value)
|
||||
elsif key == "p_contact_email_3"
|
||||
when "email_3"
|
||||
contact_3 = PContact.new(email: value)
|
||||
elsif key == "p_payment_type"
|
||||
when "reglement_par"
|
||||
n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id
|
||||
else
|
||||
eval "n.#{key} = value"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
# particular.organisation = self.name
|
||||
n.save
|
||||
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
|
||||
if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email)
|
||||
n.p_contacts << contact_1
|
||||
import_csv.import_csv_elements << ImportCsvElement.new(:element => contact_1)
|
||||
end
|
||||
if contact_2
|
||||
n.p_contacts << contact_2
|
||||
import_csv.import_csv_elements << ImportCsvElement.new(:element => contact_2)
|
||||
end
|
||||
|
||||
if contact_3
|
||||
n.p_contacts << contact_3
|
||||
import_csv.import_csv_elements << ImportCsvElement.new(:element => contact_3)
|
||||
end
|
||||
|
||||
import_csv.import_csv_elements << ImportCsvElement.new(:element => n)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user