[MERGE] forward port of branch 7.0 up to 922a52d
authorDenis Ledoux <dle@odoo.com>
Fri, 14 Nov 2014 16:59:00 +0000 (17:59 +0100)
committerDenis Ledoux <dle@odoo.com>
Fri, 14 Nov 2014 16:59:00 +0000 (17:59 +0100)
1  2 
addons/purchase/stock.py
addons/web/static/src/js/search.js

diff --combined addons/purchase/stock.py
@@@ -30,6 -30,7 +30,6 @@@ class stock_move(osv.osv)
              readonly=True),
      }
  
 -stock_move()
  
  #
  # Inherit of picking to add the link to the PO
@@@ -71,7 -72,7 +71,7 @@@ class stock_picking(osv.osv)
  
      def get_currency_id(self, cursor, user, picking):
          if picking.purchase_id:
 -            return picking.purchase_id.pricelist_id.currency_id.id
 +            return picking.purchase_id.currency_id.id
          else:
              return super(stock_picking, self).get_currency_id(cursor, user, picking)
  
@@@ -146,6 -147,16 +146,16 @@@ class stock_partial_picking(osv.osv_mem
                  return {'cost': cost, 'currency': company_currency}
          return super(stock_partial_picking, self)._product_cost_for_average_update(cr, uid, move)
  
+     def _partial_move_for(self, cr, uid, move, context=None):
+         partial_move = super(stock_partial_picking, self)._partial_move_for(cr, uid, move, context=context)
+         if move.picking_id.purchase_id and move.purchase_line_id:
+             pur_currency = move.purchase_line_id.order_id.currency_id.id
+             partial_move.update({
+                 'currency': pur_currency,
+                 'cost': move.purchase_line_id.price_unit
+             })
+         return partial_move
      def __get_help_text(self, cursor, user, picking_id, context=None):
          picking = self.pool.get('stock.picking').browse(cursor, user, picking_id, context=context)
          if picking.purchase_id:
@@@ -1,9 -1,4 +1,9 @@@
 -openerp.web.search = function(instance) {
 +
 +(function() {
 +
 +var instance = openerp;
 +openerp.web.search = {};
 +
  var QWeb = instance.web.qweb,
        _t =  instance.web._t,
       _lt = instance.web._lt;
@@@ -70,11 -65,8 +70,11 @@@ my.SearchQuery = B.Collection.extend(
          }, this);
      },
      add: function (values, options) {
 -        options || (options = {});
 -        if (!(values instanceof Array)) {
 +        options = options || {};
 +
 +        if (!values) {
 +            values = [];
 +        } else if (!(values instanceof Array)) {
              values = [values];
          }
  
                      && facet.get('field') === model.get('field');
              });
              if (previous) {
 -                previous.values.add(model.get('values'));
 +                previous.values.add(model.get('values'), _.omit(options, 'at', 'merge'));
                  return;
              }
              B.Collection.prototype.add.call(this, model, options);
          }, this);
 +        // warning: in backbone 1.0+ add is supposed to return the added models,
 +        // but here toggle may delegate to add and return its value directly.
 +        // return value of neither seems actually used but should be tested
 +        // before change, probably
          return this;
      },
      toggle: function (value, options) {
 -        options || (options = {});
 +        options = options || {};
  
          var facet = this.detect(function (facet) {
              return facet.get('category') === value.category
@@@ -160,7 -148,7 +160,7 @@@ my.InputView = instance.web.Widget.exte
              range.setStart(root, 0);
          }
          if (range.endContainer === this.el && range.endOffset === 1) {
 -            range.setEnd(root, root.length)
 +            range.setEnd(root, root.length);
          }
          assert(range.startContainer === root,
                 "selection should be in the input view");
          return {
              start: range.startOffset,
              end: range.endOffset
 -        }
 +        };
      },
      onKeydown: function (e) {
          this.el.normalize();
          setTimeout(function () {
              // Read text content (ignore pasted HTML)
              var data = this.$el.text();
 +            if (!data)
 +                return; 
              // paste raw text back in
              this.$el.empty().text(data);
              this.el.normalize();
@@@ -371,6 -357,13 +371,6 @@@ instance.web.SearchView = instance.web.
       * @param {Boolean} [options.disable_custom_filters=false] do not load custom filters from ir.filters
       */
      init: function(parent, dataset, view_id, defaults, options) {
 -        // Backward compatibility - Can be removed when forward porting
 -        if (Object(options) !== options) {
 -            options = {
 -                hidden: !!options
 -            };
 -        }
 -        // End of Backward compatibility
          this.options = _.defaults(options || {}, {
              hidden: false,
              disable_custom_filters: false,
              });
  
              this.alive($.when(load_view)).then(function (r) {
 -                return self.search_view_loaded(r)
 +                return self.search_view_loaded(r);
              }).fail(function () {
                  self.ready.reject.apply(null, arguments);
              });
  
                  if (item.facet !== undefined) {
                      // regular completion item
 +                    if (item.first) {
 +                        $item.css('borderTop', '1px solid #cccccc');
 +                    }
                      return $item.append(
                          (item.label)
                              ? $('<a>').html(item.label)
              .filter(function (input) { return input.visible(); })
              .invoke('complete', req.term)
              .value()).then(function () {
 -                resp(_(_(arguments).compact()).flatten(true));
 -        });
 +                resp(_(arguments).chain()
 +                    .compact()
 +                    .map(function (completion) {
 +                        if (completion.length && completion[0].facet !== undefined) {
 +                            completion[0].first = true;
 +                        }
 +                        return completion;
 +                    })
 +                    .flatten(true)
 +                    .value());
 +                });
      },
  
      /**
       * @returns instance.web.search.Field
       */
      make_field: function (item, field, parent) {
 +        // M2O combined with selection widget is pointless and broken in search views,
 +        // but has been used in the past for unsupported hacks -> ignore it
 +        if (field.type === "many2one" && item.attrs.widget === "selection"){
 +            item.attrs.widget = undefined;
 +        }
          var obj = instance.web.search.fields.get_any( [item.attrs.widget, field.type]);
          if(obj) {
              return new (obj) (item, field, parent || this);
@@@ -983,7 -959,7 +983,7 @@@ instance.web.search.Input = instance.we
       * @returns {jQuery.Deferred<null|Array>}
       */
      complete: function (value) {
 -        return $.when(null)
 +        return $.when(null);
      },
      /**
       * Returns a Facet instance for the provided defaults if they apply to
@@@ -1106,7 -1082,7 +1106,7 @@@ instance.web.search.FilterGroup = insta
              icon: this.icon,
              values: values,
              field: this
 -        }
 +        };
      },
      make_value: function (filter) {
          return {
  
          if (!contexts.length) { return; }
          if (contexts.length === 1) { return contexts[0]; }
 -        return _.extend(new instance.web.CompoundContext, {
 +        return _.extend(new instance.web.CompoundContext(), {
              __contexts: contexts
          });
      },
                  label: _.str.sprintf(self.completion_label.toString(),
                                       _.escape(facet_value.label)),
                  facet: self.make_facet([facet_value])
 -            }
 +            };
          }));
      }
  });
@@@ -1231,7 -1207,7 +1231,7 @@@ instance.web.search.GroupbyGroup = inst
                  get_context: this.proxy('get_context'),
                  get_domain: this.proxy('get_domain'),
                  get_groupby: this.proxy('get_groupby')
 -            }
 +            };
          }
      },
      match_facet: function (facet) {
@@@ -1309,7 -1285,7 +1309,7 @@@ instance.web.search.Field = instance.we
  
          if (contexts.length === 1) { return contexts[0]; }
  
 -        return _.extend(new instance.web.CompoundContext, {
 +        return _.extend(new instance.web.CompoundContext(), {
              __contexts: contexts
          });
      },
              domains.unshift(['|']);
          }
  
 -        return _.extend(new instance.web.CompoundDomain, {
 +        return _.extend(new instance.web.CompoundDomain(), {
              __domains: domains
          });
      }
@@@ -1521,10 -1497,18 +1521,18 @@@ instance.web.search.DateField = instanc
          return instance.web.date_to_str(facetValue.get('value'));
      },
      complete: function (needle) {
+         var d;
          try {
-             var d = instance.web.str_to_date(instance.web.parse_value(needle, {'widget': 'date'}));
+             var t = (this.attrs && this.attrs.type === 'datetime') ? 'datetime' : 'date';
+             var v = instance.web.parse_value(needle, {'widget': t});
+             if (t === 'datetime'){
+                 d = instance.web.str_to_datetime(v);
+             }
+             else{
+                 d = instance.web.str_to_date(v);
+             }
          } catch (e) {
-             return false;
+             // pass
          }
          if (!d) { return $.when(null); }
          var date_string = instance.web.format_value(d, this.attrs);
@@@ -1601,7 -1585,7 +1609,7 @@@ instance.web.search.ManyToOneField = in
          return this.model.call('name_get', [value]).then(function (names) {
              if (_(names).isEmpty()) { return null; }
              return facet_from(self, names[0]);
 -        })
 +        });
      },
      value_from: function (facetValue) {
          return facetValue.get('label');
@@@ -1967,7 -1951,7 +1975,7 @@@ instance.web.search.ExtendedSearchPropo
      },
      changed: function() {
          var nval = this.$(".searchview_extended_prop_field").val();
 -        if(this.attrs.selected == null || nval != this.attrs.selected.name) {
 +        if(this.attrs.selected === null || this.attrs.selected === undefined || nval != this.attrs.selected.name) {
              this.select_field(_.detect(this.fields, function(x) {return x.name == nval;}));
          }
      },
       */
      select_field: function(field) {
          var self = this;
 -        if(this.attrs.selected != null) {
 +        if(this.attrs.selected !== null && this.attrs.selected !== undefined) {
              this.value.destroy();
              this.value = null;
              this.$('.searchview_extended_prop_op').html('');
          }
          this.attrs.selected = field;
 -        if(field == null) {
 +        if(field === null || field === undefined) {
              return;
          }
  
  
      },
      get_proposition: function() {
 -        if ( this.attrs.selected == null)
 +        if (this.attrs.selected === null || this.attrs.selected === undefined)
              return null;
          var field = this.attrs.selected;
          var op_select = this.$('.searchview_extended_prop_op')[0];
@@@ -2145,7 -2129,7 +2153,7 @@@ instance.web.search.ExtendedSearchPropo
      get_value: function() {
          try {
              var val =this.$el.val();
 -            return instance.web.parse_value(val == "" ? 0 : val, {'widget': 'integer'});
 +            return instance.web.parse_value(val === "" ? 0 : val, {'widget': 'integer'});
          } catch (e) {
              return "";
          }
@@@ -2172,7 -2156,7 +2180,7 @@@ instance.web.search.ExtendedSearchPropo
      get_value: function() {
          try {
              var val =this.$el.val();
 -            return instance.web.parse_value(val == "" ? 0.0 : val, {'widget': 'float'});
 +            return instance.web.parse_value(val === "" ? 0.0 : val, {'widget': 'float'});
          } catch (e) {
              return "";
          }
@@@ -2227,6 -2211,6 +2235,6 @@@ instance.web.search.custom_filters = ne
      'id': 'instance.web.search.ExtendedSearchProposition.Id'
  });
  
 -};
 +})();
  
  // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: