Commit e36b8276 authored by ryanss's avatar ryanss
Browse files

Fix initializing SugarObject with custom module

Close #1
parent d37a0395
......@@ -115,7 +115,7 @@ class Session:
entry_list = results['entry_list']
ret = []
for i, result in enumerate(entry_list):
obj = SugarObject(module=q.module)
obj = SugarObject(module=q.module, __class__=q.__class__)
for key in result['name_value_list']:
setattr(obj, key, result['name_value_list'][key]['value'])
if results['relationship_list']:
......@@ -276,8 +276,11 @@ class SugarObject:
for key, value in kwargs.items():
setattr(self, key, value)
if key == "module":
cls = value[:-1].replace('ie','y').title()
self.__class__ = getattr(sys.modules['sugarcrm'], cls)
try:
cls = value[:-1].replace('ie','y').title()
self.__class__ = getattr(sys.modules['sugarcrm'], cls)
except:
pass
@property
def fields(self):
......@@ -362,5 +365,9 @@ class Report(SugarObject):
module = "Reports"
class User(SugarObject):
module = "Users"
class SugarError(Exception):
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment