Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

108 строки
3.5 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. wn.provide('wn.meta.docfield_map');
  23. wn.provide('wn.meta.docfield_copy');
  24. wn.provide('wn.meta.docfield_list');
  25. wn.provide('wn.meta.doctypes');
  26. wn.provide("wn.meta.precision_map");
  27. $.extend(wn.meta, {
  28. // build docfield_map and docfield_list
  29. add_field: function(df) {
  30. wn.provide('wn.meta.docfield_map.' + df.parent);
  31. wn.meta.docfield_map[df.parent][df.fieldname || df.label] = df;
  32. if(!wn.meta.docfield_list[df.parent])
  33. wn.meta.docfield_list[df.parent] = [];
  34. // check for repeat
  35. for(var i in wn.meta.docfield_list[df.parent]) {
  36. var d = wn.meta.docfield_list[df.parent][i];
  37. if(df.fieldname==d.fieldname)
  38. return; // no repeat
  39. }
  40. wn.meta.docfield_list[df.parent].push(df);
  41. },
  42. make_docfield_copy_for: function(doctype, docname) {
  43. var c = wn.meta.docfield_copy;
  44. if(!c[doctype])
  45. c[doctype] = {};
  46. if(!c[doctype][docname])
  47. c[doctype][docname] = {};
  48. $.each(wn.meta.docfield_list[doctype], function(i, df) {
  49. c[doctype][docname][df.fieldname || df.label] = copy_dict(df);
  50. })
  51. },
  52. get_docfield: function(dt, fn, dn) {
  53. if(dn && wn.meta.docfield_copy[dt] && wn.meta.docfield_copy[dt][dn]){
  54. return wn.meta.docfield_copy[dt][dn][fn];
  55. } else {
  56. return wn.meta.docfield_map[dt][fn];
  57. }
  58. },
  59. get_print_formats: function(doctype) {
  60. // if default print format is given, use it
  61. var print_format_list = [];
  62. if(locals.DocType[doctype].default_print_format)
  63. print_format_list.push(locals.DocType[doctype].default_print_format)
  64. if(!in_list(print_format_list, "Standard"))
  65. print_format_list.push("Standard");
  66. var print_formats = wn.model.get("Print Format", {doc_type: doctype})
  67. .sort(function(a, b) { return (a > b) ? 1 : -1; });
  68. $.each(print_formats, function(i, d) {
  69. if(!in_list(print_format_list, d.name))
  70. print_format_list.push(d.name);
  71. });
  72. return print_format_list;
  73. },
  74. get_precision_map: function(doctype) {
  75. if(!wn.meta.precision_map[doctype]) {
  76. wn.meta.precision_map[doctype] = {};
  77. var fields = wn.model.get("DocField", {parent:doctype, fieldtype: "Currency"})
  78. .concat(wn.model.get("DocField", {parent: doctype, fieldtype: "Float"}));
  79. $.each(fields, function(i, df) {
  80. wn.meta.precision_map[doctype][df.fieldname] = df.precision;
  81. });
  82. }
  83. return wn.meta.precision_map[doctype];
  84. },
  85. sync_messages: function(doc) {
  86. if(doc.__messages) {
  87. $.extend(wn._messages, doc.__messages);
  88. }
  89. },
  90. });