Class: SolidusTiny::Seller
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- SolidusTiny::Seller
- Defined in:
- app/models/solidus_tiny/seller.rb
Class Method Summary collapse
- .actives ⇒ Object
- .default ⇒ Object
- .inactivate_sellers(sellers_tiny) ⇒ Object
- .upsert_sellers(account) ⇒ Object
Instance Method Summary collapse
Class Method Details
.actives ⇒ Object
35 36 37 |
# File 'app/models/solidus_tiny/seller.rb', line 35 def self.actives where(active: true) end |
.default ⇒ Object
31 32 33 |
# File 'app/models/solidus_tiny/seller.rb', line 31 def self.default find_by(default: true) end |
.inactivate_sellers(sellers_tiny) ⇒ Object
39 40 41 |
# File 'app/models/solidus_tiny/seller.rb', line 39 def self.inactivate_sellers sellers_tiny where.not(external_id: sellers_tiny.pluck(:id)).update_all(active: false) end |
.upsert_sellers(account) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/solidus_tiny/seller.rb', line 10 def self.upsert_sellers account client = SolidusTiny::TinyClient.for_account(account) response = client.get_sellers(1) total_pages = (response.paginacao.total / 100.0).ceil upsert_sellers = [] 0.upto(total_pages - 1) do |page| response = client.get_sellers(100, (page * 100)) response.itens.map do |seller| upsert_sellers << { name: seller.contato.nome, external_id: seller.id, account_id: account.id, active: seller.situacao == "A" ? true : false } end SolidusTiny::Seller.upsert_all(upsert_sellers, unique_by: :external_id) inactivate_sellers(response.itens) end end |
Instance Method Details
#falsify_all_others ⇒ Object
43 44 45 46 47 |
# File 'app/models/solidus_tiny/seller.rb', line 43 def falsify_all_others if default self.class.where('id != ?', self.id).update_all(default: false) end end |