Module: NextErpBridge::Core::Entry::ClassMethods
- Defined in:
- lib/next_erp_bridge/core/entry.rb
Instance Method Summary collapse
- #all(limit_start = 0, limit_page_length = 0, do_login = true) ⇒ Object
-
#before_action(c = {login: true}) ⇒ Object
All methods call this so that we can do a login before we actually start CRUD in the ERP As of now for every call it is calling login which is bad TODO: Need to change this to, login when session expires.
- #client ⇒ Object
- #create(attrs) ⇒ Object
- #doctype ⇒ Object
- #encoded_doctype ⇒ Object
- #find(id, do_login = true) ⇒ Object
- #find_by(params) ⇒ Object
Instance Method Details
#all(limit_start = 0, limit_page_length = 0, do_login = true) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/next_erp_bridge/core/entry.rb', line 49 def all(limit_start=0, limit_page_length=0, do_login=true) before_action(login: do_login) res = client.fetch({doctype: encoded_doctype}, [ ], ["*"], limit_start, limit_page_length) if res['data'].present? res['data'].map { | r | self.new(r) } else [ ] end end |
#before_action(c = {login: true}) ⇒ Object
All methods call this so that we can do a login before we actually start CRUD in the ERP As of now for every call it is calling login which is bad TODO: Need to change this to, login when session expires
20 21 22 |
# File 'lib/next_erp_bridge/core/entry.rb', line 20 def before_action(c={login: true}) Client.instance.login if c[:login] end |
#client ⇒ Object
24 25 26 |
# File 'lib/next_erp_bridge/core/entry.rb', line 24 def client Client.instance.frappe_client end |
#create(attrs) ⇒ Object
36 37 38 39 40 |
# File 'lib/next_erp_bridge/core/entry.rb', line 36 def create(attrs) before_action a = attrs.merge({ doctype: encoded_doctype }) Util.instance_create(self, client.insert(a), a) end |
#doctype ⇒ Object
28 29 30 |
# File 'lib/next_erp_bridge/core/entry.rb', line 28 def doctype @doctype end |
#encoded_doctype ⇒ Object
32 33 34 |
# File 'lib/next_erp_bridge/core/entry.rb', line 32 def encoded_doctype doctype end |
#find(id, do_login = true) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/next_erp_bridge/core/entry.rb', line 42 def find(id, do_login=true) before_action(login: do_login) res = client.fetch_single_record({doctype: encoded_doctype, id: id}) d = res['data'] self.new(d) if d.present? end |
#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 |