@@ -1 +0,0 @@ | |||||
Define Field and Table Mappings between to main DocTypes (non child) so that records can be copied over easily from one DocType to another. |
@@ -1 +0,0 @@ | |||||
from __future__ import unicode_literals |
@@ -1,25 +0,0 @@ | |||||
// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) | |||||
// | |||||
// MIT License (MIT) | |||||
// | |||||
// Permission is hereby granted, free of charge, to any person obtaining a | |||||
// copy of this software and associated documentation files (the "Software"), | |||||
// to deal in the Software without restriction, including without limitation | |||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||||
// and/or sell copies of the Software, and to permit persons to whom the | |||||
// Software is furnished to do so, subject to the following conditions: | |||||
// | |||||
// The above copyright notice and this permission notice shall be included in | |||||
// all copies or substantial portions of the Software. | |||||
// | |||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |||||
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||||
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||||
// | |||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) { | |||||
cur_frm.toggle_enable(['from_doctype', 'to_doctype'], !doc.from_doctype); | |||||
} |
@@ -1,309 +0,0 @@ | |||||
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) | |||||
# | |||||
# MIT License (MIT) | |||||
# | |||||
# Permission is hereby granted, free of charge, to any person obtaining a | |||||
# copy of this software and associated documentation files (the "Software"), | |||||
# to deal in the Software without restriction, including without limitation | |||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||||
# and/or sell copies of the Software, and to permit persons to whom the | |||||
# Software is furnished to do so, subject to the following conditions: | |||||
# | |||||
# The above copyright notice and this permission notice shall be included in | |||||
# all copies or substantial portions of the Software. | |||||
# | |||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |||||
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |||||
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |||||
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||||
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |||||
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||||
# | |||||
from __future__ import unicode_literals | |||||
import webnotes | |||||
from webnotes.utils import cint, cstr, default_fields, flt | |||||
from webnotes.model import default_fields | |||||
from webnotes.model.doc import Document, addchild, make_autoname | |||||
from webnotes.model.bean import getlist | |||||
from webnotes import msgprint | |||||
from webnotes.model.doctype import get | |||||
sql = webnotes.conn.sql | |||||
class DocType: | |||||
def __init__(self, doc, doclist=[]): | |||||
self.doc = doc | |||||
self.doclist = doclist | |||||
self.ref_doc = '' | |||||
#--------------------------------------------------------------------------- | |||||
def autoname(self): | |||||
self.doc.name = make_autoname(self.doc.from_doctype + '-' + self.doc.to_doctype) | |||||
# Maps the fields in 'To DocType' | |||||
#--------------------------------------------------------------------------- | |||||
def dt_map(self, from_doctype, to_doctype, from_docname, to_doc, doclist, from_to_list = '[]'): | |||||
''' | |||||
String <from_doctype> : contains the name of DocType initiating the function | |||||
String <to_doctype> : contains the name of DocType created by the function | |||||
String <from_docname> : contains ID(name) of 'from_doctype' | |||||
String <to_doc> : contains doc of 'to_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() | |||||
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""" \ | |||||
% self.doc.name, as_dict=1) | |||||
if isinstance(from_to_list, basestring): | |||||
from_to_list = eval(from_to_list) | |||||
for t in tbl_list: | |||||
if [t['from_table'], t['to_table']] in 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 | |||||
#--------------------------------------------------------------------------- | |||||
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) | |||||
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'], doclist) | |||||
else: | |||||
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']))] | |||||
#--------------------------------------------------------------------------- | |||||
def get_fields_with_same_name(self, t, flds): | |||||
""" | |||||
Returns field list with same name in from and to doctype | |||||
""" | |||||
import copy | |||||
exception_flds = copy.copy(default_fields) | |||||
exception_flds += [f[1] for f in flds] | |||||
from_flds = [d.fieldname for d in get(t['from_table']).get_parent_doclist() \ | |||||
if cint(d.no_copy) == 0 and d.docstatus != 2 and d.fieldname \ | |||||
and d.fieldtype not in ('Table', 'Section Break', 'Column Break', 'HTML', 'Button')] | |||||
to_flds = [d.fieldname for d in get(t['to_table']).get_parent_doclist() \ | |||||
if cint(d.no_copy) == 0 and d.docstatus != 2 and d.fieldname \ | |||||
and d.fieldtype not in ('Table', 'Section Break', 'Column Break', 'HTML', 'Button')] | |||||
similar_flds = [[d, d, 'Yes'] for d in from_flds \ | |||||
if d in to_flds and d not in exception_flds] | |||||
return similar_flds | |||||
#--------------------------------------------------------------------------- | |||||
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:'): | |||||
try: | |||||
val = eval(f[0][5:]) | |||||
except: | |||||
val = '' | |||||
to_doc.fields[f[1]] = val | |||||
else: | |||||
to_doc.fields[f[1]] = obj.fields.get(f[0]) | |||||
#--------------------------------------------------------------------------- | |||||
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: | |||||
d.match_id = 0 | |||||
if not d.map: | |||||
d.map = 'Yes' | |||||
for d in getlist(self.doclist, 'table_mapper_details'): | |||||
if not d.reference_doctype_key: | |||||
d.reference_doctype_key = '' | |||||
if not d.reference_key: | |||||
d.reference_key = '' | |||||
# Check wrong field name | |||||
self.check_fields_in_dt() | |||||
def check_fields_in_dt(self): | |||||
""" | |||||
Check if any wrong fieldname entered in mapper | |||||
""" | |||||
flds = {} | |||||
for t in getlist(self.doclist, 'table_mapper_details'): | |||||
from_flds = [cstr(d.fieldname) for d in get(t.from_table, 0)] | |||||
to_flds = [cstr(d.fieldname) for d in get(t.to_table, 0)] | |||||
flds[cstr(t.match_id)] = [cstr(t.from_table), from_flds, cstr(t.to_table), to_flds] | |||||
for d in getlist(self.doclist, 'field_mapper_details'): | |||||
# Default fields like name, parent, owner does not exists in DocField | |||||
if d.from_field not in flds[cstr(d.match_id)][1] and d.from_field not in default_fields: | |||||
msgprint("'%s' does not exists in DocType: '%s'" % (cstr(d.from_field), cstr(flds[cstr(d.match_id)][0]))) | |||||
if d.to_field not in flds[cstr(d.match_id)][3] and d.to_field not in default_fields: | |||||
msgprint("'%s' does not exists in DocType: '%s'" % (cstr(d.to_field), cstr(flds[cstr(d.match_id)][2]))) | |||||
def validate_reference_value(self, obj, to_docname): | |||||
""" Check consistency of value with reference document""" | |||||
for t in getlist(self.doclist, 'table_mapper_details'): | |||||
# Reference key is the fieldname which will relate to the from_table | |||||
if t.reference_doctype_key: | |||||
for d in getlist(obj.doclist, t.to_field): | |||||
if d.fields[t.reference_doctype_key] == self.doc.from_doctype: | |||||
self.check_consistency(obj.doc, d, to_docname) | |||||
self.check_ref_docstatus() | |||||
def get_checklist(self): | |||||
""" Make list of fields whose value will be consistent with prevdoc """ | |||||
checklist = [] | |||||
for f in getlist(self.doclist, 'field_mapper_details'): | |||||
# Check which field's value will be compared | |||||
if f.checking_operator: | |||||
checklist.append({'from_fld': f.from_field, 'to_fld': f.to_field, 'op': f.checking_operator, 'match_id': f.match_id}) | |||||
return checklist | |||||
def get_label_and_type(self, from_dt, to_dt): | |||||
"""get label, fieldtype""" | |||||
from_flds, to_flds = {}, {} | |||||
for d in get(from_dt, 0): | |||||
from_flds[d.fieldname] = {'label': d.label, 'fieldtype': d.fieldtype} | |||||
for d in get(to_dt, 0): | |||||
to_flds[d.fieldname] = {'label': d.label, 'fieldtype': d.fieldtype} | |||||
return from_flds, to_flds | |||||
def check_consistency(self, par_obj, child_obj, to_docname): | |||||
"""Check whether values between from_dt and to_dt are consistent""" | |||||
checklist = self.get_checklist() | |||||
self.ref_doc = '' | |||||
for t in getlist(self.doclist, 'table_mapper_details'): | |||||
if t.reference_key and child_obj.fields[t.reference_key]: | |||||
from_flds, to_flds = self.get_label_and_type(t.from_table, t.to_table) | |||||
for cl in checklist: | |||||
if cl['match_id'] == t.match_id: | |||||
if t.to_field: | |||||
cur_val = child_obj.fields.get(cl['to_fld']) | |||||
else: | |||||
cur_val = par_obj.fields.get(cl['to_fld']) | |||||
if to_flds[cl['to_fld']]['fieldtype'] in ['Currency', 'Float']: | |||||
cur_val = '%.2f' % flt(cur_val) | |||||
if cl['op'] == '=' and to_flds[cl['to_fld']]['fieldtype'] in ['Currency', 'Float']: | |||||
consistent = sql("""select name, %s from `tab%s` \ | |||||
where name = %s and %s - %s <= 0.5"""% (cl['from_fld'], t.from_table, '%s', '%s', \ | |||||
cl['from_fld']), (child_obj.fields[t.reference_key], flt(cur_val))) | |||||
else: | |||||
consistent = sql("""select name, %s from `tab%s` \ | |||||
where name = %s and %s %s ifnull(%s, '')""" % (cl['from_fld'], t.from_table, \ | |||||
'%s', '%s', cl['op'], cl['from_fld']), (child_obj.fields[t.reference_key], \ | |||||
to_flds[cl['to_fld']]['fieldtype'] in ('Currency', 'Float', 'Int') \ | |||||
and flt(cur_val) or cstr(cur_val))) | |||||
if not self.ref_doc: | |||||
det = sql("""select name, parent from `tab%s` where name = \"%s\"""" % (t.from_table, child_obj.fields[t.reference_key])) | |||||
self.ref_doc = det[0][1] and det[0][1] or det[0][0] | |||||
if not consistent: | |||||
self.give_message(from_flds[cl['from_fld']]['label'], to_flds[cl['to_fld']]['label'], cl['op']) | |||||
def give_message(self, from_label, to_label, operator): | |||||
""" Gives message and raise exception""" | |||||
op_in_words = {'=':'equal to ', '>=':'greater than equal to ', '>':'greater than ', '<=':'less than equal to ', '<':'less than '} | |||||
msgprint("%s should be %s %s of %s: %s" % (to_label, op_in_words[operator], from_label, 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("%s: %s does not exists in the system" % (self.doc.from_doctype, self.ref_doc), raise_exception=1) | |||||
elif self.doc.ref_doc_submitted and det[0][1] != 1: | |||||
msgprint("%s: %s is not submitted document." % (self.doc.from_doctype, self.ref_doc), raise_exception=1) | |||||
def on_update(self): | |||||
""" | |||||
If developer_mode = 1, mapper will be written to files | |||||
""" | |||||
import conf | |||||
if hasattr(conf, 'developer_mode') and conf.developer_mode: | |||||
from webnotes.modules.export_file import export_to_files | |||||
export_to_files(record_list=[[self.doc.doctype, self.doc.name]]) | |||||
@@ -1,106 +0,0 @@ | |||||
[ | |||||
{ | |||||
"creation": "2013-01-10 16:34:02", | |||||
"docstatus": 0, | |||||
"modified": "2013-01-22 14:56:01", | |||||
"modified_by": "Administrator", | |||||
"owner": "Administrator" | |||||
}, | |||||
{ | |||||
"doctype": "DocType", | |||||
"issingle": 0, | |||||
"module": "Core", | |||||
"name": "__common__" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"name": "__common__", | |||||
"parent": "DocType Mapper", | |||||
"parentfield": "fields", | |||||
"parenttype": "DocType", | |||||
"permlevel": 0 | |||||
}, | |||||
{ | |||||
"create": 1, | |||||
"doctype": "DocPerm", | |||||
"name": "__common__", | |||||
"parent": "DocType Mapper", | |||||
"parentfield": "permissions", | |||||
"parenttype": "DocType", | |||||
"permlevel": 0, | |||||
"read": 1, | |||||
"report": 1, | |||||
"submit": 0, | |||||
"write": 1 | |||||
}, | |||||
{ | |||||
"doctype": "DocType", | |||||
"name": "DocType Mapper" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "module", | |||||
"fieldtype": "Select", | |||||
"label": "Module", | |||||
"oldfieldname": "module", | |||||
"oldfieldtype": "Select", | |||||
"options": "link:Module Def", | |||||
"reqd": 1 | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "from_doctype", | |||||
"fieldtype": "Select", | |||||
"label": "From DocType", | |||||
"no_copy": 1, | |||||
"oldfieldname": "from_doctype", | |||||
"oldfieldtype": "Select", | |||||
"options": "link:DocType" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "to_doctype", | |||||
"fieldtype": "Select", | |||||
"label": "To DocType", | |||||
"no_copy": 1, | |||||
"oldfieldname": "to_doctype", | |||||
"oldfieldtype": "Select", | |||||
"options": "link:DocType" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "ref_doc_submitted", | |||||
"fieldtype": "Check", | |||||
"label": "Ref Doc should be submitted?", | |||||
"oldfieldname": "ref_doc_submitted", | |||||
"oldfieldtype": "Check" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "field_mapper_details", | |||||
"fieldtype": "Table", | |||||
"label": "Field Mapper Details", | |||||
"oldfieldname": "field_mapper_details", | |||||
"oldfieldtype": "Table", | |||||
"options": "Field Mapper Detail" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "table_mapper_details", | |||||
"fieldtype": "Table", | |||||
"label": "Table Mapper Details", | |||||
"oldfieldname": "table_mapper_details", | |||||
"oldfieldtype": "Table", | |||||
"options": "Table Mapper Detail" | |||||
}, | |||||
{ | |||||
"doctype": "DocPerm", | |||||
"role": "Administrator" | |||||
}, | |||||
{ | |||||
"amend": 0, | |||||
"cancel": 0, | |||||
"doctype": "DocPerm", | |||||
"role": "System Manager" | |||||
} | |||||
] |
@@ -1 +0,0 @@ | |||||
Field level mapping in DocType Mapper |
@@ -1 +0,0 @@ | |||||
from __future__ import unicode_literals |
@@ -1,27 +0,0 @@ | |||||
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) | |||||
# | |||||
# MIT License (MIT) | |||||
# | |||||
# Permission is hereby granted, free of charge, to any person obtaining a | |||||
# copy of this software and associated documentation files (the "Software"), | |||||
# to deal in the Software without restriction, including without limitation | |||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||||
# and/or sell copies of the Software, and to permit persons to whom the | |||||
# Software is furnished to do so, subject to the following conditions: | |||||
# | |||||
# The above copyright notice and this permission notice shall be included in | |||||
# all copies or substantial portions of the Software. | |||||
# | |||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |||||
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |||||
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |||||
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||||
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |||||
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||||
from __future__ import unicode_literals | |||||
import webnotes | |||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl |
@@ -1,81 +0,0 @@ | |||||
[ | |||||
{ | |||||
"creation": "2013-02-22 01:27:33", | |||||
"docstatus": 0, | |||||
"modified": "2013-03-07 07:03:21", | |||||
"modified_by": "Administrator", | |||||
"owner": "Administrator" | |||||
}, | |||||
{ | |||||
"autoname": "FMD/.#####", | |||||
"doctype": "DocType", | |||||
"istable": 1, | |||||
"module": "Core", | |||||
"name": "__common__" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"name": "__common__", | |||||
"parent": "Field Mapper Detail", | |||||
"parentfield": "fields", | |||||
"parenttype": "DocType", | |||||
"permlevel": 0 | |||||
}, | |||||
{ | |||||
"doctype": "DocType", | |||||
"name": "Field Mapper Detail" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "from_field", | |||||
"fieldtype": "Data", | |||||
"label": "From Field", | |||||
"oldfieldname": "from_field", | |||||
"oldfieldtype": "Data", | |||||
"print_width": "180px", | |||||
"width": "180px" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "to_field", | |||||
"fieldtype": "Data", | |||||
"label": "To Field", | |||||
"oldfieldname": "to_field", | |||||
"oldfieldtype": "Data", | |||||
"print_width": "180px", | |||||
"width": "180px" | |||||
}, | |||||
{ | |||||
"default": "0", | |||||
"doctype": "DocField", | |||||
"fieldname": "match_id", | |||||
"fieldtype": "Int", | |||||
"label": "Match Id", | |||||
"oldfieldname": "match_id", | |||||
"oldfieldtype": "Int", | |||||
"print_width": "50px", | |||||
"width": "50px" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "map", | |||||
"fieldtype": "Select", | |||||
"label": "Map", | |||||
"oldfieldname": "map", | |||||
"oldfieldtype": "Select", | |||||
"options": "Yes\nNo", | |||||
"print_width": "50px", | |||||
"width": "50px" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "checking_operator", | |||||
"fieldtype": "Select", | |||||
"label": "Checking Operator (To Fld, Operator, From Fld)", | |||||
"oldfieldname": "checking_operator", | |||||
"oldfieldtype": "Select", | |||||
"options": "\n=\n>\n>=\n<\n<=", | |||||
"print_width": "180px", | |||||
"width": "180px" | |||||
} | |||||
] |
@@ -1 +0,0 @@ | |||||
Mapping of child tables between two main DocTypes of DocType Mapper |
@@ -1 +0,0 @@ | |||||
from __future__ import unicode_literals |
@@ -1,27 +0,0 @@ | |||||
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) | |||||
# | |||||
# MIT License (MIT) | |||||
# | |||||
# Permission is hereby granted, free of charge, to any person obtaining a | |||||
# copy of this software and associated documentation files (the "Software"), | |||||
# to deal in the Software without restriction, including without limitation | |||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||||
# and/or sell copies of the Software, and to permit persons to whom the | |||||
# Software is furnished to do so, subject to the following conditions: | |||||
# | |||||
# The above copyright notice and this permission notice shall be included in | |||||
# all copies or substantial portions of the Software. | |||||
# | |||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |||||
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |||||
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |||||
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||||
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |||||
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||||
from __future__ import unicode_literals | |||||
import webnotes | |||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl |
@@ -1,110 +0,0 @@ | |||||
[ | |||||
{ | |||||
"creation": "2013-02-22 01:27:35", | |||||
"docstatus": 0, | |||||
"modified": "2013-03-07 07:03:33", | |||||
"modified_by": "Administrator", | |||||
"owner": "Administrator" | |||||
}, | |||||
{ | |||||
"autoname": "TMD/.#######", | |||||
"doctype": "DocType", | |||||
"istable": 1, | |||||
"module": "Core", | |||||
"name": "__common__" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"name": "__common__", | |||||
"parent": "Table Mapper Detail", | |||||
"parentfield": "fields", | |||||
"parenttype": "DocType", | |||||
"permlevel": 0 | |||||
}, | |||||
{ | |||||
"doctype": "DocType", | |||||
"name": "Table Mapper Detail" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "from_table", | |||||
"fieldtype": "Select", | |||||
"label": "From Table", | |||||
"oldfieldname": "from_table", | |||||
"oldfieldtype": "Select", | |||||
"options": "link:DocType", | |||||
"print_width": "140px", | |||||
"reqd": 1, | |||||
"width": "140px" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "to_table", | |||||
"fieldtype": "Select", | |||||
"label": "To Table", | |||||
"oldfieldname": "to_table", | |||||
"oldfieldtype": "Select", | |||||
"options": "link:DocType", | |||||
"print_width": "140px", | |||||
"reqd": 1, | |||||
"width": "140px" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "from_field", | |||||
"fieldtype": "Data", | |||||
"label": "From Field", | |||||
"oldfieldname": "from_field", | |||||
"oldfieldtype": "Data", | |||||
"print_width": "140px", | |||||
"width": "140px" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "to_field", | |||||
"fieldtype": "Data", | |||||
"label": "To Field", | |||||
"oldfieldname": "to_field", | |||||
"oldfieldtype": "Data", | |||||
"print_width": "140px", | |||||
"width": "140px" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "match_id", | |||||
"fieldtype": "Int", | |||||
"label": "Match Id", | |||||
"oldfieldname": "match_id", | |||||
"oldfieldtype": "Int", | |||||
"print_width": "60px", | |||||
"reqd": 0, | |||||
"width": "60px" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "validation_logic", | |||||
"fieldtype": "Small Text", | |||||
"label": "Validation Logic", | |||||
"oldfieldname": "validation_logic", | |||||
"oldfieldtype": "Small Text", | |||||
"print_width": "150px", | |||||
"reqd": 1, | |||||
"width": "150px" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "reference_doctype_key", | |||||
"fieldtype": "Data", | |||||
"label": "Reference DocType Key", | |||||
"oldfieldname": "reference_doctype_key", | |||||
"oldfieldtype": "Data" | |||||
}, | |||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "reference_key", | |||||
"fieldtype": "Data", | |||||
"label": "Reference Docname Key", | |||||
"oldfieldname": "reference_key", | |||||
"oldfieldtype": "Data" | |||||
} | |||||
] |
@@ -267,17 +267,4 @@ _f.Frm.prototype.call = function(opts) { | |||||
_f.Frm.prototype.get_field = function(field) { | _f.Frm.prototype.get_field = function(field) { | ||||
return cur_frm.fields_dict[field]; | return cur_frm.fields_dict[field]; | ||||
} | |||||
_f.Frm.prototype.map = function(from_to_list) { | |||||
var doctype = from_to_list[0][1]; | |||||
console.log("Making " + doctype); | |||||
var new_docname = wn.model.make_new_doc_and_get_name(doctype); | |||||
$c("dt_map", { | |||||
"docs": wn.model.compress([locals[doctype][new_docname]]), | |||||
"from_doctype": cur_frm.doc.doctype, | |||||
"to_doctype": doctype, | |||||
"from_docname": cur_frm.doc.name, | |||||
"from_to_list": JSON.stringify(from_to_list), | |||||
}, function(r, rt) { if(!r.exc) loaddoc(doctype, new_docname); }); | |||||
} | } |
@@ -397,17 +397,6 @@ def copy_doclist(in_doclist): | |||||
new_doclist.append(doc(d.fields.copy())) | new_doclist.append(doc(d.fields.copy())) | ||||
return doclist(new_doclist) | return doclist(new_doclist) | ||||
def map_doclist(from_to_list, from_docname, to_doclist=None): | |||||
from_doctype, to_doctype = from_to_list[0][0], from_to_list[0][1] | |||||
if to_doclist: | |||||
to_doclist = bean(to_doclist).doclist | |||||
else: | |||||
to_doclist = bean({"doctype": to_doctype}).doclist | |||||
mapper = get_obj("DocType Mapper", "-".join(from_to_list[0])) | |||||
to_doclist = mapper.dt_map(from_doctype, to_doctype, from_docname, to_doclist[0], to_doclist, from_to_list) | |||||
return to_doclist | |||||
def compare(val1, condition, val2): | def compare(val1, condition, val2): | ||||
import webnotes.utils | import webnotes.utils | ||||
@@ -73,30 +73,6 @@ def web_logout(): | |||||
<p><a href='index'>Back to Home</a></p>""") | <p><a href='index'>Back to Home</a></p>""") | ||||
webnotes.login_manager.logout() | webnotes.login_manager.logout() | ||||
@webnotes.whitelist() | |||||
def dt_map(): | |||||
import webnotes | |||||
import webnotes.model.utils | |||||
from webnotes.model.code import get_obj | |||||
from webnotes.model.doc import Document | |||||
from webnotes.model.bean import Bean | |||||
form_dict = webnotes.form_dict | |||||
dt_list = webnotes.model.utils.expand(form_dict.get('docs')) | |||||
from_doctype = form_dict.get('from_doctype') | |||||
to_doctype = form_dict.get('to_doctype') | |||||
from_docname = form_dict.get('from_docname') | |||||
from_to_list = form_dict.get('from_to_list') | |||||
dm = get_obj('DocType Mapper', from_doctype +'-' + to_doctype) | |||||
dl = dm.dt_map(from_doctype, to_doctype, from_docname, | |||||
Document(fielddata = dt_list[0]), | |||||
(len(dt_list) > 1) and Bean(dt_list).doclist or [], from_to_list) | |||||
webnotes.response['docs'] = dl | |||||
@webnotes.whitelist() | @webnotes.whitelist() | ||||
def uploadfile(): | def uploadfile(): | ||||
import webnotes.utils | import webnotes.utils | ||||
@@ -94,16 +94,7 @@ def rename_doctype(doctype, old, new, force=False): | |||||
# rename comments | # rename comments | ||||
webnotes.conn.sql("""update tabComment set comment_doctype=%s where comment_doctype=%s""", | webnotes.conn.sql("""update tabComment set comment_doctype=%s where comment_doctype=%s""", | ||||
(new, old)) | (new, old)) | ||||
# update mapper | |||||
rename_mapper(new) | |||||
def rename_mapper(new): | |||||
for mapper in webnotes.conn.sql("""select name, from_doctype, to_doctype | |||||
from `tabDocType Mapper` where from_doctype=%s or to_doctype=%s""", (new, new), as_dict=1): | |||||
if not webnotes.conn.exists("DocType Mapper", mapper.from_doctype + "-" + mapper.to_doctype): | |||||
rename_doc("DocType Mapper", mapper.name, mapper.from_doctype + "-" + mapper.to_doctype, force=True) | |||||
def update_child_docs(old, new, doclist): | def update_child_docs(old, new, doclist): | ||||
# update "parent" | # update "parent" | ||||
child_doctypes = (d.options for d in doclist | child_doctypes = (d.options for d in doclist | ||||