[IMP]Improved code for show message if selection of same column and can not match file field with object field.
bzr revid: kch@tinyerp.com-20110902121642-qv4ike63cuqaa9vk
This commit is contained in:
@@ -1411,6 +1411,10 @@ class Import(View):
|
||||
@openerpweb.httprequest
|
||||
def import_data(self, req, **params):
|
||||
import StringIO
|
||||
_fields = {}
|
||||
_fields_invert = {}
|
||||
prefix_node=''
|
||||
prefix_value = ''
|
||||
|
||||
context = req.session.eval_context(req.context)
|
||||
modle_obj = req.session.model(params.get('model'))
|
||||
@@ -1443,6 +1447,23 @@ class Import(View):
|
||||
if not isinstance(fields, list):
|
||||
fields = [fields]
|
||||
|
||||
flds = dict(req.session.model(params.get('model')).fields_get(False, req.session.eval_context(req.context)))
|
||||
flds.update({'id':{'string':'ID'},'.id':{'string':'Database ID'}})
|
||||
fields_order = flds.keys()
|
||||
for field in fields_order:
|
||||
st_name = prefix_value+flds[field]['string'] or field
|
||||
_fields[prefix_node+field] = st_name
|
||||
_fields_invert[st_name] = prefix_node+field
|
||||
|
||||
unmatch_field = []
|
||||
for fld in fields:
|
||||
if ((fld not in _fields.keys()) and (fld not in _fields_invert.keys())):
|
||||
unmatch_field.append(fld)
|
||||
|
||||
if unmatch_field:
|
||||
error = {'message':("You cannot import the fields '%s',because we cannot auto-detect it." % (unmatch_field))}
|
||||
return simplejson.dumps({'error':error})
|
||||
|
||||
for line in data:
|
||||
try:
|
||||
datas.append(map(lambda x:x.decode(params.get('csvcode')).encode('utf-8'), line))
|
||||
|
||||
@@ -66,18 +66,22 @@ openerp.base.DataImport = openerp.base.Dialog.extend({
|
||||
var success_node = $("#success");
|
||||
success_node.append(QWeb.render('ImportView-result',{'success': results['success']}));
|
||||
}
|
||||
var mm = [];
|
||||
var selected_fields = [];
|
||||
$("td #sel_field").click(function(){
|
||||
mm = [];
|
||||
selected_fields = [];
|
||||
$("td #sel_field option:selected").each(function(){
|
||||
mm.push($(this).index());
|
||||
selected_fields.push($(this).index());
|
||||
});
|
||||
});
|
||||
$("td #sel_field").change(function(){
|
||||
$(this).css('background-color','');
|
||||
var kk = this.selectedIndex;
|
||||
if ($.inArray(kk,mm) > -1){
|
||||
$("#message").empty();
|
||||
$("td #sel_field").css('background-color','');
|
||||
$(".ui-button-text:contains('Import File')").parent().attr("disabled",false);
|
||||
var curr_selected = this.selectedIndex;
|
||||
if ($.inArray(curr_selected,selected_fields) > -1){
|
||||
$(this).css('background-color','#FF6666');
|
||||
$("#message").append("Selected column should not be same.");
|
||||
$(".ui-button-text:contains('Import File')").parent().attr("disabled",true);
|
||||
}else{
|
||||
$(this).css('background-color','');
|
||||
}
|
||||
|
||||
@@ -1415,7 +1415,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table align="center">
|
||||
<table align="left">
|
||||
<tr>
|
||||
<td><label>CSV File:</label></td>
|
||||
<td>
|
||||
@@ -1439,6 +1439,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="message" style="color:red"></div>
|
||||
<div id="result"></div>
|
||||
<fieldset>
|
||||
<legend style="cursor:pointer;">CSV Options</legend>
|
||||
|
||||
Reference in New Issue
Block a user