Merge lp:~openerp/openobject-client-web/trunk-bug-filters-niv into lp:openobject-client-web/trunk

Proposed by Nicolas Vanhoren (OpenERP)
Status: Superseded
Proposed branch: lp:~openerp/openobject-client-web/trunk-bug-filters-niv
Merge into: lp:openobject-client-web/trunk
Diff against target: 301 lines (+157/-116)
2 files modified
addons/openerp/controllers/search.py (+2/-1)
addons/openerp/static/javascript/search.js (+155/-115)
To merge this branch: bzr merge lp:~openerp/openobject-client-web/trunk-bug-filters-niv
Reviewer Review Type Date Requested Status
Xavier (Open ERP) (community) Needs Fixing
Review via email: mp+52688@code.launchpad.net

Description of the change

Fixed incorrect merge. Restored a previous patch that fixed problems with booleans (+ some other types) in custom filters.

To post a comment you must log in.
4608. By Nicolas Vanhoren (OpenERP)

Fixed incorrect merge in 4445 that overrided some files. Restored previous fix with custom filters.

------------- This line and the following will be ignored --------------

modified:
  addons/openerp/controllers/search.py
  addons/openerp/static/javascript/search.js
unknown:
  openerp/
  tmp.diff
  addons/web_livechat/
  addons/openerp/static/javascript/search..bak.js

Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

* Don't revert the parsing to simplejson, the data received is not necessarily in JS, because they can come from e.g. switch_SearchView which throws raw Python datastructures in there so filters are breaking when e.g. switching to Form view then back to List
* The else branch within the ilike/not ilike case is not correct, '%' is added by the server and adding it in JS breaks the custom filters when switching back from other views (or saving)
* Is it really necessary to revert the whole revision instead of just the fields handling? Do you know why they were originally removed?

review: Needs Fixing

Unmerged revisions

4608. By Nicolas Vanhoren (OpenERP)

Fixed incorrect merge in 4445 that overrided some files. Restored previous fix with custom filters.

------------- This line and the following will be ignored --------------

modified:
  addons/openerp/controllers/search.py
  addons/openerp/static/javascript/search.js
