[IMP]Improved code for show message if selection of same column and can not match...
authorKunal Chavda (OpenERP) <kch@tinyerp.com>
Fri, 2 Sep 2011 12:16:42 +0000 (17:46 +0530)
committerKunal Chavda (OpenERP) <kch@tinyerp.com>
Fri, 2 Sep 2011 12:16:42 +0000 (17:46 +0530)
bzr revid: kch@tinyerp.com-20110902121642-qv4ike63cuqaa9vk

addons/base/controllers/main.py
addons/base/static/src/js/data_import.js
addons/base/static/src/xml/base.xml

index 3a1d84b..23ec289 100644 (file)
@@ -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))
index e09b4dc..6329f09 100644 (file)
@@ -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','');
             }
index 42c64a3..7d8dc77 100644 (file)
         </tr>
         <tr>
             <td>
-                <table align="center">
+                <table align="left">
                     <tr>
                         <td><label>CSV File:</label></td>
                         <td>
                             </td>
                         </tr>
                     </table>
+                    <div id="message" style="color:red"></div>
                     <div id="result"></div>
                     <fieldset>
                         <legend style="cursor:pointer;">CSV Options</legend>