[MERGE] Forward-port of 7.0 bugfixes up to e2201369a314feaec70a485f0459c1dcdcecd82b
authorDenis Ledoux <dle@odoo.com>
Tue, 24 Jun 2014 11:56:51 +0000 (13:56 +0200)
committerDenis Ledoux <dle@odoo.com>
Tue, 24 Jun 2014 11:56:51 +0000 (13:56 +0200)
1  2 
addons/web/static/src/js/formats.js

@@@ -1,9 -1,5 +1,9 @@@
  
 -openerp.web.formats = function(instance) {
 +(function() {
 +
 +var instance = openerp;
 +openerp.web.formats = {};
 +
  var _t = instance.web._t;
  
  /**
@@@ -145,7 -141,6 +145,7 @@@ instance.web.format_value = function (v
                  return '';
              }
              console.warn('Field', descriptor, 'had an empty string as value, treating as false...');
 +            return value_if_empty === undefined ?  '' : value_if_empty;
          case false:
          case undefined:
          case Infinity:
          case 'selection': case 'statusbar':
              // Each choice is [value, label]
              if(_.isArray(value)) {
 -                 value = value[0]
 +                 return value[1];
              }
              var result = _(descriptor.selection).detect(function (choice) {
                  return choice[0] === value;
@@@ -225,9 -220,9 +225,9 @@@ instance.web.parse_value = function (va
          case "":
              return value_if_empty === undefined ?  false : value_if_empty;
      }
 +    var tmp;
      switch (descriptor.widget || descriptor.type || (descriptor.field && descriptor.field.type)) {
          case 'integer':
 -            var tmp;
              do {
                  tmp = value;
                  value = value.replace(instance.web._t.database.parameters.thousands_sep, "");
                  throw new Error(_.str.sprintf(_t("'%s' is not a correct integer"), value));
              return tmp;
          case 'float':
 -            var tmp = Number(value);
 +            tmp = Number(value);
              if (!isNaN(tmp))
                  return tmp;
  
                      value, (date_pattern + ' ' + time_pattern));
              if (datetime !== null)
                  return instance.web.datetime_to_str(datetime);
-             datetime = Date.parseExact(value.replace(/\d+/g, function(m){
+             datetime = Date.parseExact(value.toString().replace(/\d+/g, function(m){
                  return m.length === 1 ? "0" + m : m ;
              }), (date_pattern + ' ' + time_pattern));
              if (datetime !== null)
              var date = Date.parseExact(value, date_pattern);
              if (date !== null)
                  return instance.web.date_to_str(date);
-             date = Date.parseExact(value.replace(/\d+/g, function(m){
+             date = Date.parseExact(value.toString().replace(/\d+/g, function(m){
                  return m.length === 1 ? "0" + m : m ;
              }), date_pattern);
              if (date !== null)
@@@ -361,4 -356,4 +361,4 @@@ instance.web.round_decimals = function(
      return instance.web.round_precision(value, Math.pow(10,-decimals));
  };
  
 -};
 +})();