This repository has been archived on 2021-11-24. You can view files and clone it, but cannot push or open issues or pull requests.
phone_app/app/models/p_fournisseur.rb

82 lines
3.1 KiB
Ruby

class PFournisseur < ApplicationRecord
# has_many :particulars, :as => :owner, :dependent => :destroy
has_many :p_contacts, :as => :contactable, :dependent => :destroy
acts_as_csv_import :fields => [
:name,
:address1,
:cp,
:city,
:country,
:email,
: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,
:iban,
:payment_delais,
:tva_num,
:p_payment_type
]
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
# particular = Particular.new(pro: true)
contact_1 = PContact.new
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_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
eval "n.#{key} = value"
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
# import_csv.import_csv_elements << ImportCsvElement.new(:element => n)
end
end
end