unknown:
  openerp/
  tmp.diff
  addons/web_livechat/
  addons/openerp/static/javascript/search..bak.js

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/openerp/controllers/search.py'
2--- addons/openerp/controllers/search.py 2011-03-04 07:12:57 +0000
3+++ addons/openerp/controllers/search.py 2011-03-09 14:34:04 +0000
4@@ -25,6 +25,7 @@
5 from error_page import _ep
6 from openobject import rpc
7 from openobject.tools import expose, ast
8+import simplejson
9
10 class Search(Form):
11
12@@ -342,7 +343,7 @@
13 if not custom_domains:
14 custom_domains = []
15 else:
16- custom_domains = ast.literal_eval(custom_domains)
17+ custom_domains = simplejson.loads(custom_domains)
18
19 # conversion of the pseudo domain from the javascript to a valid domain
20 ncustom_domain = []
21
22=== modified file 'addons/openerp/static/javascript/search.js'
23--- addons/openerp/static/javascript/search.js 2011-03-02 09:50:09 +0000
24+++ addons/openerp/static/javascript/search.js 2011-03-09 14:34:04 +0000
25@@ -297,121 +297,161 @@
26 }
27 });
28
29- if (!error) {
30- openobject.http.postJSON('/openerp/search/get', {
31- record: serializeJSON(Allrecords),
32- _terp_model: jQuery(idSelector('_terp_model')).val()
33- }).addCallback(function(obj){
34- var custom_domain = [];
35- if (obj.errors.length) {
36- for (er_field in obj.errors) {
37- for (er in obj.errors[er_field]) {
38- jQuery('tbody .filter_row_class', idSelector('filter_option_table')).each(function(){
39- if (jQuery(idSelector('filterlabel'), this).attr('value') == er) {
40- jQuery('input.qstring', this).addClass('errorfield').val(obj.errors[er_field][er]).click(function(){
41- jQuery(this).val('').removeClass('errorfield');
42- });
43- }
44- })
45- }
46- }
47- return;
48- }
49- var form_result = obj.frm;
50- var tbody_keys = jQuery.keys(form_result);
51-
52- if (form_result) {
53- // By property, we get incorrect ordering
54- for (var ind = 0; ind < tbody_keys.length; ind++) {
55- var All_domain = [];
56- var group = [];
57- var tbody_frm_ind = form_result[tbody_keys[ind]]; //tbody dictionary
58- var trs_keys = jQuery.unique(jQuery.keys(tbody_frm_ind)); //sort trs
59- for (var index = 0; index < trs_keys.length; index++) {
60- var return_record = tbody_frm_ind[trs_keys[index]];
61- var $curr_body = jQuery('tbody', idSelector('filter_option_table')).eq(tbody_keys[ind]);
62- var $row = jQuery('.filter_row_class', $curr_body).eq(trs_keys[index]);
63- var $next_row = [];
64- if ($row.next('tr.filter_row_class').find('input.qstring').val() != '') {
65- $next_row = jQuery($row.next());
66- }
67-
68- var type = return_record.type;
69- var temp_domain = [];
70- var grouping = $next_row.length != 0 ? jQuery('label.and_or', $next_row).text() : null;
71-
72- if (group.length == 0) {
73- var $new_grp = $curr_body.find('tr.filter_row_class:gt(' + trs_keys[index] + ')').find('td#filter_column:not(:has(label)) input.qstring[value]');
74- if ($new_grp.length) {
75- group.push('&')
76- }
77- }
78- if (grouping) {
79- temp_domain.push(grouping == 'AND' ? '&' : '|');
80- }
81-
82- var field = return_record['rec'];
83- var comparison = jQuery('select.expr', $row).val();
84- var value = return_record['rec_val'];
85-
86- switch (comparison) {
87- case 'ilike':
88- case 'not ilike':
89- if (isOrderable(type)) {
90- comparison = (comparison == 'ilike' ? '=' : '!=');
91- }
92- break;
93- case '<':
94- case '>':
95- if (!isOrderable(type)) {
96- comparison = '=';
97- }
98- break;
99- case 'in':
100- case 'not in':
101- if (typeof value == 'string') {
102- value = value.split(',');
103- }
104- else
105- if (type == 'many2many') {
106- /* very weird array-type construct
107- looks a bit like [[6, 0, [list of ids here]]]
108- */
109- value = value[value.length - 1][value[value.length - 1].length - 1]
110- }
111- else
112- if (type == 'one2many') {
113- value = value[0];
114- }
115- else {
116- value = value;
117- }
118- break;
119- }
120-
121- if (jQuery('label.and_or', $row).length > 0 || grouping) {
122- temp_domain.push(field, comparison, value);
123- group.push(temp_domain);
124- }
125- else {
126- group.push(field, comparison, value)
127- }
128-
129- if (!grouping) {
130- All_domain.push(group);
131- group = [];
132- }
133- }
134-
135- if (All_domain.length) {
136- custom_domain.push(All_domain);
137- }
138- }
139- }
140-
141- final_search_domain(serializeJSON(custom_domain), all_domains, group_by_ctx);
142- });
143- }
144+ openobject.http.postJSON('/openerp/search/get', {
145+ record: serializeJSON(Allrecords),
146+ _terp_model: jQuery('#_terp_model').val()
147+ }).addCallback(function(obj) {
148+ var custom_domain = [];
149+ if(obj.error) {
150+ jQuery('#filter_option_table tbody > .filter_row_class').each(function () {
151+ if(jQuery(this).find('#filterlabel').attr('value') == obj['error_field']) {
152+ jQuery(this).find('input.qstring').css('background', '#f66').val(obj.error);
153+ }
154+ else {
155+ error_display(obj.error)
156+ }
157+ });
158+ }
159+ var form_result = obj.frm;
160+ var tbody_keys = jQuery.keys(form_result);
161+
162+ if(form_result) {
163+ // By property, we get incorrect ordering
164+ for(var ind=0; ind<tbody_keys.length ;ind++){
165+ var All_domain = [];
166+ var group = [];
167+ var tbody_frm_ind = form_result[tbody_keys[ind]]; //tbody dictionary
168+ var trs_keys = jQuery.unique(jQuery.keys(tbody_frm_ind)); //sort trs
169+
170+ for(var index = 0; index<trs_keys.length ; index++) {
171+ var return_record = tbody_frm_ind[trs_keys[index]];
172+ var $curr_body = jQuery('#filter_option_table > tbody').eq(tbody_keys[ind]);
173+ var $row = $curr_body.find('> .filter_row_class').eq(trs_keys[index]);
174+ var $next_row = [];
175+
176+ if ($row.next('tr.filter_row_class').find('input.qstring').val() != ''){
177+ $next_row = jQuery($row.next());
178+ }
179+
180+ var type = return_record.type;
181+ var temp_domain = [];
182+ var grouping = $next_row.length != 0 ? $next_row.find('label.and_or').text(): null;
183+
184+ if (group.length==0) {
185+ var $new_grp = $curr_body.find('tr.filter_row_class:gt('+trs_keys[index]+')')
186+ .find('td#filter_column:not(:has(label)) input.qstring[value]');
187+ if ($new_grp.length){
188+ group.push('&')
189+ }
190+ }
191+ if(grouping) {
192+ temp_domain.push(grouping == 'AND' ? '&' : '|');
193+ }
194+
195+ var field = return_record['rec'];
196+ var comparison = $row.find('select.expr').val();
197+ var value = return_record['rec_val'];
198+
199+ // if there is multiple values we must split them before conversion
200+ isMultipleValues = comparison == 'in' || comparison == 'not in';
201+ var values;
202+ if(isMultipleValues) {
203+ values = value.split(',');
204+ } else {
205+ values = [value];
206+ }
207+ // converting values
208+ var newValues = [];
209+ jQuery.each(values, function(i,valuePart) {
210+ var tmp;
211+ switch (type) {
212+ case "string":
213+ case "many2one":
214+ case "many2many":
215+ case "one2many":
216+ case "date":
217+ case "reference":
218+ case "char":
219+ case "text":
220+ case "datetime":
221+ case "time":
222+ case "binary":
223+ case "selection":
224+ case "one2one":
225+ break;
226+ case "boolean":
227+ valuePart = valuePart.toLowerCase().trim();
228+ if(valuePart == "true" || valuePart == "yes" || valuePart == "1") {
229+ valuePart = true;
230+ } else if (valuePart == "false" || valuePart == "no" || valuePart == "0") {
231+ valuePart = false;
232+ } else {
233+ valuePart = Boolean(valuePart);
234+ }
235+ break;
236+ case "integer":
237+ case "integer_big":
238+ tmp = parseInt(valuePart,10);
239+ if(! isNaN(tmp)) {
240+ valuePart = tmp;
241+ }
242+ break;
243+ case "float":
244+ tmp = parseFloat(valuePart);
245+ if(! isNaN(tmp)) {
246+ valuePart = tmp;
247+ }
248+ break;
249+ default:
250+ //console.warning("unhandled type: " + type);
251+ }
252+ newValues.push(valuePart);
253+ });
254+ if(isMultipleValues) {
255+ value = newValues;
256+ } else {
257+ value = newValues[0];
258+ }
259+
260+ switch (comparison) {
261+ case 'ilike':
262+ case 'not ilike':
263+ if(isOrderable(type)) {
264+ comparison = (comparison == 'ilike' ? '=' : '!=');
265+ }
266+ else{
267+ value = '%' + value + '%';
268+ }
269+ break;
270+ case '<':
271+ case '>':
272+ if(!isOrderable(type)) {
273+ comparison = '=';
274+ }
275+ break;
276+ }
277+
278+ if ($row.find('label.and_or').length>0 || grouping){
279+ temp_domain.push(field, comparison, value);
280+ group.push(temp_domain);
281+ }
282+ else{
283+ group.push(field, comparison, value)
284+ }
285+
286+ if (!grouping) {
287+ All_domain.push(group);
288+ group = [];
289+ }
290+ }
291+
292+ if (All_domain.length) {
293+ custom_domain.push(All_domain);
294+ }
295+ }
296+ }
297+ final_search_domain(serializeJSON(custom_domain), all_domains, group_by_ctx);
298+ });
299 }
300
301 var group_by = [];