Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

51 lignes
1.4 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import frappe
  5. from frappe.utils import formatdate, fmt_money, flt, cstr, cint, format_datetime
  6. from frappe.model.meta import get_field_currency, get_field_precision
  7. import re
  8. def format_value(value, df, doc=None, currency=None):
  9. # Convert dict to object if necessary
  10. if (isinstance(df, dict)):
  11. df = frappe._dict(df)
  12. if value is None:
  13. value = ""
  14. if not df:
  15. return value
  16. elif df.get("fieldtype")=="Date":
  17. return formatdate(value)
  18. elif df.get("fieldtype")=="Datetime":
  19. return format_datetime(value)
  20. elif df.get("fieldtype") == "Currency" or (df.get("fieldtype")=="Float" and (df.options or "").strip()):
  21. return fmt_money(value, precision=get_field_precision(df, doc),
  22. currency=currency if currency else (get_field_currency(df, doc) if doc else None))
  23. elif df.get("fieldtype") == "Float":
  24. precision = get_field_precision(df, doc)
  25. # show 1.000000 as 1
  26. # options should not specified
  27. if not df.options and value is not None:
  28. temp = cstr(value).split(".")
  29. if len(temp)==1 or cint(temp[1])==0:
  30. precision = 0
  31. return fmt_money(value, precision=precision)
  32. elif df.get("fieldtype") == "Percent":
  33. return "{}%".format(flt(value, 2))
  34. elif df.get("fieldtype") in ("Text", "Small Text"):
  35. if not re.search("(\<br|\<div|\<p)", value):
  36. return value.replace("\n", "<br>")
  37. return value