您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

73 行
2.4 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. import webnotes
  24. from webnotes import msgprint, _
  25. from webnotes.utils import flt, cint, cstr
  26. error_coniditon_map = {
  27. "=": "!=",
  28. "!=": "=",
  29. "<": ">=",
  30. ">": "<=",
  31. ">=": "<",
  32. "<=": ">",
  33. "in": _("not in"),
  34. "not in": _("in"),
  35. "^": _("cannot start with"),
  36. }
  37. class DocListController(object):
  38. def __init__(self, doc, doclist):
  39. self.doc, self.doclist = doc, doclist
  40. if hasattr(self, "setup"):
  41. self.setup()
  42. @property
  43. def meta(self):
  44. if not hasattr(self, "_meta"):
  45. self._meta = webnotes.get_doctype(self.doc.doctype)
  46. return self._meta
  47. def validate_value(self, fieldname, condition, val2, doc=None):
  48. if not doc:
  49. doc = self.doc
  50. df = self.meta.get_field(fieldname, parent=doc.doctype)
  51. val1 = doc.fields.get(fieldname)
  52. if df.fieldtype in ("Currency", "Float"):
  53. val1 = flt(val1)
  54. elif df.fieldtype in ("Int", "Check"):
  55. val1 = cint(val1)
  56. if not webnotes.compare(val1, condition, val2):
  57. msg = _("Error: ")
  58. if doc.parentfield:
  59. msg += _("Row") + (" # %d: " % doc.idx)
  60. msg += _(self.meta.get_label(fieldname, parent=doc.doctype)) \
  61. + " " + error_coniditon_map.get(condition, "") + " " + cstr(val2)
  62. msgprint(msg, raise_exception=True)