Merge lp:~jfb-tempo-consulting/unifield-web/US-1019-us15 into lp:unifield-web

Proposed by jftempo on 2019-10-30
Status: Merged
Merged at revision: 4977
Proposed branch: lp:~jfb-tempo-consulting/unifield-web/US-1019-us15
Merge into: lp:unifield-web
Diff against target: 209 lines (+57/-15)
3 files modified
addons/openerp/static/javascript/search.js (+17/-6)
addons/openerp/widgets/search.py (+39/-8)
addons/openerp/widgets/templates/search/filters_group.mako (+1/-1)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-web/US-1019-us15
Reviewer Review Type Date Requested Status
UniField Dev Team 2019-10-30 Pending
Review via email: mp+374916@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/openerp/static/javascript/search.js'
2--- addons/openerp/static/javascript/search.js 2018-10-24 14:22:10 +0000
3+++ addons/openerp/static/javascript/search.js 2019-10-30 13:23:30 +0000
4@@ -440,7 +440,7 @@
5 var check_domain = '[]';
6 var domains = {};
7 var search_context = {};
8- var all_boxes = [];
9+ var all_boxes = {};
10 var $filter_list = jQuery('#filter_list');
11 var domain = '[]';
12 if (jQuery('div.group-data').length) {
13@@ -571,17 +571,28 @@
14
15 forEach(selected_boxes, function(box){
16 if (box.id && box.checked && box.value != '[]') {
17- all_boxes = all_boxes.concat(box.value);
18+
19+ pdiv = box.closest('div[class^="filters-group"]');
20+ if (!(pdiv.id in all_boxes)) {
21+ all_boxes[pdiv.id] = []
22+ }
23+ all_boxes[pdiv.id].push(box.value.replace(/^\s*\[/, '').replace(/]\s*$/, ''));
24 }
25 });
26
27- var checked_button = all_boxes.toString();
28+ var new_boxes = [];
29+ for (var key in all_boxes) {
30+ length = all_boxes[key].length
31+ for (var i=1; i<length; i+=1) {
32+ all_boxes[key].unshift("'|'");
33+ }
34+ new_boxes = new_boxes.concat(all_boxes[key]);
35+ }
36+ var checked_button = new_boxes.toString();
37
38 if(checked_button.length) {
39- check_domain = checked_button.length > 0? checked_button.replace(/(],\[)/g, ', ') : '[]';
40- all_domains['check_domain'] = check_domain;
41+ all_domains['check_domain'] = checked_button.length > 0 ? '['+checked_button+']' : '[]';
42 }
43-
44 // compute filter_status based on current filter states
45 var fl_status = {};
46 jQuery('[filter_status]').each(function() {
47
48=== modified file 'addons/openerp/widgets/search.py'
49--- addons/openerp/widgets/search.py 2018-11-12 17:08:16 +0000
50+++ addons/openerp/widgets/search.py 2019-10-30 13:23:30 +0000
51@@ -37,9 +37,10 @@
52 from openobject.i18n.format import convert_date_format_in_domain
53
54
55-def get_search_default(attrs, screen_context=None, default_domain=[]):
56+def get_search_default(attrs, screen_context=None, default_domain=None, add_active=False):
57 screen_context = screen_context or {}
58-
59+ if default_domain is None:
60+ default_domain = []
61 if 'context' in attrs:
62 ctx = expr_eval(attrs.get('context', "{}"), {'self':attrs.get('name', False)})
63 group_by = ctx.get('group_by')
64@@ -63,6 +64,8 @@
65 # resolution of those, so either we have a truthy value and we
66 # return it, or we don't and we don't do anything
67 return search_default
68+ elif add_active and attrs['name'] == 'active' and 'active' not in '%s'%default_domain:
69+ return True
70
71 return False
72
73@@ -129,13 +132,14 @@
74 self.filter_id = 'filter_%s' % (random.randint(0,10000))
75 self.filter_name = attrs.get('name', attrs.get('string', '')).replace('/', '-')
76 self.filter_status = attrs.get('filter_status', {}).get(self.filter_name)
77+ self.expand_grp_id = False
78 filter_context = attrs.get('context')
79 screen_context = attrs.get('screen_context', {})
80
81 self.def_checked = False
82 self.groupcontext = []
83
84- default_search = get_search_default(attrs, screen_context, default_domain)
85+ default_search = get_search_default(attrs, screen_context, default_domain, add_active=True)
86
87 # context implemented only for group_by.
88 self.group_context = None
89@@ -147,9 +151,10 @@
90 self.group_context = map(lambda x: 'group_' + x, self.group_context)
91 else:
92 self.group_context = 'group_' + self.group_context
93-
94 if default_search:
95 self.def_checked = True
96+ if attrs.get('expand_grp_id'):
97+ self.expand_grp_id = attrs['expand_grp_id']
98 self.global_domain += (expr_eval(self.filter_domain, {'context':screen_context}))
99 if self.group_context:
100 self.groupcontext = self.group_context
101@@ -202,6 +207,7 @@
102
103 self.domain = copy.deepcopy(domain) or []
104 self.listof_domain = domain or []
105+ self.listof_ored_domain = {}
106 self.filter_domain = filter_domain or []
107 self.filter_status = {}
108 self.custom_filter_domain = []
109@@ -267,6 +273,11 @@
110 self.fields_list.sort(lambda x, y: cmp(x[1], y[1]))
111
112 self.frame = self.parse(model, dom, self.fields, values)
113+ for oreddom in self.listof_ored_domain:
114+ for el in range(1, len(self.listof_ored_domain[oreddom])):
115+ self.listof_ored_domain[oreddom].insert(0, '|')
116+ for oredfilter in self.listof_ored_domain[oreddom]:
117+ self.listof_domain += oredfilter
118 if self.frame:
119 self.frame = self.frame[0]
120
121@@ -296,7 +307,7 @@
122 self.flt_domain = str(self.filter_domain).replace("(", "[").replace(')', ']')
123 self.custom_filter_domain = self.filter_domain
124
125- def parse(self, model=None, root=None, fields=None, values={}):
126+ def parse(self, model=None, root=None, fields=None, values={}, parent_group=False):
127
128 views = []
129 search_model = model
130@@ -317,19 +328,23 @@
131 if 'nolabel' in attrs:
132 attrs['nolabel'] = False
133
134+ expand_grp_id = False
135 if node.localName in ('form', 'tree', 'search', 'group'):
136 if node.localName == 'group':
137 attrs['group_by_ctx'] = values.get('group_by_ctx')
138 attrs['expand'] = expr_eval(attrs.get('expand',False),{'context':self.context})
139+ expand_grp_id = 'expand_grp_%s' % (random.randint(0,10000))
140 Element = Group
141 else:
142 Element = Frame
143
144 views.append(Element(children=
145 self.parse(model=search_model, root=node,
146- fields=fields, values=values),
147+ fields=fields, values=values, parent_group=expand_grp_id),
148 **attrs))
149
150+ elif node.localName=='label':
151+ views.append(Label(**attrs))
152 elif node.localName=='newline':
153 views.append(NewLine(**attrs))
154
155@@ -346,12 +361,19 @@
156 if values and values.get('filter_status'):
157 attrs['filter_status'] = values['filter_status']
158
159+ if parent_group:
160+ attrs['expand_grp_id'] = parent_group
161 v = Filter(**attrs)
162 if v.groupcontext and v.groupcontext not in self.groupby:
163 self.groupby.append(v.groupcontext)
164- self.listof_domain.extend(i for i in v.global_domain if not i in self.listof_domain)
165+ if v.global_domain and v.expand_grp_id:
166+ self.listof_ored_domain.setdefault(v.expand_grp_id, []).append([i for i in v.global_domain])
167+ else:
168+ self.listof_domain.extend(i for i in v.global_domain if not i in self.listof_domain)
169 filters_run.append(v)
170
171+ elif node.localName == 'separator':
172+ parent_group = 'expand_grp_%s' % (random.randint(0,10000))
173 elif node.localName == 'field':
174 val = attrs.get('select', False) or fields[str(attrs['name'])].get('select', False) or self.view_type == 'search'
175 if val:
176@@ -494,6 +516,14 @@
177 attrs['is_search'] = True
178 super(FiltersGroup, self).__init__(**attrs)
179
180+class Label(form.Char):
181+ template = "/openerp/widgets/templates/search/label.mako"
182+ width = False
183+ name = 'label'
184+ def __init__(self, **attrs):
185+ super(Label, self).__init__(**attrs)
186+
187+
188 class Char(form.Char): pass
189 class DateTime(form.DateTime): pass
190 class Float(form.Float): pass
191@@ -538,5 +568,6 @@
192 'many2one': M2O_search,
193 'email' : Char,
194 'url' : Char,
195- 'separator': Separator
196+ 'separator': Separator,
197+ 'label': Label,
198 }
199
200=== modified file 'addons/openerp/widgets/templates/search/filters_group.mako'
201--- addons/openerp/widgets/templates/search/filters_group.mako 2010-10-15 11:10:50 +0000
202+++ addons/openerp/widgets/templates/search/filters_group.mako 2019-10-30 13:23:30 +0000
203@@ -1,3 +1,3 @@
204-<div class="filters-group">
205+<div class="filters-group" id="grp-filter-${expand_grp_id}">
206 ${display_member(frame)}
207 </div>
208
209=== added file 'addons/openerp/widgets/templates/search/label.mako'

Subscribers

People subscribed via source and target branches