changeset 9d18e1c0befb in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=9d18e1c0befb
description:
Add local context to get context without session context
The issue8312 was to strict by its usage of Group._context as it misses
the
context_model, the parent context or the _datetime keys.
Instead we introduce a second type of context which provides the same
context
but without the session part.
issue8463
review255831002
diffstat:
src/model.js | 65 +++++++++++++++++++++++++++++++++++++---------------------
src/screen.js | 15 +++++++++---
src/tab.js | 2 +-
3 files changed, 53 insertions(+), 29 deletions(-)
diffs (172 lines):
diff -r ad0a8a3f98b7 -r 9d18e1c0befb src/model.js
--- a/src/model.js Mon Aug 12 12:55:48 2019 +0200
+++ b/src/model.js Sun Aug 18 18:51:54 2019 +0200
@@ -390,27 +390,40 @@
});
Object.defineProperty(array, 'context', {
get: function() {
- var context = jQuery.extend({}, this.model.session.context);
- if (this.parent) {
- var parent_context = this.parent.get_context();
- jQuery.extend(context, parent_context);
- if (this.child_name in this.parent.model.fields) {
- var field = this.parent.model.fields[this.child_name];
- jQuery.extend(context, field.get_context(
- this.parent, parent_context));
- }
- }
- jQuery.extend(context, this._context);
- if (this.parent_datetime_field) {
- context._datetime = this.parent.get_eval()
- [this.parent_datetime_field];
- }
- return context;
+ return this._get_context();
},
set: function(context) {
this._context = jQuery.extend({}, context);
}
});
+ Object.defineProperty(array, 'local_context', {
+ get: function() {
+ return this._get_context(true);
+ }
+ });
+ array._get_context = function(local) {
+ var context;
+ if (!local) {
+ context = jQuery.extend({}, this.model.session.context);
+ } else {
+ context = {};
+ }
+ if (this.parent) {
+ var parent_context = this.parent.get_context(local);
+ jQuery.extend(context, parent_context);
+ if (this.child_name in this.parent.model.fields) {
+ var field = this.parent.model.fields[this.child_name];
+ jQuery.extend(context, field.get_context(
+ this.parent, parent_context, local));
+ }
+ }
+ jQuery.extend(context, this._context);
+ if (this.parent_datetime_field) {
+ context._datetime = this.parent.get_eval()
+ [this.parent_datetime_field];
+ }
+ return context;
+ };
array.clean4inversion = function(domain) {
if (jQuery.isEmptyObject(domain)) {
return [];
@@ -813,8 +826,12 @@
}
return fields;
},
- get_context: function() {
- return this.group.context;
+ get_context: function(local) {
+ if (!local) {
+ return this.group.context;
+ } else {
+ return this.group.local_context;
+ }
},
field_get: function(name) {
return this.model.fields[name].get(this);
@@ -1415,12 +1432,12 @@
get_timestamp: function(record) {
return {};
},
- get_context: function(record, record_context) {
+ get_context: function(record, record_context, local) {
var context;
if (record_context) {
context = jQuery.extend({}, record_context);
} else {
- context = record.get_context();
+ context = record.get_context(local);
}
jQuery.extend(context,
record.expr_eval(this.description.context || {}));
@@ -1864,9 +1881,9 @@
Sao.field.Many2One._super.set_client.call(this, record, value,
force_change);
},
- get_context: function(record, record_context) {
+ get_context: function(record, record_context, local) {
var context = Sao.field.Many2One._super.get_context.call(
- this, record, record_context);
+ this, record, record_context, local);
if (this.description.datetime_field) {
context._datetime = record.get_eval()[
this.description.datetime_field];
@@ -2389,9 +2406,9 @@
return Sao.field.Reference._super.get_on_change_value.call(
this, record);
},
- get_context: function(record, record_context) {
+ get_context: function(record, record_context, local) {
var context = Sao.field.Reference._super.get_context.call(
- this, record, record_context);
+ this, record, record_context, local);
if (this.description.datetime_field) {
context._datetime = record.get_eval()[
this.description.datetime_field];
diff -r ad0a8a3f98b7 -r 9d18e1c0befb src/screen.js
--- a/src/screen.js Mon Aug 12 12:55:48 2019 +0200
+++ b/src/screen.js Sun Aug 18 18:51:54 2019 +0200
@@ -983,8 +983,8 @@
this.context_screen.display(true);
return jQuery.when();
}
- this.new_group(jQuery.extend({},
- this.group._context,
+ this.new_group(jQuery.extend(
+ this.local_context,
this.context_screen.get_on_change_value()));
}
@@ -1118,6 +1118,13 @@
}
return context;
},
+ get local_context() {
+ var context = this.group.local_context;
+ if (this.context_screen) {
+ context.context_model = this.context_screen.model_name;
+ }
+ return context;
+ },
set_group: function(group) {
var fields = {},
fields_views = {},
@@ -1321,7 +1328,7 @@
'model': this.model_name,
'id': this.get_id(),
'ids': [this.get_id()]
- }, jQuery.extend({}, this.group._context), false);
+ }, this.local_context, false);
} else {
if (!this.modified()) {
this.switch_view('form');
@@ -1907,7 +1914,7 @@
if (!jQuery.isEmptyObject(this.domain)) {
query_string.push(['domain', dumps(this.domain)]);
}
- var context = this.group._context; // Avoid rpc context
+ var context = this.local_context; // Avoid rpc context
if (!jQuery.isEmptyObject(context)) {
query_string.push(['context', dumps(context)]);
}
diff -r ad0a8a3f98b7 -r 9d18e1c0befb src/tab.js
--- a/src/tab.js Mon Aug 12 12:55:48 2019 +0200
+++ b/src/tab.js Sun Aug 18 18:51:54 2019 +0200
@@ -648,7 +648,7 @@
ids: record_ids
};
Sao.Action.exec_action(exec_action, data,
- jQuery.extend({}, screen.group._context));
+ jQuery.extend({}, screen.local_context));
});
}.bind(this))
.appendTo(menu);