refacto import
This commit is contained in:
parent
906e101881
commit
8f92692d79
@ -4,27 +4,27 @@ class PFournisseur < ApplicationRecord
|
|||||||
has_many :p_fournisseur_refs
|
has_many :p_fournisseur_refs
|
||||||
|
|
||||||
acts_as_csv_import :fields => [
|
acts_as_csv_import :fields => [
|
||||||
:name,
|
:nom_fournisseur,
|
||||||
:address1,
|
:address,
|
||||||
:cp,
|
:cp,
|
||||||
:city,
|
:ville,
|
||||||
:country,
|
:pays,
|
||||||
:email,
|
:tva_intracom,
|
||||||
|
:delai_paiement,
|
||||||
|
:interlocuteur,
|
||||||
|
:fonction,
|
||||||
:tel,
|
:tel,
|
||||||
:p_contact_name,
|
:skype,
|
||||||
:p_contact_comment,
|
:email_1,
|
||||||
:p_contact_tel,
|
:email_2,
|
||||||
:p_contact_skype,
|
:email_3,
|
||||||
:p_contact_email_1,
|
|
||||||
:p_contact_email_2,
|
|
||||||
:p_contact_email_3,
|
|
||||||
:bic,
|
|
||||||
:iban,
|
:iban,
|
||||||
:payment_delais,
|
:bic,
|
||||||
:tva_num,
|
:reglement_par
|
||||||
:p_payment_type
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def self.custom_csv_import(list, import_csv)
|
def self.custom_csv_import(list, import_csv)
|
||||||
# ap "*********************************************************************************************************"
|
# ap "*********************************************************************************************************"
|
||||||
# ap "*********************************************************************************************************"
|
# ap "*********************************************************************************************************"
|
||||||
@ -50,33 +50,86 @@ class PFournisseur < ApplicationRecord
|
|||||||
|
|
||||||
if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal
|
if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal
|
||||||
eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')"
|
eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')"
|
||||||
elsif key == "p_contact_name"
|
|
||||||
contact_1.name = value
|
|
||||||
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
|
else
|
||||||
eval "n.#{key} = value"
|
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
|
||||||
|
when "fonction"
|
||||||
|
contact_1.p_contact_types << PContactType.find_or_create_by(name: value)
|
||||||
|
when "tel"
|
||||||
|
contact_1.tel = value
|
||||||
|
when "skype"
|
||||||
|
contact_1.skype = value
|
||||||
|
when "email_1"
|
||||||
|
contact_1.email = value
|
||||||
|
when "email_2"
|
||||||
|
contact_2 = PContact.new(email: value)
|
||||||
|
when "email_3"
|
||||||
|
contact_3 = PContact.new(email: value)
|
||||||
|
when "reglement_par"
|
||||||
|
n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id
|
||||||
|
else
|
||||||
|
eval "n.#{key} = value"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
# particular.organisation = self.name
|
# particular.organisation = self.name
|
||||||
n.save
|
n.save
|
||||||
n.p_contacts << contact_1 if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email)
|
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_1
|
||||||
n.p_contacts << contact_3 if contact_3
|
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)
|
import_csv.import_csv_elements << ImportCsvElement.new(:element => n)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user