p_fournisseur CSV+EXCEL import ok
This commit is contained in:
parent
e6ddcfe183
commit
0e33efd61a
@ -5,5 +5,5 @@ class PContact < ApplicationRecord
|
||||
has_many :p_contact_contact_types, :dependent => :destroy
|
||||
|
||||
has_many :p_contact_types, :through => :p_contact_contact_types
|
||||
|
||||
belongs_to :p_payment_type
|
||||
end
|
||||
|
@ -1,2 +1,81 @@
|
||||
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
|
||||
|
@ -1,7 +1,8 @@
|
||||
class PPaymentType < ApplicationRecord
|
||||
belongs_to :p_bank_account
|
||||
has_many :p_payments
|
||||
|
||||
has_many :p_fournisseurs
|
||||
|
||||
after_save do
|
||||
if self.p_bank_account
|
||||
self.p_payments.where(:remise => false).update_all(:p_bank_account_id => self.p_bank_account_id)
|
||||
|
@ -6,7 +6,7 @@
|
||||
= f.input :name, :label => "Nom de l'import :"
|
||||
= f.input :file, :label => "file :"
|
||||
|
||||
= f.input :table_name, :label => "Table :" , :as => :select, :collection => ["order_hist_lines"]
|
||||
= f.input :table_name, :label => "Type d'import :" , :as => :select, :collection => [["Base fournisseurs", "p_fournisseur"], ["Mise à jour catalogue prix","price_document"]]
|
||||
|
||||
-if f.object.id
|
||||
%table.import_csv_champs_form
|
||||
@ -23,4 +23,4 @@
|
||||
|
||||
|
||||
.actions=f.submit "sauvegarder", :class => "btn btn-primary"
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
.qi_header
|
||||
.right= link_to ic(:plus)+' Ajouter', new_admin_import_csv_path(), :class => "btn btn-primary btn-ap-add", :remote => true
|
||||
%h1
|
||||
%h1 Import xls
|
||||
|
||||
|
||||
|
||||
@ -12,4 +12,4 @@
|
||||
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @import_csvs}
|
||||
|
||||
|
||||
=debug OrderHistLine.new.class.type_for_attribute("ff")
|
||||
=debug OrderHistLine.new.class.type_for_attribute("ff")
|
||||
|
5
db/migrate/20211004161651_add_skype_to_p_contacts.rb
Normal file
5
db/migrate/20211004161651_add_skype_to_p_contacts.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddSkypeToPContacts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :p_contacts, :skype, :string
|
||||
end
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
class AddDetailsToPFournisseurs < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :p_fournisseurs, :payment_delais, :integer
|
||||
add_column :p_fournisseurs, :tva_num, :string
|
||||
add_column :p_fournisseurs, :p_payment_type_id, :integer
|
||||
add_column :p_fournisseurs, :iban, :string
|
||||
add_column :p_fournisseurs, :bic, :string
|
||||
end
|
||||
end
|
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_09_17_124338) do
|
||||
ActiveRecord::Schema.define(version: 2021_10_04_161753) do
|
||||
|
||||
create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
|
||||
t.string "name"
|
||||
@ -1164,6 +1164,7 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do
|
||||
t.string "contactable_type"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.string "skype"
|
||||
t.index ["contactable_id"], name: "index_p_contacts_on_contactable_id"
|
||||
end
|
||||
|
||||
@ -1463,6 +1464,11 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do
|
||||
t.string "compta_account"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.integer "payment_delais"
|
||||
t.string "tva_num"
|
||||
t.integer "p_payment_type_id"
|
||||
t.string "iban"
|
||||
t.string "bic"
|
||||
end
|
||||
|
||||
create_table "p_grades", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
|
||||
|
@ -9,7 +9,7 @@ module ActsAsCsvImport::Hook
|
||||
end
|
||||
|
||||
def self.import_csv(list, import_csv)
|
||||
puts self.instance_methods
|
||||
# puts self.instance_methods
|
||||
|
||||
if self.methods.include?(:custom_csv_import)
|
||||
custom_csv_import(list, import_csv)
|
||||
|
Reference in New Issue
Block a user