Method: NextErpBridge::Core::Entry::ClassMethods#find_by

Defined in:
lib/next_erp_bridge/core/entry.rb

#find_by(params) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/next_erp_bridge/core/entry.rb', line 59

def find_by(params)
  before_action
  filters = [[doctype]]
  params.each { | k, v | filters[0].concat([k.to_s, '=', v]) }
  res = client.fetch({ doctype: encoded_doctype }, filters)
  data = res['data']
  if data.present?
    find(data.first['name'], false)
  else
    data
  end
end