Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 13 roky
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # metadata
  23. from __future__ import unicode_literals
  24. import webnotes
  25. #=================================================================================
  26. def get_dt_values(doctype, fields, as_dict = 0):
  27. return webnotes.conn.sql('SELECT %s FROM tabDocType WHERE name="%s"' % (fields, doctype), as_dict = as_dict)
  28. def set_dt_value(doctype, field, value):
  29. return webnotes.conn.set_value('DocType', doctype, field, value)
  30. def is_single(doctype):
  31. try:
  32. return get_dt_values(doctype, 'issingle')[0][0]
  33. except IndexError, e:
  34. raise Exception, 'Cannot determine whether %s is single' % doctype
  35. #=================================================================================
  36. def get_parent_dt(dt):
  37. parent_dt = webnotes.conn.sql("""select parent from tabDocField
  38. where fieldtype="Table" and options="%s" and (parent not like "old_parent:%%")
  39. limit 1""" % dt)
  40. return parent_dt and parent_dt[0][0] or ''
  41. #=================================================================================
  42. def set_fieldname(field_id, fieldname):
  43. webnotes.conn.set_value('DocField', field_id, 'fieldname', fieldname)
  44. #=================================================================================
  45. def get_link_fields(doctype):
  46. """
  47. Returns list of link fields for a doctype in tuple (fieldname, options, label)
  48. """
  49. import webnotes.model.doctype
  50. doclist = webnotes.model.doctype.get(doctype)
  51. return [
  52. (d.fields.get('fieldname'), d.fields.get('options'), d.fields.get('label'))
  53. for d in doclist
  54. if d.fields.get('doctype') == 'DocField' and d.fields.get('parent') == doctype
  55. and d.fields.get('fieldname')!='owner'
  56. and (d.fields.get('fieldtype') == 'Link' or
  57. ( d.fields.get('fieldtype') == 'Select'
  58. and (d.fields.get('options') or '').startswith('link:'))
  59. )
  60. ]
  61. #=================================================================================
  62. def get_table_fields(doctype):
  63. child_tables = [[d[0], d[1]] for d in webnotes.conn.sql("select options, fieldname from tabDocField \
  64. where parent='%s' and fieldtype='Table'" % doctype, as_list=1)]
  65. custom_child_tables = [[d[0], d[1]] for d in webnotes.conn.sql("select options, fieldname from `tabCustom Field` \
  66. where dt='%s' and fieldtype='Table'" % doctype, as_list=1)]
  67. return child_tables + custom_child_tables