Module: UserExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/user_extensions.rb
Instance Method Summary collapse
- #mesonic_account_number ⇒ Object
-
#push_to_mesonic ⇒ Object
— Instance Methods — #.
- #update_erp_account_nr ⇒ Object
- #update_mesonic(billing_address: self.billing_addresses.first) ⇒ Object
Instance Method Details
#mesonic_account_number ⇒ Object
72 73 74 |
# File 'app/models/user_extensions.rb', line 72 def mesonic_account_number "%06d" % self.erp_account_nr[0..-11] # ...it is actually a string and may contain 1I for potential buyers end |
#push_to_mesonic ⇒ Object
— Instance Methods — #
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/user_extensions.rb', line 36 def push_to_mesonic @timestamp = Time.now @kontonummer = MercatorMesonic::Kontenstamm.next_kontonummer @kontaktenummer = MercatorMesonic::KontakteStamm.next_kontaktenummer @mesonic_kontakte_stamm = MercatorMesonic::KontakteStamm.initialize_mesonic(user: self, kontonummer: @kontonummer, kontaktenummer: @kontaktenummer) @mesonic_kontenstamm = MercatorMesonic::Kontenstamm.initialize_mesonic(user: self, kontonummer: @kontonummer, timestamp: @timestamp) @mesonic_kontenstamm_fakt = MercatorMesonic::KontenstammFakt.initialize_mesonic(kontonummer: @kontonummer, email: self.email_address) @mesonic_kontenstamm_fibu = MercatorMesonic::KontenstammFibu.initialize_mesonic(kontonummer: @kontonummer) @mesonic_kontenstamm_adresse = MercatorMesonic::KontenstammAdresse.initialize_mesonic(billing_address: self.billing_addresses.first, kontonummer: @kontonummer) if [@mesonic_kontakte_stamm, @mesonic_kontenstamm, @mesonic_kontenstamm_adresse, @mesonic_kontenstamm_fibu, @mesonic_kontenstamm_fakt ].collect(&:valid?).all? [@mesonic_kontakte_stamm, @mesonic_kontenstamm, @mesonic_kontenstamm_adresse, @mesonic_kontenstamm_fibu, @mesonic_kontenstamm_fakt ].collect(&:save).all? end self.update(erp_account_nr: User.mesoprim(number: @kontonummer), erp_contact_nr: User.mesoprim(number: @kontaktenummer) ) end |
#update_erp_account_nr ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/user_extensions.rb', line 76 def update_erp_account_nr # We want to fix the local database entry for erp_account_nr if someone changed the Account on mesonic side, # e.g. if the potential customer ('Interessent') was changed to an actual customer accout. if self.erp_contact_nr && !self.mesonic_kontenstamm && self.mesonic_kontakte_stamm mesonic_kontenstamm = MercatorMesonic::Kontenstamm.where(c002: self.mesonic_kontakte_stamm.c039).first if self.update(erp_account_nr: mesonic_kontenstamm.mesoprim) ::JobLogger.info("Updated user " + self.id.to_s + "'s erp account number to " + self.erp_account_nr) else ::JobLogger.error("Error updating user" + self.id.to_s + "'s erp account number") end end end |
#update_mesonic(billing_address: self.billing_addresses.first) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/user_extensions.rb', line 60 def update_mesonic(billing_address: self.billing_addresses.first) mesonic_kontenstamm_adresse = MercatorMesonic::KontenstammAdresse.where(mesoprim: self.erp_account_nr).first mesonic_kontenstamm_adresse.update(c050: billing_address.street, c051: billing_address.postalcode, c052: billing_address.city, c053: billing_address.c_o, c123: billing_address.country, c181: billing_address.name.split(/\s/).last, c116: billing_address.email_address.to_s) end |