[imp] added default name on false quick create in m2o
bzr revid: nicolas.vanhoren@openerp.com-20110617141945-wnnhkhf8wezwfyed
This commit is contained in:
parent
e975b4ac1e
commit
157273f15a
|
@ -455,9 +455,10 @@ class DataSet(openerpweb.Controller):
|
||||||
return {'result': r}
|
return {'result': r}
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
@openerpweb.jsonrequest
|
||||||
def default_get(self, req, model, fields, context={}):
|
def default_get(self, req, model, fields):
|
||||||
m = req.session.model(model)
|
m = req.session.model(model)
|
||||||
r = m.default_get(fields, context)
|
ctx = _eval_domain_and_context(req, [req.context], [])["context"]
|
||||||
|
r = m.default_get(fields, ctx)
|
||||||
return {'result': r}
|
return {'result': r}
|
||||||
|
|
||||||
class DataGroup(openerpweb.Controller):
|
class DataGroup(openerpweb.Controller):
|
||||||
|
|
|
@ -231,10 +231,10 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
|
||||||
* @param {openerp.base.Session} session current OpenERP session
|
* @param {openerp.base.Session} session current OpenERP session
|
||||||
* @param {String} model the OpenERP model this dataset will manage
|
* @param {String} model the OpenERP model this dataset will manage
|
||||||
*/
|
*/
|
||||||
init: function(session, model) {
|
init: function(session, model, context) {
|
||||||
this._super(session);
|
this._super(session);
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.context = {};
|
this.context = context || {};
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
},
|
},
|
||||||
|
@ -371,9 +371,9 @@ openerp.base.DataSetStatic = openerp.base.DataSet.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
openerp.base.DataSetSearch = openerp.base.DataSet.extend({
|
openerp.base.DataSetSearch = openerp.base.DataSet.extend({
|
||||||
init: function(session, model) {
|
init: function(session, model, context, domain) {
|
||||||
this._super(session, model);
|
this._super(session, model, context);
|
||||||
this.domain = [];
|
this.domain = domain || [];
|
||||||
this._sort = [];
|
this._sort = [];
|
||||||
this.offset = 0;
|
this.offset = 0;
|
||||||
// subset records[offset:offset+limit]
|
// subset records[offset:offset+limit]
|
||||||
|
@ -440,33 +440,34 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
openerp.base.CompoundContext = function(source_context) {
|
openerp.base.CompoundContext = function() {
|
||||||
this.__ref = "compound_context";
|
this.__ref = "compound_context";
|
||||||
this.__contexts = [];
|
this.__contexts = [];
|
||||||
if (source_context === undefined)
|
var self = this;
|
||||||
return;
|
_.each(arguments, function(x) {
|
||||||
else if (source_context.__ref === "compound_context")
|
self.add(x);
|
||||||
this.__contexts.concat(source_context.__contexts);
|
});
|
||||||
else
|
|
||||||
this.add(source_context);
|
|
||||||
};
|
};
|
||||||
openerp.base.CompoundContext.prototype.add = function(context) {
|
openerp.base.CompoundContext.prototype.add = function(context) {
|
||||||
this.__contexts.push(context);
|
if (context.__ref === "compound_context")
|
||||||
|
this.__contexts = this.__contexts.concat(context.__contexts);
|
||||||
|
else
|
||||||
|
this.__contexts.push(context);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
openerp.base.CompoundDomain = function(source_domain) {
|
openerp.base.CompoundDomain = function() {
|
||||||
this.__ref = "compound_domain";
|
this.__ref = "compound_domain";
|
||||||
this.__domains = [];
|
this.__domains = [];
|
||||||
if (source_domain === undefined)
|
_.each(arguments, function(x) {
|
||||||
return;
|
self.add(x);
|
||||||
else if (source_domain.__ref === "compound_domain")
|
});
|
||||||
this.__domains.concat(source_domain.__domains);
|
|
||||||
else
|
|
||||||
this.add(source_domain);
|
|
||||||
};
|
};
|
||||||
openerp.base.CompoundDomain.prototype.add = function(domain) {
|
openerp.base.CompoundDomain.prototype.add = function(domain) {
|
||||||
this.__domains.push(domain);
|
if (domain.__ref === "compound_domain")
|
||||||
|
this.__domains = this.__domains.concat(domain.__domains);
|
||||||
|
else
|
||||||
|
this.__domains.push(domain);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
||||||
this.touched = false;
|
this.touched = false;
|
||||||
this.flags = this.view_manager.flags || {};
|
this.flags = this.view_manager.flags || {};
|
||||||
this.registry = openerp.base.form.widgets;
|
this.registry = openerp.base.form.widgets;
|
||||||
|
this.has_been_loaded = $.Deferred();
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
//this.log('Starting FormView '+this.model+this.view_id)
|
//this.log('Starting FormView '+this.model+this.view_id)
|
||||||
|
@ -47,7 +48,6 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
||||||
on_loaded: function(data) {
|
on_loaded: function(data) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.fields_view = data.fields_view;
|
this.fields_view = data.fields_view;
|
||||||
|
|
||||||
var frame = new (this.registry.get_object('frame'))(this, this.fields_view.arch);
|
var frame = new (this.registry.get_object('frame'))(this, this.fields_view.arch);
|
||||||
|
|
||||||
this.$element.html(QWeb.render(this.template, { 'frame': frame, 'view': this }));
|
this.$element.html(QWeb.render(this.template, { 'frame': frame, 'view': this }));
|
||||||
|
@ -65,6 +65,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
||||||
this.$element.find('#' + this.element_id + '_header button.oe_form_button_new').click(this.on_button_new);
|
this.$element.find('#' + this.element_id + '_header button.oe_form_button_new').click(this.on_button_new);
|
||||||
|
|
||||||
this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
|
this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
|
||||||
|
this.has_been_loaded.resolve();
|
||||||
},
|
},
|
||||||
do_show: function () {
|
do_show: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -222,8 +223,10 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
||||||
},
|
},
|
||||||
on_button_new: function() {
|
on_button_new: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.dataset.default_get(_.keys(this.fields), function(result) {
|
$.when(this.has_been_loaded).then(function() {
|
||||||
self.on_record_loaded(result.result);
|
self.dataset.default_get(_.keys(self.fields_view.fields), function(result) {
|
||||||
|
self.on_record_loaded(result.result);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -1183,11 +1186,11 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
self._change_int_ext_value(data.result);
|
self._change_int_ext_value(data.result);
|
||||||
}, function(a, b) {
|
}, function(a, b) {
|
||||||
self._change_int_value(null);
|
self._change_int_value(null);
|
||||||
self._search_create_popup("form");
|
self._search_create_popup("form", undefined, {"default_name": name});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// all search/create popup handling
|
// all search/create popup handling
|
||||||
_search_create_popup: function(view, ids) {
|
_search_create_popup: function(view, ids, context) {
|
||||||
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
|
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
|
||||||
var self = this;
|
var self = this;
|
||||||
var pop = new openerp.base.form.SelectCreatePopup(null, self.view.session);
|
var pop = new openerp.base.form.SelectCreatePopup(null, self.view.session);
|
||||||
|
@ -1195,7 +1198,8 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
initial_ids: ids ? _.map(ids, function(x) {return x[0]}) : undefined,
|
initial_ids: ids ? _.map(ids, function(x) {return x[0]}) : undefined,
|
||||||
initial_view: view,
|
initial_view: view,
|
||||||
disable_multiple_selection: true
|
disable_multiple_selection: true
|
||||||
});
|
}, self.view.domain || [],
|
||||||
|
new openerp.base.CompoundContext(build_relation_context(self)).add(context || {}));
|
||||||
pop.on_select_elements.add(function(element_ids) {
|
pop.on_select_elements.add(function(element_ids) {
|
||||||
dataset.call("name_get", [element_ids[0]], function(data) {
|
dataset.call("name_get", [element_ids[0]], function(data) {
|
||||||
self._change_int_ext_value(data.result[0]);
|
self._change_int_ext_value(data.result[0]);
|
||||||
|
@ -1431,7 +1435,8 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
this._super();
|
this._super();
|
||||||
this.dataset = new openerp.base.DataSetSearch(this.session, this.model);
|
this.dataset = new openerp.base.DataSetSearch(this.session, this.model,
|
||||||
|
this.context, this.domain);
|
||||||
if ((this.options.initial_view || "search") == "search") {
|
if ((this.options.initial_view || "search") == "search") {
|
||||||
this.setup_search_view();
|
this.setup_search_view();
|
||||||
} else { // "form"
|
} else { // "form"
|
||||||
|
@ -1450,8 +1455,8 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
|
||||||
});
|
});
|
||||||
this.searchview.on_search.add(function(domains, contexts, groupbys) {
|
this.searchview.on_search.add(function(domains, contexts, groupbys) {
|
||||||
if (self.initial_ids) {
|
if (self.initial_ids) {
|
||||||
self.view_list.do_search.call(self, [[["id", "in",
|
self.view_list.do_search.call(self,[[["id", "in", self.initial_ids]]],
|
||||||
self.initial_ids]]], contexts, groupbys);
|
contexts, groupbys);
|
||||||
self.initial_ids = undefined;
|
self.initial_ids = undefined;
|
||||||
} else {
|
} else {
|
||||||
self.view_list.do_search.call(self, domains, contexts, groupbys);
|
self.view_list.do_search.call(self, domains, contexts, groupbys);
|
||||||
|
|
|
@ -173,7 +173,7 @@ class CompoundDomain:
|
||||||
|
|
||||||
if isinstance(domain, list):
|
if isinstance(domain, list):
|
||||||
final_domain.extend(domain)
|
final_domain.extend(domain)
|
||||||
break
|
continue
|
||||||
|
|
||||||
ctx = dict(context or {})
|
ctx = dict(context or {})
|
||||||
ctx['context'] = ctx
|
ctx['context'] = ctx
|
||||||
|
@ -201,7 +201,7 @@ class CompoundContext:
|
||||||
|
|
||||||
if isinstance(context_to_eval, dict):
|
if isinstance(context_to_eval, dict):
|
||||||
final_context.update(context_to_eval)
|
final_context.update(context_to_eval)
|
||||||
break
|
continue
|
||||||
|
|
||||||
ctx.update(final_context)
|
ctx.update(final_context)
|
||||||
ctx["context"] = ctx
|
ctx["context"] = ctx
|
||||||
|
|
Loading…
Reference in New Issue