Просмотр исходного кода

Merge branch 'master' of github.com:webnotes/wnframework

version-14
Rushabh Mehta 14 лет назад
Родитель
Сommit
12e2c95531
10 измененных файлов: 147 добавлений и 178 удалений
  1. +3
    -2
      js/legacy/form.compressed.js
  2. +5
    -0
      js/legacy/widgets/form/form.js
  3. +1
    -1
      js/legacy/widgets/form/grid.js
  4. +14
    -62
      py/core/doctype/doctype/doctype.txt
  5. +103
    -100
      py/core/doctype/doctype_mapper/doctype_mapper.py
  6. +4
    -0
      py/webnotes/modules/patch.py
  7. +2
    -2
      py/webnotes/profile.py
  8. +8
    -9
      py/webnotes/utils/email_lib/__init__.py
  9. +2
    -1
      py/webnotes/utils/email_lib/html2text.py
  10. +5
    -1
      py/webnotes/utils/email_lib/send.py

+ 3
- 2
js/legacy/form.compressed.js Просмотреть файл

@@ -61,7 +61,8 @@ this.setup_footer();if(!(this.meta.istable||user=='Guest'))this.frm_head=new _f.
this.layout.wrapper.style.backgroundColor='#'+this.meta.colour.split(':')[1];this.setup_fields_std();}
_f.Frm.prototype.setup_print=function(){var fl=getchildren('DocFormat',this.meta.name,'formats','DocType');var l=[];this.default_format='Standard';if(fl.length){this.default_format=fl[0].format;for(var i=0;i<fl.length;i++)
l.push(fl[i].format);}
l.push('Standard');this.print_sel=$a(null,'select','',{width:'160px'});add_sel_options(this.print_sel,l);this.print_sel.value=this.default_format;}
if(this.meta.default_print_format)
this.default_format=this.meta.default_print_format;l.push('Standard');this.print_sel=$a(null,'select','',{width:'160px'});add_sel_options(this.print_sel,l);this.print_sel.value=this.default_format;}
_f.Frm.prototype.print_doc=function(){if(this.doc.docstatus==2){msgprint("Cannot Print Cancelled Documents.");return;}
_p.show_dialog();}
_f.Frm.prototype.email_doc=function(){if(!_e.dialog)_e.make();sel=this.print_sel;var c=$td(_e.dialog.rows['Format'].tab,0,1);if(c.cur_sel){c.removeChild(c.cur_sel);c.cur_sel=null;}
@@ -263,7 +264,7 @@ _f.Grid.prototype.make_ui=function(parent){var ht=make_table($a(parent,'div'),1,
_f.Grid.prototype.show=function(){if(this.can_add_rows){$ds(this.tbar_div);}else{$dh(this.tbar_div);}
$ds(this.wrapper);}
_f.Grid.prototype.hide=function(){$dh(this.wrapper);$dh(this.tbar_div);}
_f.Grid.prototype.insert_column=function(doctype,fieldname,fieldtype,label,width,options,perm,reqd){var idx=this.head_row.cells.length;if(!width)width='140px';if((width+'').slice(-2)!='px'){width=width+'px';}
_f.Grid.prototype.insert_column=function(doctype,fieldname,fieldtype,label,width,options,perm,reqd){var idx=this.head_row.cells.length;if(!width)width='100px';if((width+'').slice(-2)!='px'){width=width+'px';}
var col=this.head_row.insertCell(idx);col.doctype=doctype;col.fieldname=fieldname;col.fieldtype=fieldtype;col.innerHTML='<div>'+label+'</div>';col.label=label;if(reqd)
col.childNodes[0].style.color="#D22";col.style.width=width;col.options=options;col.perm=perm;this.col_idx_by_name[fieldname]=idx;}
_f.Grid.prototype.reset_table_width=function(){var w=0;for(var i=0,len=this.head_row.cells.length;i<len;i++){w+=cint(this.head_row.cells[i].style.width);}


+ 5
- 0
js/legacy/widgets/form/form.js Просмотреть файл

@@ -176,6 +176,11 @@ _f.Frm.prototype.setup_print = function() {
l.push(fl[i].format);
}

// if default print format is given, use it
if(this.meta.default_print_format)
this.default_format = this.meta.default_print_format;

l.push('Standard');
this.print_sel = $a(null, 'select', '', {width:'160px'});
add_sel_options(this.print_sel, l);


+ 1
- 1
js/legacy/widgets/form/grid.js Просмотреть файл

@@ -62,7 +62,7 @@ _f.Grid.prototype.hide = function() {
_f.Grid.prototype.insert_column = function(doctype, fieldname, fieldtype, label, width, options, perm, reqd) {
var idx = this.head_row.cells.length;
if(!width)width = '140px';
if(!width)width = '100px';
if((width+'').slice(-2)!='px') {
width= width + 'px';
}


+ 14
- 62
py/core/doctype/doctype/doctype.txt Просмотреть файл

@@ -5,14 +5,14 @@
{
'creation': '2009-05-12 11:19:11',
'docstatus': 0,
'modified': '2011-05-16 10:19:14',
'modified': '2011-09-07 15:28:18',
'modified_by': 'Administrator',
'owner': 'Administrator'
},

# These values are common for all DocType
{
'_last_update': '1307624201',
'_last_update': '1311674341',
'allow_copy': 0,
'allow_email': 0,
'allow_print': 0,
@@ -21,7 +21,6 @@
'doctype': 'DocType',
'hide_heading': 0,
'hide_toolbar': 0,
'idx': 0,
'issingle': 0,
'istable': 0,
'module': 'Core',
@@ -32,7 +31,7 @@
'section_style': 'Simple',
'server_code_error': ' ',
'show_in_menu': 0,
'version': 8
'version': 11
},

# These values are common for all DocField
@@ -52,7 +51,8 @@
'parent': 'DocType',
'parentfield': 'permissions',
'parenttype': 'DocType',
'read': 1
'read': 1,
'role': 'Administrator'
},

# DocType, DocType
@@ -61,22 +61,13 @@
'name': 'DocType'
},

# DocPerm
{
'doctype': 'DocPerm',
'permlevel': 0,
'role': 'System Manager'
},

# DocPerm
{
'cancel': 0,
'create': 1,
'doctype': 'DocPerm',
'execute': 0,
'idx': 1,
'permlevel': 0,
'role': 'Administrator',
'submit': 0,
'write': 1
},
@@ -84,9 +75,7 @@
# DocPerm
{
'doctype': 'DocPerm',
'idx': 2,
'permlevel': 1,
'role': 'Administrator'
'permlevel': 1
},

# DocField
@@ -94,7 +83,6 @@
'doctype': 'DocField',
'fieldtype': 'Section Break',
'hidden': 0,
'idx': 1,
'label': 'Options',
'oldfieldtype': 'Section Break',
'reqd': 0,
@@ -105,7 +93,6 @@
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 2,
'label': 'Settings',
'oldfieldtype': 'Column Break',
'width': '50%'
@@ -116,7 +103,6 @@
'doctype': 'DocField',
'fieldname': 'module',
'fieldtype': 'Link',
'idx': 3,
'label': 'Module',
'oldfieldname': 'module',
'oldfieldtype': 'Link',
@@ -129,7 +115,6 @@
'doctype': 'DocField',
'fieldname': 'version',
'fieldtype': 'Int',
'idx': 4,
'label': 'Version',
'oldfieldname': 'version',
'oldfieldtype': 'Int'
@@ -141,7 +126,6 @@
'fieldname': 'name',
'fieldtype': 'Data',
'hidden': 1,
'idx': 5,
'label': 'Name',
'oldfieldname': 'name',
'oldfieldtype': 'Data',
@@ -155,7 +139,6 @@
'fieldname': 'autoname',
'fieldtype': 'Data',
'hidden': 0,
'idx': 6,
'label': 'Auto Name',
'oldfieldname': 'autoname',
'oldfieldtype': 'Data',
@@ -169,7 +152,6 @@
'fieldname': 'owner',
'fieldtype': 'Link',
'hidden': 1,
'idx': 7,
'label': 'Owner',
'oldfieldname': 'owner',
'oldfieldtype': 'Link',
@@ -182,7 +164,6 @@
'doctype': 'DocField',
'fieldname': 'name_case',
'fieldtype': 'Select',
'idx': 8,
'label': 'Name Case',
'oldfieldname': 'name_case',
'oldfieldtype': 'Select',
@@ -195,7 +176,6 @@
'fieldname': 'search_fields',
'fieldtype': 'Data',
'hidden': 0,
'idx': 9,
'label': 'Search Fields',
'oldfieldname': 'search_fields',
'oldfieldtype': 'Data',
@@ -210,7 +190,6 @@
'doctype': 'DocField',
'fieldname': 'subject',
'fieldtype': 'Data',
'idx': 10,
'label': 'Subject'
},

@@ -221,7 +200,6 @@
'doctype': 'DocField',
'fieldname': 'tag_fields',
'fieldtype': 'Data',
'idx': 11,
'label': 'tag_fields'
},

@@ -231,7 +209,6 @@
'fieldname': 'istable',
'fieldtype': 'Check',
'hidden': 0,
'idx': 12,
'label': 'Is Table',
'oldfieldname': 'istable',
'oldfieldtype': 'Check',
@@ -245,7 +222,6 @@
'fieldname': 'read_only',
'fieldtype': 'Check',
'hidden': 0,
'idx': 13,
'label': 'Not In Search',
'oldfieldname': 'read_only',
'oldfieldtype': 'Check',
@@ -258,7 +234,6 @@
'doctype': 'DocField',
'fieldname': 'in_create',
'fieldtype': 'Check',
'idx': 14,
'label': 'Not In Create',
'oldfieldname': 'in_create',
'oldfieldtype': 'Check'
@@ -270,7 +245,6 @@
'fieldname': 'issingle',
'fieldtype': 'Check',
'hidden': 0,
'idx': 15,
'label': 'Is Single',
'oldfieldname': 'issingle',
'oldfieldtype': 'Check',
@@ -284,7 +258,6 @@
'doctype': 'DocField',
'fieldname': 'read_only_onload',
'fieldtype': 'Check',
'idx': 16,
'label': 'Show Print First',
'oldfieldname': 'read_only_onload',
'oldfieldtype': 'Check'
@@ -295,7 +268,6 @@
'doctype': 'DocField',
'fieldname': 'show_in_menu',
'fieldtype': 'Check',
'idx': 17,
'label': 'Show In Pages',
'oldfieldname': 'show_in_menu',
'oldfieldtype': 'Check'
@@ -306,7 +278,6 @@
'doctype': 'DocField',
'fieldname': 'document_type',
'fieldtype': 'Select',
'idx': 18,
'label': 'Document Type',
'oldfieldname': 'document_type',
'oldfieldtype': 'Select',
@@ -318,7 +289,6 @@
'doctype': 'DocField',
'fieldtype': 'Column Break',
'hidden': 0,
'idx': 19,
'label': 'Display',
'oldfieldtype': 'Column Break',
'reqd': 0,
@@ -331,7 +301,6 @@
'doctype': 'DocField',
'fieldname': 'is_transaction_doc',
'fieldtype': 'Check',
'idx': 20,
'label': 'Is Transaction Doc',
'oldfieldname': 'is_transaction_doc',
'oldfieldtype': 'Check'
@@ -342,7 +311,6 @@
'doctype': 'DocField',
'fieldname': 'use_template',
'fieldtype': 'Check',
'idx': 21,
'label': 'Use Template',
'oldfieldname': 'use_template',
'oldfieldtype': 'Check'
@@ -354,7 +322,6 @@
'fieldname': 'print_outline',
'fieldtype': 'Select',
'hidden': 0,
'idx': 22,
'label': 'Print Outline',
'oldfieldname': 'print_outline',
'oldfieldtype': 'Select',
@@ -369,7 +336,6 @@
'fieldname': 'allow_print',
'fieldtype': 'Check',
'hidden': 0,
'idx': 23,
'label': 'Hide Print',
'oldfieldname': 'allow_print',
'oldfieldtype': 'Check',
@@ -383,7 +349,6 @@
'fieldname': 'allow_email',
'fieldtype': 'Check',
'hidden': 0,
'idx': 24,
'label': 'Hide Email',
'oldfieldname': 'allow_email',
'oldfieldtype': 'Check',
@@ -396,7 +361,6 @@
'doctype': 'DocField',
'fieldname': 'in_dialog',
'fieldtype': 'Check',
'idx': 25,
'label': 'In Dialog',
'oldfieldname': 'in_dialog',
'oldfieldtype': 'Check'
@@ -408,7 +372,6 @@
'fieldname': 'allow_copy',
'fieldtype': 'Check',
'hidden': 0,
'idx': 26,
'label': 'Hide Copy',
'oldfieldname': 'allow_copy',
'oldfieldtype': 'Check',
@@ -422,7 +385,6 @@
'fieldname': 'hide_toolbar',
'fieldtype': 'Check',
'hidden': 0,
'idx': 27,
'label': 'Hide Toolbar',
'oldfieldname': 'hide_toolbar',
'oldfieldtype': 'Check',
@@ -436,7 +398,6 @@
'fieldname': 'hide_heading',
'fieldtype': 'Check',
'hidden': 0,
'idx': 28,
'label': 'Hide Heading',
'oldfieldname': 'hide_heading',
'oldfieldtype': 'Check',
@@ -449,7 +410,6 @@
'doctype': 'DocField',
'fieldname': 'allow_attach',
'fieldtype': 'Check',
'idx': 29,
'label': 'Allow Attach',
'oldfieldname': 'allow_attach',
'oldfieldtype': 'Check',
@@ -462,7 +422,6 @@
'fieldname': 'max_attachments',
'fieldtype': 'Int',
'hidden': 1,
'idx': 30,
'label': 'Max Attachments',
'oldfieldname': 'max_attachments',
'oldfieldtype': 'Int'
@@ -473,7 +432,6 @@
'doctype': 'DocField',
'fieldname': 'allow_rename',
'fieldtype': 'Check',
'idx': 31,
'label': 'Allow Rename',
'oldfieldname': 'allow_rename',
'oldfieldtype': 'Check'
@@ -484,7 +442,6 @@
'doctype': 'DocField',
'fieldname': 'section_style',
'fieldtype': 'Select',
'idx': 32,
'label': 'Section Style',
'oldfieldname': 'section_style',
'oldfieldtype': 'Select',
@@ -497,7 +454,6 @@
'fieldname': 'colour',
'fieldtype': 'Select',
'hidden': 0,
'idx': 33,
'label': 'Colour',
'oldfieldname': 'colour',
'oldfieldtype': 'Select',
@@ -512,7 +468,6 @@
'fieldname': 'smallicon',
'fieldtype': 'Select',
'hidden': 0,
'idx': 34,
'label': 'Small Icon',
'oldfieldname': 'smallicon',
'oldfieldtype': 'Select',
@@ -521,11 +476,18 @@
'search_index': 0
},

# DocField
{
'doctype': 'DocField',
'fieldname': 'default_print_format',
'fieldtype': 'Data',
'label': 'Default Print Format'
},

# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 35,
'label': 'Permissions',
'oldfieldtype': 'Section Break'
},
@@ -534,7 +496,6 @@
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 36,
'label': 'Roles and Permissions',
'oldfieldtype': 'Column Break',
'width': '70%'
@@ -547,7 +508,6 @@
'fieldname': 'permissions',
'fieldtype': 'Table',
'hidden': 0,
'idx': 37,
'label': 'Permissions',
'oldfieldname': 'permissions',
'oldfieldtype': 'Table',
@@ -561,7 +521,6 @@
'doctype': 'DocField',
'fieldname': 'allow_trash',
'fieldtype': 'Check',
'idx': 38,
'label': 'Allow Trash',
'oldfieldname': 'allow_trash',
'oldfieldtype': 'Check'
@@ -571,7 +530,6 @@
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 39,
'label': 'Print Formats',
'oldfieldtype': 'Column Break',
'width': '30%'
@@ -583,7 +541,6 @@
'fieldname': 'formats',
'fieldtype': 'Table',
'hidden': 0,
'idx': 40,
'label': 'Formats',
'oldfieldname': 'formats',
'oldfieldtype': 'Table',
@@ -597,7 +554,6 @@
'doctype': 'DocField',
'fieldtype': 'Section Break',
'hidden': 0,
'idx': 41,
'label': 'Fields',
'oldfieldtype': 'Section Break',
'reqd': 0,
@@ -609,7 +565,6 @@
'doctype': 'DocField',
'fieldtype': 'Column Break',
'hidden': 0,
'idx': 42,
'label': 'Document Fields',
'oldfieldtype': 'Column Break',
'reqd': 0,
@@ -622,7 +577,6 @@
'fieldname': 'fields',
'fieldtype': 'Table',
'hidden': 0,
'idx': 43,
'label': 'Fields',
'oldfieldname': 'fields',
'oldfieldtype': 'Table',
@@ -636,7 +590,6 @@
'doctype': 'DocField',
'fieldtype': 'Section Break',
'hidden': 0,
'idx': 44,
'label': 'Description',
'oldfieldtype': 'Section Break',
'reqd': 0,
@@ -649,7 +602,6 @@
'fieldname': 'description',
'fieldtype': 'Text',
'hidden': 0,
'idx': 45,
'label': 'Description',
'oldfieldname': 'description',
'oldfieldtype': 'Text',


+ 103
- 100
py/core/doctype/doctype_mapper/doctype_mapper.py Просмотреть файл

@@ -21,41 +21,17 @@ class DocType:
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
self.prefix = is_testing and 'test' or 'tab'
self.ref_doc = ''
# Autoname
#---------
#---------------------------------------------------------------------------
def autoname(self):
self.doc.name = make_autoname(self.doc.from_doctype + '-' + self.doc.to_doctype)

def map_fields_with_same_name(self, from_doctype, to_doctype, from_doc, to_doc, fld_list):
"""
Returns field list with same name in from and to doctype
"""
exception_flds = [f[0] for f in fld_list if f[2] == 'No']
exception_flds += default_fields
exception_flds += ['amended_from', 'amendment_date', 'file_list', 'naming_series', 'status']
map_fld_list = [
[d[0], d[0], 'Yes'] for d in sql("""
select t1.fieldname
from `tabDocField` t1, `tabDocField` t2
where t1.parent = %s and t2.parent = %s
and t1.fieldname = t2.fieldname
and t1.docstatus != 2 and t2.docstatus != 2
and ifnull(t1.fieldname, '') != ''
""",(from_doctype, to_doctype)) if d[0] not in exception_flds
]

self.set_value(map_fld_list, from_doc, to_doc)
# Maps the fields in 'To DocType'
#--------------------------------
#---------------------------------------------------------------------------
def dt_map(self, from_doctype, to_doctype, from_docname, to_doc, doclist, from_to_list = '[]'):

# definition of arguments
'''
String <from_doctype> : contains the name of DocType initiating the function
String <to_doctype> : contains the name of DocType created by the function
@@ -64,6 +40,10 @@ class DocType:
String <doclist> : contains doclist of 'to_doctype'
String <from_to_list> : contains list of tables which will be mapped
'''
if not from_docname:
msgprint(from_doctype + " not selected for mapping", raise_exception=1)
# Validate reference doc docstatus
self.ref_doc = from_docname
self.check_ref_docstatus()
@@ -71,75 +51,93 @@ class DocType:
if not doclist:
doclist.append(to_doc)

tbl_list = sql("select from_table, to_table, from_field, to_field, match_id, validation_logic from `tabTable Mapper Detail` where parent ='%s' order by match_id" % (from_doctype + "-" + to_doctype))

for t in tbl_list:
from_table_name = t[0]
to_table_name = t[1]
from_table_fname = t[2]
to_table_fname = t[3]
match_id = t[4]
validation_logic = t[5]

from_to = [from_table_name, to_table_name]
tbl_list = sql("select from_table, to_table, from_field, to_field, match_id, validation_logic from `tabTable Mapper Detail` where parent ='%s' order by match_id" % self.doc.name, as_dict=1)

if from_to in eval(from_to_list):
fld_list = sql("select from_field, to_field, map from `tabField Mapper Detail` where parent = '%s' and match_id = %s" % (from_doctype + "-" + to_doctype, match_id))
if not from_docname:
msgprint(from_doctype + " not selected for mapping")
raise Exception
# Parent to parent mapping
if from_table_name == self.doc.from_doctype and to_table_name == self.doc.to_doctype:
# Check validation
nm = sql("select name from `tab%s` where name = '%s' and %s" % (from_doctype, from_docname, validation_logic))
nm = nm and nm[0][0] or ''
# If validation failed raise exception
if not nm:
msgprint("Validation failed in doctype mapper. Please contact Administrator.")
raise Exception
from_doc = Document(from_doctype, nm)

# Map fields with same name
for t in tbl_list:
if [t['from_table'], t['to_table']] in eval(from_to_list):
self.map_fields(t, from_doctype, from_docname, to_doc, doclist)
# Doclist is required when called from server side for refreshing table
return doclist

self.map_fields_with_same_name(from_doctype, to_doctype, from_doc, to_doc, fld_list)
# Maps field in parent
if fld_list:
self.set_value(fld_list, from_doc, to_doc)

#---------------------------------------------------------------------------
def map_fields(self, t, from_dt, from_dn, to_doc, doclist):
"""
Creates from, to obj and maps flds as per mapper and with same name
"""
flds = self.get_mapper_fields(t)
flds += self.get_fields_with_same_name(t, flds)

# Parent to child OR child to child mapping
if flds:
from_docnames = self.get_docnames(t, from_dt, from_dn)
for dn in from_docnames:
# Creates object for 'From DocType', it can be parent or child
from_doc_obj = Document(t['from_table'], dn[0])
# Add a row in target table in 'To DocType' and returns obj
if t['to_table'] != self.doc.to_doctype:
to_doc_obj = addchild(to_doc, t['to_field'], t['to_table'], 1, doclist)
else:
dnlist = ()
if from_table_name == self.doc.from_doctype:
dnlist = ((from_docname,),)
else:
dnlist = sql("select name from `tab%s` where parent='%s' and parenttype = '%s' and %s order by idx" % (from_table_name, from_docname, self.doc.from_doctype, validation_logic))
for dn in dnlist:
# Add a row in target table in 'To DocType' and returns obj
ch = addchild(to_doc, t[3], t[1], 1, doclist)
# Creates object for 'From DocType', it can be parent or child
d = Document(t[0], dn[0])
# Map fields with same name
self.map_fields_with_same_name(from_table_name, t[1], d, ch, fld_list)
# Map values
if fld_list:
self.set_value(fld_list, d, ch)
to_doc_obj = to_doc

self.set_value(flds, from_doc_obj, to_doc_obj)
#---------------------------------------------------------------------------
def get_docnames(self, t, from_dt, from_dn):
"""
Returns docnames of source document (parent/child)
"""
docnames = ()
if t['from_table'] == self.doc.from_doctype:
docnames = sql("select name from `tab%s` where name = '%s' and %s" % (from_dt, from_dn, t['validation_logic']))
if not docnames:
msgprint("Validation failed in doctype mapper. Please contact Administrator.", raise_exception=1)
else:
docnames = sql("select name from `tab%s` where parent='%s' and parenttype = '%s' and %s order by idx" % (t['from_table'], from_dn, self.doc.from_doctype, t['validation_logic']))
return docnames
#---------------------------------------------------------------------------
def get_mapper_fields(self, t):
return [[f[0], f[1], f[2]] for f in sql("""
select from_field, to_field, map
from `tabField Mapper Detail`
where parent = '%s' and match_id = %s
""" % (self.doc.name, t['match_id']))]


# Required when called from server side for refreshing table
return doclist
#---------------------------------------------------------------------------
def get_fields_with_same_name(self, t, flds):
"""
Returns field list with same name in from and to doctype
"""
exception_flds = default_fields
exception_flds += [f[1] for f in flds]
similar_flds = [
[d[0], d[0], 'Yes'] for d in sql("""
select t1.fieldname
from `tabDocField` t1, `tabDocField` t2
where t1.parent = %s and t2.parent = %s
and t1.fieldname = t2.fieldname
and t1.docstatus != 2 and t2.docstatus != 2
and ifnull(t1.no_copy, 0) = 0
and ifnull(t1.fieldname, '') != ''
and t1.fieldtype not in ('Table', 'Section Break', 'Column Break', 'HTML')
""",(t['from_table'], t['to_table'])) if d[0] not in exception_flds
]
return similar_flds
# Assigns value to "To Doctype"
#------------------------------
#---------------------------------------------------------------------------
def set_value(self, fld_list, obj, to_doc):
"""
Assigns value to fields in "To Doctype"
"""
for f in fld_list:
if f[2] == 'Yes':
if f[0].startswith('eval:'):
@@ -152,9 +150,12 @@ class DocType:
else:
to_doc.fields[f[1]] = obj.fields.get(f[0])
# Validate
#---------
#---------------------------------------------------------------------------
def validate(self):
"""
Validate mapper while saving
"""
for d in getlist(self.doclist, 'field_mapper_details'):
# Automatically assigns default value if not entered
if not d.match_id:
@@ -169,10 +170,13 @@ class DocType:
# Check wrong field name
self.check_fields_in_dt()
# Check if any wrong fieldname entered
#--------------------------------------
#---------------------------------------------------------------------------
def check_fields_in_dt(self):
"""
Check if any wrong fieldname entered in mapper
"""
for d in getlist(self.doclist, 'field_mapper_details'):
table_name = sql("select from_table, to_table from `tabTable Mapper Detail` where parent ='%s' and match_id = '%s'" % (self.doc.name, d.match_id))
@@ -186,6 +190,7 @@ class DocType:
if not exists2 and d.to_field not in default_fields:
msgprint('"' + cstr(d.to_field) + '" does not exists in DocType "' + cstr(table_name[0][1]) + '"')
# Check consistency of value with reference document
#---------------------------------------------------
def validate_reference_value(self, obj, to_docname):
@@ -235,7 +240,6 @@ class DocType:
if cl[2] == '=' and (ft[1] == 'Currency' or ft[1] == 'Float'):
consistent = sql("select name, %s from `tab%s` where name = '%s' and '%s' - %s <= 0.5" % (cl[0], t.from_table, child_obj.fields[t.reference_key], flt(cur_val), cl[0]))
else:
#consistent = sql("select name, %s from `tab%s` where name = '%s' and '%s' %s %s" % (cl[0], t.from_table, child_obj.fields[t.reference_key], cur_val, cl[2], cl[0]))
consistent = sql("select name, %s from `tab%s` where name = '%s' and '%s' %s ifnull(%s, '')" % (cl[0], t.from_table, child_obj.fields[t.reference_key], ft[1] in ('Currency', 'Float', 'Int') and flt(cur_val) or cstr(cur_val), cl[2], cl[0]))

if not self.ref_doc:
@@ -253,22 +257,21 @@ class DocType:
from_fld_label = sql("select label from tabDocField where parent = '%s' and fieldname = '%s'" % (from_table, from_field))
op_in_words = {'=':'equal to ', '>=':'greater than equal to ', '>':'greater than ', '<=':'less than equal to ', '<':'less than '}
msgprint(to_fld_label[0][0] + " should be " + op_in_words[operator] + from_fld_label[0][0] + " of " + self.doc.from_doctype + ": " + self.ref_doc)
raise Exception, "Validation Error."
msgprint(to_fld_label[0][0] + " should be " + op_in_words[operator] + from_fld_label[0][0] + " of " + self.doc.from_doctype + ": " + self.ref_doc, raise_exception=1)
def check_ref_docstatus(self):
if self.ref_doc:
det = sql("select name, docstatus from `tab%s` where name = '%s'" % (self.doc.from_doctype, self.ref_doc))
if not det:
msgprint(self.doc.from_doctype + ": " + self.ref_doc + " does not exists in the system")
raise Exception, "Validation Error."
msgprint(self.doc.from_doctype + ": " + self.ref_doc + " does not exists in the system", raise_exception=1)
elif self.doc.ref_doc_submitted and det[0][1] != 1:
msgprint(self.doc.from_doctype + ": " + self.ref_doc + " is not Submitted Document.")
raise Exception, "Validation Error."
msgprint(self.doc.from_doctype + ": " + self.ref_doc + " is not Submitted Document.", raise_exception=1)

def on_update(self):
"""
If developer_mode = 1, mapper will be written to files
"""
import webnotes.defs
if hasattr(webnotes.defs, 'developer_mode') and webnotes.defs.developer_mode:
from webnotes.modules.export_module import export_to_files
export_to_files(record_list=[[self.doc.doctype, self.doc.name]])
export_to_files(record_list=[[self.doc.doctype, self.doc.name]])

+ 4
- 0
py/webnotes/modules/patch.py Просмотреть файл

@@ -5,6 +5,10 @@ def run(log_exception=1):
from patches import patch
from webnotes.utils import cint
if webnotes.conn.cur_db_name=='accounts':
# no patches on accounts
return
next_patch = cint(webnotes.conn.get_global('next_patch'))
if next_patch <= patch.last_patch:


+ 2
- 2
py/webnotes/profile.py Просмотреть файл

@@ -162,12 +162,12 @@ class Profile:

# update tab Profile
webnotes.conn.sql("UPDATE tabProfile SET password=password(%s) WHERE name=%s", (pwd, profile[0][0]))
self.send_email("Password Reset", "<p>Dear %s%s,</p><p>your password has been changed to %s</p><p>[Automatically Generated]</p>" % (profile[0][2], (profile[0][3] and (' ' + profile[0][3]) or ''), pwd), profile[0][1])
def send_email(self, subj, mess, email):
import webnotes.utils.email_lib
webnotes.utils.email_lib.sendmail(email, msg=mess, subject=subj)
# update recent documents


+ 8
- 9
py/webnotes/utils/email_lib/__init__.py Просмотреть файл

@@ -29,19 +29,18 @@ def sendmail(recipients, sender='', msg='', subject='[No Subject]', parts=[], cc
email = EMail(sender, recipients, subject, reply_to=reply_to)
email.cc = cc
if msg:
if template:
msg = make_html_body(msg, template)
if msg:
if template:
msg = make_html_body(msg, template).encode('utf-8')
else:
# if not html, then lets put some whitespace
if (not '<br>' in msg) or (not '<p>' in msg):
msg = msg.replace('\n','<br>')
msg = msg.replace('\n','<br>')
footer = get_footer()
msg = msg + (footer or '')
email.set_text(html2text(msg))
email.set_html(msg)
msg = msg + (footer or '')
email.set_text(html2text(msg))
email.set_html(msg)
for p in parts:
email.set_message(p[1])
for a in attach:


+ 2
- 1
py/webnotes/utils/email_lib/html2text.py Просмотреть файл

@@ -447,7 +447,8 @@ def html2text_file(html, out=wrapwrite, baseurl=''):
return h.close()

def html2text(html, baseurl=''):
return optwrap(html2text_file(html, None, baseurl))
txt = html2text_file(html.decode('utf-8'), None, baseurl)
return optwrap(txt.encode('utf-8'))

if __name__ == "__main__":
baseurl = ''


+ 5
- 1
py/webnotes/utils/email_lib/send.py Просмотреть файл

@@ -16,6 +16,9 @@ class EMail:
"""
def __init__(self, sender='', recipients=[], subject='', from_defs=0, alternative=0, reply_to=None):
from email.mime.multipart import MIMEMultipart
from email import Charset
Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8')

if type(recipients)==str:
recipients = recipients.replace(';', ',')
recipients = recipients.split(',')
@@ -36,7 +39,8 @@ class EMail:
Attach message in the text portion of multipart/alternative
"""
from email.mime.text import MIMEText
part = MIMEText(message, 'plain')
msg = unicode(message, 'utf-8')
part = MIMEText(msg.encode('utf-8'), 'plain', 'UTF-8')
self.msg_multipart.attach(part)
def set_html(self, message):


Загрузка…
Отмена
Сохранить