1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"use strict";
(function(){
var instance = openerp;
var QWeb = instance.web.qweb, _t = instance.web._t;
instance.web_readonly_bypass = {
/**
* ignore readonly: place options['readonly_fields'] into the data
* if nothing is specified into the context
*
* create mode: remove read-only keys having a 'false' value
*
* @param {Object} data field values to possibly be updated
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields to merge into the data object
* @param boolean mode: True case of create, false case of write
* @param {Object} context->readonly_by_pass
*/
ignore_readonly: function(data, options, mode, context){
var readonly_by_pass_fields = this.retrieve_readonly_by_pass_fields(
options, context);
if(mode){
$.each( readonly_by_pass_fields, function( key, value ) {
if(value==false){
delete(readonly_by_pass_fields[key]);
}
});
}
data = $.extend(data,readonly_by_pass_fields);
},
/**
* retrieve_readonly_by_pass_fields: retrieve readonly fields to save
* according context.
*
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: all values from readonly fields
* @param {Object} context->readonly_by_pass: Can be true if all
* all readonly fields should be saved or an array of field name to
* save ie: ['readonly_field_1', 'readonly_field_2']
* @returns {Object}: readonly key/value fields to save according context
*/
retrieve_readonly_by_pass_fields: function(options, context){
var readonly_by_pass_fields = {};
if (options && 'readonly_fields' in options &&
options['readonly_fields'] && context &&
'readonly_by_pass' in context && context['readonly_by_pass']){
if (_.isArray(context['readonly_by_pass'])){
$.each( options.readonly_fields, function( key, value ) {
if(_.contains(context['readonly_by_pass'], key)){
readonly_by_pass_fields[key] = value;
}
});
}else{
readonly_by_pass_fields = options.readonly_fields;
}
}
return readonly_by_pass_fields;
},
};
var readonly_bypass = instance.web_readonly_bypass;
instance.web.BufferedDataSet.include({
init : function() {
this._super.apply(this, arguments);
},
/**
* Creates Overriding
*
* @param {Object} data field values to set on the new record
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields that were updated by
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
* @returns super {$.Deferred}
*/
create : function(data, options) {
var self = this;
var context = instance.web.pyeval.eval('contexts',
self.context.__eval_context);
readonly_bypass.ignore_readonly(data, options, true, context);
return self._super(data,options);
},
/**
* Creates Overriding
*
* @param {Object} data field values to set on the new record
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields that were updated by
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
* @returns super {$.Deferred}
*/
write : function(id, data, options) {
var self = this;
var context = instance.web.pyeval.eval('contexts',
self.context.__eval_context);
readonly_bypass.ignore_readonly(data, options, false, context);
return self._super(id,data,options);
},
});
instance.web.DataSet.include({
/*
BufferedDataSet: case of 'add an item' into a form view
*/
init : function() {
this._super.apply(this, arguments);
},
/**
* Creates Overriding
*
* @param {Object} data field values to set on the new record
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields that were updated by
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
* @returns super {$.Deferred}
*/
create : function(data, options) {
var self = this;
readonly_bypass.ignore_readonly(data, options, true, self.context);
return self._super(data,options);
},
/**
* Creates Overriding
*
* @param {Object} data field values to set on the new record
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields that were updated by
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
* @returns super {$.Deferred}
*/
write : function(id, data, options) {
var self = this;
readonly_bypass.ignore_readonly(data, options, false, self.context);
return self._super(id,data,options);
},
});
})();