[imp] added default name on false quick create in m2o

bzr revid: nicolas.vanhoren@openerp.com-20110617141945-wnnhkhf8wezwfyed
This commit is contained in:
niv-openerp 2011-06-17 16:19:45 +02:00
parent e975b4ac1e
commit 157273f15a
4 changed files with 41 additions and 34 deletions

View File

@ -455,9 +455,10 @@ class DataSet(openerpweb.Controller):
return {'result': r}
@openerpweb.jsonrequest
def default_get(self, req, model, fields, context={}):
def default_get(self, req, model, fields):
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}
class DataGroup(openerpweb.Controller):

View File

@ -231,10 +231,10 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
* @param {openerp.base.Session} session current OpenERP session
* @param {String} model the OpenERP model this dataset will manage
*/
init: function(session, model) {
init: function(session, model, context) {
this._super(session);
this.model = model;
this.context = {};
this.context = context || {};
this.index = 0;
this.count = 0;
},
@ -371,9 +371,9 @@ openerp.base.DataSetStatic = openerp.base.DataSet.extend({
});
openerp.base.DataSetSearch = openerp.base.DataSet.extend({
init: function(session, model) {
this._super(session, model);
this.domain = [];
init: function(session, model, context, domain) {
this._super(session, model, context);
this.domain = domain || [];
this._sort = [];
this.offset = 0;
// 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.__contexts = [];
if (source_context === undefined)
return;
else if (source_context.__ref === "compound_context")
this.__contexts.concat(source_context.__contexts);
else
this.add(source_context);
var self = this;
_.each(arguments, function(x) {
self.add(x);
});
};
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;
};
openerp.base.CompoundDomain = function(source_domain) {
openerp.base.CompoundDomain = function() {
this.__ref = "compound_domain";
this.__domains = [];
if (source_domain === undefined)
return;
else if (source_domain.__ref === "compound_domain")
this.__domains.concat(source_domain.__domains);
else
this.add(source_domain);
_.each(arguments, function(x) {
self.add(x);
});
};
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;
};

View File

@ -34,6 +34,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
this.touched = false;
this.flags = this.view_manager.flags || {};
this.registry = openerp.base.form.widgets;
this.has_been_loaded = $.Deferred();
},
start: function() {
//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) {
var self = this;
this.fields_view = data.fields_view;
var frame = new (this.registry.get_object('frame'))(this, this.fields_view.arch);
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.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
this.has_been_loaded.resolve();
},
do_show: function () {
var self = this;
@ -222,8 +223,10 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
},
on_button_new: function() {
var self = this;
this.dataset.default_get(_.keys(this.fields), function(result) {
self.on_record_loaded(result.result);
$.when(this.has_been_loaded).then(function() {
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);
}, function(a, b) {
self._change_int_value(null);
self._search_create_popup("form");
self._search_create_popup("form", undefined, {"default_name": name});
});
},
// 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 self = this;
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_view: view,
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) {
dataset.call("name_get", [element_ids[0]], function(data) {
self._change_int_ext_value(data.result[0]);
@ -1431,7 +1435,8 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
},
start: function() {
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") {
this.setup_search_view();
} else { // "form"
@ -1450,8 +1455,8 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
});
this.searchview.on_search.add(function(domains, contexts, groupbys) {
if (self.initial_ids) {
self.view_list.do_search.call(self, [[["id", "in",
self.initial_ids]]], contexts, groupbys);
self.view_list.do_search.call(self,[[["id", "in", self.initial_ids]]],
contexts, groupbys);
self.initial_ids = undefined;
} else {
self.view_list.do_search.call(self, domains, contexts, groupbys);

View File

@ -173,7 +173,7 @@ class CompoundDomain:
if isinstance(domain, list):
final_domain.extend(domain)
break
continue
ctx = dict(context or {})
ctx['context'] = ctx
@ -201,7 +201,7 @@ class CompoundContext:
if isinstance(context_to_eval, dict):
final_context.update(context_to_eval)
break
continue
ctx.update(final_context)
ctx["context"] = ctx