From 6ed30defc6ce5dd1dc17718c06ff678faf5a5a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 16:18:06 +0200 Subject: [PATCH] bugfix import --- app/models/p_customer.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index 54900d5..23c9012 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -732,12 +732,16 @@ class PCustomer < ApplicationRecord n.payment_delais = 0 when "30 JOURS FIN DE MOIS" n.payment_delais = 30 + n.comptant = false when "VIR 60J NET DATE RELEVE" n.payment_delais = 60 + n.comptant = false when "TRAITE A 60 JOURS FIN DE MOIS" n.payment_delais = 60 + n.comptant = false when "Mensuel - 30j fin de mois du dépôt" n.payment_delais = 30 + n.comptant = false else n.payment_delais = value if !value.blank? end @@ -860,20 +864,22 @@ class PCustomer < ApplicationRecord n.particulars << particular_bill - n.save + n.save! if bank bank.bic = bic bank.particulars << bank_particular if bank_particular.address_1 - bank.save + bank.save! import_csv.import_csv_elements << ImportCsvElement.new(:element => bank) end if bic || iban - rib = PCustomerRib.create(bic: bic, iban: iban) + rib = PCustomerRib.find_or_create_by!(bic: bic, iban: iban) rib.bank = bank.name if bank - account = PBankAccount.create(bic: bic, iban: iban, p_bank: bank, p_customer: n) + account = PBankAccount.find_or_create_by!(bic: bic, iban: iban, p_customer: n) + account.update(p_bank: bank) if bank + n.p_customer_ribs << rib import_csv.import_csv_elements << ImportCsvElement.new(:element => rib) import_csv.import_csv_elements << ImportCsvElement.new(:element => account) @@ -882,6 +888,7 @@ class PCustomer < ApplicationRecord if p_commercial_code || p_commercial_firstname p_commercial = PCommercial.find_or_create_by!(code: p_commercial_code, firstname: p_commercial_firstname) n.p_commercial = p_commercial + import_csv.import_csv_elements << ImportCsvElement.new(:element => p_commercial) end if send_tel || send_tel2 || send_fax || send_address_2