You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

729 line
22 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. from __future__ import unicode_literals
  23. """
  24. Contains the Document class representing an object / record
  25. """
  26. import webnotes
  27. import webnotes.model.meta
  28. from webnotes.utils import *
  29. class Document:
  30. """
  31. The wn(meta-data)framework equivalent of a Database Record.
  32. Stores,Retrieves,Updates the record in the corresponding table.
  33. Runs the triggers required.
  34. The `Document` class represents the basic Object-Relational Mapper (ORM). The object type is defined by
  35. `DocType` and the object ID is represented by `name`::
  36. Please note the anamoly in the Web Notes Framework that `ID` is always called as `name`
  37. If both `doctype` and `name` are specified in the constructor, then the object is loaded from the database.
  38. If only `doctype` is given, then the object is not loaded
  39. If `fielddata` is specfied, then the object is created from the given dictionary.
  40. **Note 1:**
  41. The getter and setter of the object are overloaded to map to the fields of the object that
  42. are loaded when it is instantiated.
  43. For example: doc.name will be the `name` field and doc.owner will be the `owner` field
  44. **Note 2 - Standard Fields:**
  45. * `name`: ID / primary key
  46. * `owner`: creator of the record
  47. * `creation`: datetime of creation
  48. * `modified`: datetime of last modification
  49. * `modified_by` : last updating user
  50. * `docstatus` : Status 0 - Saved, 1 - Submitted, 2- Cancelled
  51. * `parent` : if child (table) record, this represents the parent record
  52. * `parenttype` : type of parent record (if any)
  53. * `parentfield` : table fieldname of parent record (if any)
  54. * `idx` : Index (sequence) of the child record
  55. """
  56. def __init__(self, doctype = '', name = '', fielddata = {}, prefix='tab'):
  57. self._roles = []
  58. self._perms = []
  59. self._user_defaults = {}
  60. self._prefix = prefix
  61. if fielddata:
  62. self.fields = webnotes.DictObj(fielddata)
  63. else:
  64. self.fields = webnotes.DictObj()
  65. if not self.fields.has_key('name'):
  66. self.fields['name']='' # required on save
  67. if not self.fields.has_key('doctype'):
  68. self.fields['doctype']='' # required on save
  69. if not self.fields.has_key('owner'):
  70. self.fields['owner']='' # required on save
  71. if doctype:
  72. self.fields['doctype'] = doctype
  73. if name:
  74. self.fields['name'] = name
  75. self.__initialized = 1
  76. if (doctype and name):
  77. self._loadfromdb(doctype, name)
  78. else:
  79. if not fielddata:
  80. self.fields['__islocal'] = 1
  81. if not self.fields.docstatus:
  82. self.fields.docstatus = 0
  83. def __nonzero__(self):
  84. return True
  85. def __str__(self):
  86. return str(self.fields)
  87. # Load Document
  88. # ---------------------------------------------------------------------------
  89. def encode(self, encoding='utf-8'):
  90. """convert all unicode values to utf-8"""
  91. for key in self.fields:
  92. if isinstance(self.fields[key], unicode):
  93. self.fields[key] = self.fields[key].encode(encoding)
  94. def _loadfromdb(self, doctype = None, name = None):
  95. if name: self.name = name
  96. if doctype: self.doctype = doctype
  97. is_single = False
  98. try:
  99. is_single = webnotes.model.meta.is_single(self.doctype)
  100. except Exception, e:
  101. pass
  102. if is_single:
  103. self._loadsingle()
  104. else:
  105. dataset = webnotes.conn.sql('select * from `%s%s` where name="%s"' % (self._prefix, self.doctype, self.name.replace('"', '\"')))
  106. if not dataset:
  107. raise Exception, '[WNF] %s %s does not exist' % (self.doctype, self.name)
  108. self._load_values(dataset[0], webnotes.conn.get_description())
  109. # Load Fields from dataset
  110. # ---------------------------------------------------------------------------
  111. def _load_values(self, data, description):
  112. if '__islocal' in self.fields:
  113. del self.fields['__islocal']
  114. for i in range(len(description)):
  115. v = data[i]
  116. self.fields[description[i][0]] = webnotes.conn.convert_to_simple_type(v)
  117. def _merge_values(self, data, description):
  118. for i in range(len(description)):
  119. v = data[i]
  120. if v: # only if value, over-write
  121. self.fields[description[i][0]] = webnotes.conn.convert_to_simple_type(v)
  122. # Load Single Type
  123. # ---------------------------------------------------------------------------
  124. def _loadsingle(self):
  125. self.name = self.doctype
  126. self.fields.update(getsingle(self.doctype))
  127. # Setter
  128. # ---------------------------------------------------------------------------
  129. def __setattr__(self, name, value):
  130. # normal attribute
  131. if not self.__dict__.has_key('_Document__initialized'):
  132. self.__dict__[name] = value
  133. elif self.__dict__.has_key(name):
  134. self.__dict__[name] = value
  135. else:
  136. # field attribute
  137. f = self.__dict__['fields']
  138. f[name] = value
  139. # Getter
  140. # ---------------------------------------------------------------------------
  141. def __getattr__(self, name):
  142. if self.__dict__.has_key(name):
  143. return self.__dict__[name]
  144. elif self.fields.has_key(name):
  145. return self.fields[name]
  146. else:
  147. return ''
  148. # Get Amendement number
  149. # ---------------------------------------------------------------------------
  150. def _get_amended_name(self):
  151. am_id = 1
  152. am_prefix = self.amended_from
  153. if webnotes.conn.sql('select amended_from from `tab%s` where name = "%s"' % (self.doctype, self.amended_from))[0][0] or '':
  154. am_id = cint(self.amended_from.split('-')[-1]) + 1
  155. am_prefix = '-'.join(self.amended_from.split('-')[:-1]) # except the last hyphen
  156. self.name = am_prefix + '-' + str(am_id)
  157. # Set Name
  158. # ---------------------------------------------------------------------------
  159. def _set_name(self, autoname, istable):
  160. self.localname = self.name
  161. # get my object
  162. import webnotes.model.code
  163. so = webnotes.model.code.get_server_obj(self, [])
  164. # amendments
  165. if self.amended_from:
  166. self._get_amended_name()
  167. # by method
  168. elif so and hasattr(so, 'autoname'):
  169. r = webnotes.model.code.run_server_obj(so, 'autoname')
  170. if r: return r
  171. # based on a field
  172. elif autoname and autoname.startswith('field:'):
  173. n = self.fields[autoname[6:]]
  174. if not n:
  175. raise Exception, 'Name is required'
  176. self.name = n.strip()
  177. # based on expression
  178. elif autoname and autoname.startswith('eval:'):
  179. doc = self # for setting
  180. self.name = eval(autoname[5:])
  181. # call the method!
  182. elif autoname and autoname!='Prompt':
  183. self.name = make_autoname(autoname, self.doctype)
  184. # given
  185. elif self.fields.get('__newname',''):
  186. self.name = self.fields['__newname']
  187. # default name for table
  188. elif istable:
  189. self.name = make_autoname('#########', self.doctype)
  190. # unable to determine a name, use a serial number!
  191. if not self.name:
  192. self.name = make_autoname('#########', self.doctype)
  193. # Validate Name
  194. # ---------------------------------------------------------------------------
  195. def _validate_name(self, case):
  196. if webnotes.conn.sql('select name from `tab%s` where name=%s' % (self.doctype,'%s'), self.name):
  197. raise NameError, 'Name %s already exists' % self.name
  198. # no name
  199. if not self.name: return 'No Name Specified for %s' % self.doctype
  200. # new..
  201. if self.name.startswith('New '+self.doctype):
  202. return 'There were some errors setting the name, please contact the administrator'
  203. if case=='Title Case': self.name = self.name.title()
  204. if case=='UPPER CASE': self.name = self.name.upper()
  205. self.name = self.name.strip() # no leading and trailing blanks
  206. forbidden = ['%', "'", '"', '#', '*', '?', '`']
  207. for f in forbidden:
  208. if f in self.name:
  209. webnotes.msgprint('%s not allowed in ID (name)' % f, raise_exception =1)
  210. # Insert
  211. # ---------------------------------------------------------------------------
  212. def insert(self, autoname, istable, case='', make_autoname=1):
  213. # set name
  214. if make_autoname:
  215. self._set_name(autoname, istable)
  216. # validate name
  217. self._validate_name(case)
  218. # insert!
  219. if not self.owner: self.owner = webnotes.session['user']
  220. self.modified_by = webnotes.session['user']
  221. self.creation = self.modified = now()
  222. webnotes.conn.sql("""insert into `tab%(doctype)s` (name, owner, creation, modified, modified_by)
  223. values ('%(name)s', '%(owner)s', '%(creation)s', '%(modified)s', '%(modified_by)s')""" % self.fields)
  224. # Update Values
  225. # ---------------------------------------------------------------------------
  226. def _update_single(self, link_list):
  227. update_str = ["(%s, 'modified', %s)",]
  228. values = [self.doctype, now()]
  229. webnotes.conn.sql("delete from tabSingles where doctype='%s'" % self.doctype)
  230. for f in self.fields.keys():
  231. if not (f in ('modified', 'doctype', 'name', 'perm', 'localname', 'creation'))\
  232. and (not f.startswith('__')): # fields not saved
  233. # validate links
  234. if link_list and link_list.get(f):
  235. self.fields[f] = self._validate_link(link_list[f][0], self.fields[f])
  236. if self.fields[f]==None:
  237. update_str.append("(%s,%s,NULL)")
  238. values.append(self.doctype)
  239. values.append(f)
  240. else:
  241. update_str.append("(%s,%s,%s)")
  242. values.append(self.doctype)
  243. values.append(f)
  244. values.append(self.fields[f])
  245. webnotes.conn.sql("insert into tabSingles(doctype, field, value) values %s" % (', '.join(update_str)), values)
  246. # Validate Links
  247. # ---------------------------------------------------------------------------
  248. def validate_links(self, link_list):
  249. err_list = []
  250. for f in self.fields.keys():
  251. # validate links
  252. old_val = self.fields[f]
  253. if link_list and link_list.get(f):
  254. self.fields[f] = self._validate_link(link_list[f][0], self.fields[f])
  255. if old_val and not self.fields[f]:
  256. s = link_list[f][1] + ': ' + old_val
  257. err_list.append(s)
  258. return err_list
  259. def make_link_list(self):
  260. res = webnotes.model.meta.get_link_fields(self.doctype)
  261. link_list = {}
  262. for i in res: link_list[i[0]] = (i[1], i[2]) # options, label
  263. return link_list
  264. def _validate_link(self, dt, dn):
  265. if not dt: return dn
  266. if not dn: return None
  267. if dt.lower().startswith('link:'):
  268. dt = dt[5:]
  269. if '\n' in dt:
  270. dt = dt.split('\n')[0]
  271. tmp = webnotes.conn.sql("""SELECT name FROM `tab%s`
  272. WHERE name = %s""" % (dt, '%s'), dn)
  273. return tmp and tmp[0][0] or ''# match case
  274. # Update query
  275. # ---------------------------------------------------------------------------
  276. def _update_values(self, issingle, link_list, ignore_fields=0):
  277. if issingle:
  278. self._update_single(link_list)
  279. else:
  280. update_str, values = [], []
  281. # set modified timestamp
  282. self.modified = now()
  283. self.modified_by = webnotes.session['user']
  284. for f in self.fields.keys():
  285. if (not (f in ('doctype', 'name', 'perm', 'localname', 'creation','_user_tags'))) \
  286. and (not f.startswith('__')): # fields not saved
  287. # validate links
  288. if link_list and link_list.get(f):
  289. self.fields[f] = self._validate_link(link_list[f][0], self.fields[f])
  290. if self.fields[f]==None or self.fields[f]=='':
  291. update_str.append("`%s`=NULL" % f)
  292. if ignore_fields:
  293. try: r = webnotes.conn.sql("update `tab%s` set `%s`=NULL where name=%s" % (self.doctype, f, '%s'), self.name)
  294. except: pass
  295. else:
  296. values.append(self.fields[f])
  297. update_str.append("`%s`=%s" % (f, '%s'))
  298. if ignore_fields:
  299. try: r = webnotes.conn.sql("update `tab%s` set `%s`=%s where name=%s" % (self.doctype, f, '%s', '%s'), (self.fields[f], self.name))
  300. except: pass
  301. if values:
  302. if not ignore_fields:
  303. # update all in one query
  304. r = webnotes.conn.sql("update `tab%s` set %s where name='%s'" % (self.doctype, ', '.join(update_str), self.name), values)
  305. # Save values
  306. # ---------------------------------------------------------------------------
  307. def save(self, new=0, check_links=1, ignore_fields=0, make_autoname = 1):
  308. """
  309. Saves the current record in the database. If new = 1, creates a new instance of the record.
  310. Also clears temperory fields starting with `__`
  311. * if check_links is set, it validates all `Link` fields
  312. * if ignore_fields is sets, it does not throw an exception for any field that does not exist in the
  313. database table
  314. """
  315. res = webnotes.model.meta.get_dt_values(self.doctype, 'autoname, issingle, istable, name_case', as_dict=1)
  316. res = res and res[0] or {}
  317. # add missing parentinfo (if reqd)
  318. if self.parent and not (self.parenttype and self.parentfield):
  319. self.update_parentinfo()
  320. if self.parent and not self.idx:
  321. self.set_idx()
  322. # if required, make new
  323. if new or (not new and self.fields.get('__islocal')) and (not res.get('issingle')):
  324. r = self.insert(res.get('autoname'), res.get('istable'), res.get('name_case'), \
  325. make_autoname)
  326. if r:
  327. return r
  328. # save the values
  329. self._update_values(res.get('issingle'), check_links and self.make_link_list() or {}, ignore_fields)
  330. self._clear_temp_fields()
  331. def update_parentinfo(self):
  332. """update parent type and parent field, if not explicitly specified"""
  333. tmp = webnotes.conn.sql("""select parent, fieldname from tabDocField
  334. where fieldtype='Table' and options=%s""", self.doctype)
  335. if len(tmp)==0:
  336. raise Exception, 'Incomplete parent info in child table (%s, %s)' \
  337. % (self.doctype, self.fields.get('name', '[new]'))
  338. elif len(tmp)>1:
  339. raise Exception, 'Ambiguous parent info (%s, %s)' \
  340. % (self.doctype, self.fields.get('name', '[new]'))
  341. else:
  342. self.parenttype = tmp[0][0]
  343. self.parentfield = tmp[0][1]
  344. def set_idx(self):
  345. """set idx"""
  346. self.idx = (webnotes.conn.sql("""select max(idx) from `tab%s`
  347. where parent=%s and parentfield=%s""" % (self.doctype, '%s', '%s'),
  348. (self.parent, self.parentfield))[0][0] or 0) + 1
  349. # check permissions
  350. # ---------------------------------------------------------------------------
  351. def _get_perms(self):
  352. if not self._perms:
  353. self._perms = webnotes.conn.sql("""select role, `match` from tabDocPerm
  354. where parent=%s and ifnull(`read`,0) = 1
  355. and ifnull(permlevel,0)=0""", self.doctype)
  356. def _get_roles(self):
  357. # check if roles match/
  358. if not self._roles:
  359. if webnotes.user:
  360. self._roles = webnotes.user.get_roles()
  361. else:
  362. self._roles = ['Guest']
  363. def _get_user_defaults(self):
  364. if not self._user_defaults:
  365. if webnotes.user:
  366. self._user_defaults = webnotes.user.get_defaults()
  367. else:
  368. self.defaults = {}
  369. def check_perm(self, verbose=0):
  370. import webnotes
  371. # Admin has all permissions
  372. if webnotes.session['user']=='Administrator':
  373. return 1
  374. # find roles with read access for this record at 0
  375. self._get_perms()
  376. self._get_roles()
  377. self._get_user_defaults()
  378. has_perm, match = 0, []
  379. # loop through everything to find if there is a match
  380. for r in self._perms:
  381. if r[0] in self._roles:
  382. has_perm = 1
  383. if r[1] and match != -1:
  384. match.append(r[1]) # add to match check
  385. else:
  386. match = -1 # has permission and no match, so match not required!
  387. if has_perm and match and match != -1:
  388. for m in match:
  389. if self.fields.get(m, 'no value') in self._user_defaults.get(m, 'no default'):
  390. has_perm = 1
  391. break # permission found! break
  392. else:
  393. has_perm = 0
  394. if verbose:
  395. webnotes.msgprint("Value not allowed: '%s' for '%s'" % (self.fields.get(m, 'no value'), m))
  396. return has_perm
  397. def _clear_temp_fields(self):
  398. # clear temp stuff
  399. keys = self.fields.keys()
  400. for f in keys:
  401. if f.startswith('__'):
  402. del self.fields[f]
  403. def clear_table(self, doclist, tablefield, save=0):
  404. """
  405. Clears the child records from the given `doclist` for a particular `tablefield`
  406. """
  407. from webnotes.model.utils import getlist
  408. table_list = getlist(doclist, tablefield)
  409. delete_list = [d.name for d in table_list]
  410. if delete_list:
  411. #filter doclist
  412. doclist = filter(lambda d: d.name not in delete_list, doclist)
  413. # delete from db
  414. webnotes.conn.sql("""\
  415. delete from `tab%s`
  416. where parent=%s and parenttype=%s"""
  417. % (table_list[0].doctype, '%s', '%s'),
  418. (self.name, self.doctype))
  419. self.fields['__unsaved'] = 1
  420. return doclist
  421. def addchild(self, fieldname, childtype = '', local=0, doclist=None):
  422. """
  423. Returns a child record of the give `childtype`.
  424. * if local is set, it does not save the record
  425. * if doclist is passed, it append the record to the doclist
  426. """
  427. d = Document()
  428. d.parent = self.name
  429. d.parenttype = self.doctype
  430. d.parentfield = fieldname
  431. d.doctype = childtype
  432. d.docstatus = 0;
  433. d.name = ''
  434. d.owner = webnotes.session['user']
  435. if local:
  436. d.fields['__islocal'] = 1 # for Client to identify unsaved doc
  437. else:
  438. d.save(new=1)
  439. if doclist != None:
  440. doclist.append(d)
  441. return d
  442. def addchild(parent, fieldname, childtype = '', local=0, doclist=None):
  443. """
  444. Create a child record to the parent doc.
  445. Example::
  446. c = Document('Contact','ABC')
  447. d = addchild(c, 'contact_updates', 'Contact Update', local = 1)
  448. d.last_updated = 'Phone call'
  449. d.save(1)
  450. """
  451. return parent.addchild(fieldname, childtype, local, doclist)
  452. # Naming
  453. # ------
  454. def make_autoname(key, doctype=''):
  455. """
  456. Creates an autoname from the given key:
  457. **Autoname rules:**
  458. * The key is separated by '.'
  459. * '####' represents a series. The string before this part becomes the prefix:
  460. Example: ABC.#### creates a series ABC0001, ABC0002 etc
  461. * 'MM' represents the current month
  462. * 'YY' and 'YYYY' represent the current year
  463. *Example:*
  464. * DE/./.YY./.MM./.##### will create a series like
  465. DE/09/01/0001 where 09 is the year, 01 is the month and 0001 is the series
  466. """
  467. n = ''
  468. l = key.split('.')
  469. for e in l:
  470. en = ''
  471. if e.startswith('#'):
  472. digits = len(e)
  473. en = getseries(n, digits, doctype)
  474. elif e=='YY':
  475. import time
  476. en = time.strftime('%y')
  477. elif e=='MM':
  478. import time
  479. en = time.strftime('%m')
  480. elif e=='YYYY':
  481. import time
  482. en = time.strftime('%Y')
  483. else: en = e
  484. n+=en
  485. return n
  486. # Get Series for Autoname
  487. # -----------------------
  488. def getseries(key, digits, doctype=''):
  489. # series created ?
  490. if webnotes.conn.sql("select name from tabSeries where name='%s'" % key):
  491. # yes, update it
  492. webnotes.conn.sql("update tabSeries set current = current+1 where name='%s'" % key)
  493. # find the series counter
  494. r = webnotes.conn.sql("select current from tabSeries where name='%s'" % key)
  495. n = r[0][0]
  496. else:
  497. # no, create it
  498. webnotes.conn.sql("insert into tabSeries (name, current) values ('%s', 1)" % key)
  499. n = 1
  500. return ('%0'+str(digits)+'d') % n
  501. # Get Children
  502. # ------------
  503. def getchildren(name, childtype, field='', parenttype='', from_doctype=0, prefix='tab'):
  504. import webnotes
  505. from webnotes.model.doclist import DocList
  506. tmp = ''
  507. if field:
  508. tmp = ' and parentfield="%s" ' % field
  509. if parenttype:
  510. tmp = ' and parenttype="%s" ' % parenttype
  511. dataset = webnotes.conn.sql("select * from `%s%s` where parent='%s' %s order by idx" \
  512. % (prefix, childtype, name, tmp))
  513. desc = webnotes.conn.get_description()
  514. l = DocList()
  515. for i in dataset:
  516. d = Document()
  517. d.doctype = childtype
  518. d._load_values(i, desc)
  519. l.append(d)
  520. return l
  521. # Check if "Guest" is allowed to view this page
  522. # ---------------------------------------------
  523. def check_page_perm(doc):
  524. if doc.name=='Login Page':
  525. return
  526. if doc.publish:
  527. return
  528. if not webnotes.conn.sql("select name from `tabPage Role` where parent=%s and role='Guest'", doc.name):
  529. webnotes.response['403'] = 1
  530. raise webnotes.PermissionError, '[WNF] No read permission for %s %s' % ('Page', doc.name)
  531. def get_report_builder_code(doc):
  532. if doc.doctype=='Search Criteria':
  533. from webnotes.model.code import get_code
  534. if doc.standard != 'No':
  535. doc.report_script = get_code(doc.module, 'Search Criteria', doc.name, 'js')
  536. doc.custom_query = get_code(doc.module, 'Search Criteria', doc.name, 'sql')
  537. # called from everywhere
  538. # load a record and its child records and bundle it in a list - doclist
  539. # ---------------------------------------------------------------------
  540. def get(dt, dn='', with_children = 1, from_get_obj = 0, prefix = 'tab'):
  541. """
  542. Returns a doclist containing the main record and all child records
  543. """
  544. import webnotes
  545. import webnotes.model
  546. from webnotes.model.doclist import DocList
  547. dn = dn or dt
  548. # load the main doc
  549. doc = Document(dt, dn, prefix=prefix)
  550. # check permission - for doctypes, pages
  551. if (dt in ('DocType', 'Page', 'Control Panel', 'Search Criteria')) or (from_get_obj and webnotes.session.get('user') != 'Guest'):
  552. if dt=='Page' and webnotes.session['user'] == 'Guest':
  553. check_page_perm(doc)
  554. else:
  555. if not doc.check_perm():
  556. webnotes.response['403'] = 1
  557. raise webnotes.ValidationError, '[WNF] No read permission for %s %s' % (dt, dn)
  558. if not with_children:
  559. # done
  560. return DocList([doc,])
  561. # get all children types
  562. tablefields = webnotes.model.meta.get_table_fields(dt)
  563. # load chilren
  564. doclist = DocList([doc,])
  565. for t in tablefields:
  566. doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix)
  567. # import report_builder code
  568. if not from_get_obj:
  569. get_report_builder_code(doc)
  570. return doclist
  571. def getsingle(doctype):
  572. """get single doc as dict"""
  573. dataset = webnotes.conn.sql("select field, value from tabSingles where doctype=%s", doctype)
  574. return dict(dataset)