Merge lp:~openerp-commiter/openobject-client/trunk-ach-client-fixes into lp:openobject-client

Proposed by Anup(SerpentCS)
Status: Merged
Merge reported by: Naresh(OpenERP)
Merged at revision: not available
Proposed branch: lp:~openerp-commiter/openobject-client/trunk-ach-client-fixes
Merge into: lp:openobject-client
Diff against target: 279 lines (+108/-50)
7 files modified
bin/po/openerp-client.pot (+16/-0)
bin/tools/__init__.py (+81/-30)
bin/widget/model/field.py (+1/-2)
bin/widget/view/form.py (+1/-3)
bin/widget/view/form_gtk/parser.py (+6/-9)
bin/widget/view/list.py (+1/-2)
bin/widget/view/tree_gtk/parser.py (+2/-4)
To merge this branch: bzr merge lp:~openerp-commiter/openobject-client/trunk-ach-client-fixes
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Pending
tfr (Openerp) Pending
OpenERP sa GTK client R&D Pending
Review via email: mp+44435@code.launchpad.net

Description of the change

Hello,

    I have made the changes suggested by tfr(OpenERP) and have made a single stack instead of two.
    I have also made changes suggested by RGA(OpenERP) as followed,
      I have added a condition to check if the field exists in the model or not.
      I have added translation for the message.

Thanks.

To post a comment you must log in.
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

seems merged in latest trunk client

Thanks,

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/po/openerp-client.pot'
2--- bin/po/openerp-client.pot 2010-12-13 17:15:27 +0000
3+++ bin/po/openerp-client.pot 2010-12-22 08:46:10 +0000
4@@ -17,6 +17,22 @@
5 "Content-Type: text/plain; charset=UTF-8\n"
6 "Content-Transfer-Encoding: 8bit\n"
7
8+#: bin/tools/__init__.py:90
9+msgid "Wrong attrs Implementation!"
10+msgstr ""
11+
12+#: bin/tools/__init__.py:90
13+msgid "You have wrongly specified conditions in attrs %s"
14+msgstr ""
15+
16+#: bin/tools/__init__.py:105
17+msgid "Field not found"
18+msgstr ""
19+
20+#: bin/tools/__init__.py:105
21+msgid "The Field %s does not exist in the view"
22+msgstr ""
23+
24 #: bin/plugins/__init__.py:27
25 msgid "Print Workflow"
26 msgstr ""
27
28=== modified file 'bin/tools/__init__.py'
29--- bin/tools/__init__.py 2010-10-12 16:53:15 +0000
30+++ bin/tools/__init__.py 2010-12-22 08:46:10 +0000
31@@ -20,6 +20,7 @@
32 ##############################################################################
33
34 import datetime
35+import operator
36 import logging
37 import locale
38 import os
39@@ -80,38 +81,88 @@
40 return attrs
41
42 #FIXME use spaces
43-def calc_condition(self,model,con):
44- if model and (con[0] in model.mgroup.fields):
45- val = model[con[0]].get(model)
46- if con[1]=="=" or con[1]=="==":
47- if val==con[2]:
48- return True
49- elif con[1]=="!=" or con[1]=="<>":
50- if val!=con[2]:
51- return True
52- elif con[1]=="<":
53- if val<con[2]:
54- return True
55- elif con[1]==">":
56- if val>con[2]:
57- return True
58- elif con[1]=="<=":
59- if val<=con[2]:
60- return True
61- elif con[1]==">=":
62- if val>=con[2]:
63- return True
64- elif con[1].lower()=="in":
65- for cond in con[2]:
66- if val == cond:
67- return True
68- elif con[1].lower()=="not in":
69- for cond in con[2]:
70- if val == cond:
71- return False
72+def calc_condition(self, model, cond):
73+ cond_main = cond[:]
74+ try:
75+ return ConditionExpr(cond).eval(model)
76+ except:
77+ import common
78+ common.error(_('Wrong attrs Implementation!'),_('You have wrongly specified conditions in attrs %s') %(cond_main,))
79+
80+class ConditionExpr(object):
81+
82+ OPERAND_MAPPER = {'<>': '!=', '==': '='}
83+
84+ def __init__(self, condition):
85+ self.cond = condition
86+ self.check_condition(self.cond)
87+
88+ def check_condition(self, con):
89+ for element in cond:
90+ if self.is_leaf(element):
91+ left,opr,right = element
92+ if not model.get(left,False):
93+ common.error(_('Field not found'),_('The Field %s does not exist in the view') %(left,))
94+
95+ ops = ['=','!=','<','>','<=','>=','in','not in','<>','==']
96+
97+ def is_leaf(self,cond): # Method to check the Operands
98+ if (len(cond)==3 and cond[1] in ops) or isinstance(cond,bool):
99 return True
100- return False
101+ else:
102+ return False
103+
104+ def eval(self, model):
105+ if model:
106+ eval_stack = [] # Stack used for evaluation
107+
108+ def evaluate(cond): # Method to evaluate the conditions
109+ if isinstance(cond,bool):
110+ return cond
111+ left, oper, right = cond
112+ oper = self.OPERAND_MAPPER.get(oper.lower(), oper)
113+ if oper == '=':
114+ res = operator.eq(model[left].get(model),right)
115+ elif oper == '!=':
116+ res = operator.ne(model[left].get(model),right)
117+ elif oper == '<':
118+ res = operator.lt(model[left].get(model),right)
119+ elif oper == '>':
120+ res = operator.gt(model[left].get(model),right)
121+ elif oper == '<=':
122+ res = operator.le(model[left].get(model),right)
123+ elif oper == '>=':
124+ res = operator.ge(model[left].get(model),right)
125+ elif oper == 'in':
126+ res = operator.contains(right, model[left].get(model))
127+ elif oper == 'not in':
128+ res = operator.contains(right, model[left].get(model))
129+ res = operator.not_(res)
130+ return res
131
132+ eval_stack = self.cond[:]
133+ eval_stack.reverse()
134+
135+ while len(eval_stack) > 1:
136+ condition = eval_stack.pop()
137+ if self.is_leaf(condition): # If operand Push on Stack
138+ eval_stack.append(condition)
139+ eval_stack.append('&') #by default it's a and
140+ elif condition in ['|','&','!']: # If operator pop necessary operands from stack and evaluate and store the result back to stack
141+ if condition in ('|','&'):
142+ elem_1 = eval_stack.pop()
143+ elem_2 = eval_stack.pop()
144+ if condition=='|':
145+ result = any((evaluate(elem_1), evaluate(elem_2)))
146+ else:
147+ result = all((evaluate(elem_1), evaluate(elem_2)))
148+ elif condition == '!':
149+ elem_1 = eval_stack.pop()
150+ result = not evaluate(elem_1)
151+ eval_stack.append(result)
152+ res = all(evaluate(expr) for expr in eval_stack) # evaluate all the remaining elments if any
153+ return res
154+
155 def call_log(fun):
156 """Debug decorator
157 TODO: Add optionnal execution time
158
159=== modified file 'bin/widget/model/field.py'
160--- bin/widget/model/field.py 2010-12-06 11:11:51 +0000
161+++ bin/widget/model/field.py 2010-12-22 08:46:10 +0000
162@@ -143,8 +143,7 @@
163 attrs_changes[k][i]=cond
164 for k,v in attrs_changes.items():
165 result = True
166- for condition in v:
167- result = result and tools.calc_condition(self,model,condition)
168+ result = tools.calc_condition(self, model, v)
169 if result:
170 self.get_state_attrs(model)[k]=True
171
172
173=== modified file 'bin/widget/view/form.py'
174--- bin/widget/view/form.py 2010-12-03 15:04:54 +0000
175+++ bin/widget/view/form.py 2010-12-22 08:46:10 +0000
176@@ -353,9 +353,7 @@
177 cond=v[i][0],v[i][1],v[i][2][0]
178 attrs_changes[k][i]=cond
179 for k,v in attrs_changes.items():
180- result = True
181- for condition in v:
182- result = result and tools.calc_condition(self,model,condition)
183+ result = tools.calc_condition(self, model, v)
184 if result:
185 if k=='invisible':
186 obj.hide()
187
188=== modified file 'bin/widget/view/form_gtk/parser.py'
189--- bin/widget/view/form_gtk/parser.py 2010-11-10 12:47:34 +0000
190+++ bin/widget/view/form_gtk/parser.py 2010-12-22 08:46:10 +0000
191@@ -152,9 +152,7 @@
192 attrs_changes = eval(sa.get('attrs',"{}"),{'uid':rpc.session.uid})
193 for k,v in attrs_changes.items():
194 result = True
195- for condition in v:
196- result = result and tools.calc_condition(self,model,condition)
197-
198+ result = result and tools.calc_condition(self, model, v)
199 if k == 'invisible':
200 func = ['show', 'hide'][bool(result)]
201 getattr(self.widget, func)()
202@@ -214,7 +212,7 @@
203
204 def create_label(self, name, markup=False, align=1.0, wrap=False,
205 angle=None, width=None, fname=None, help=None, detail_tooltip=False):
206-
207+
208 label = gtk.Label(name)
209 eb = gtk.EventBox()
210 eb.set_events(gtk.gdk.BUTTON_PRESS_MASK)
211@@ -222,12 +220,11 @@
212 label.set_use_markup(True)
213 self.trans_box_label.append((eb, name, fname))
214 eb.add(label)
215-
216+
217 def size_allocate(label, allocation):
218 label.set_size_request( allocation.width - 2, -1 )
219 if fname is None and name and len(name) > 50:
220 label.connect( "size-allocate", size_allocate )
221-
222 uid = rpc.session.uid
223 tooltip = ''
224 if help:
225@@ -399,13 +396,13 @@
226 visval = eval(attrs['invisible'], {'context':self.screen.context})
227 if visval:
228 continue
229-
230+
231 if 'default_focus' in attrs and not self.default_focus_button:
232 attrs['focus_button'] = attrs['default_focus']
233 self.default_focus_button = True
234-
235+
236 button = Button(attrs)
237-
238+
239 states = [e for e in attrs.get('states','').split(',') if e]
240 saw_list.append(StateAwareWidget(button, states=states))
241 container.wid_add(button.widget, colspan=int(attrs.get('colspan', 1)))
242
243=== modified file 'bin/widget/view/list.py'
244--- bin/widget/view/list.py 2010-12-13 12:54:46 +0000
245+++ bin/widget/view/list.py 2010-12-22 08:46:10 +0000
246@@ -497,8 +497,7 @@
247 attrs_changes = eval(path.attrs.get('attrs',"{}"),{'uid':rpc.session.uid})
248 for k,v in attrs_changes.items():
249 result = True
250- for condition in v:
251- result = tools.calc_condition(self,model,condition)
252+ result = tools.calc_condition(self,model,v)
253 if result:
254 if k=='invisible':
255 return False
256
257=== modified file 'bin/widget/view/tree_gtk/parser.py'
258--- bin/widget/view/tree_gtk/parser.py 2010-11-29 20:37:53 +0000
259+++ bin/widget/view/tree_gtk/parser.py 2010-12-22 08:46:10 +0000
260@@ -266,8 +266,7 @@
261 attrs_changes = eval(self.attrs.get('attrs',"{}"),{'uid':rpc.session.uid})
262 for k,v in attrs_changes.items():
263 result = False
264- for condition in v:
265- result = tools.calc_condition(self,model,condition)
266+ result = tools.calc_condition(self,model,v)
267 model[self.field_name].get_state_attrs(model)[k] = result
268
269 def state_set(self, model, state='draft'):
270@@ -678,8 +677,7 @@
271 attrs_changes = eval(self.attrs.get('attrs',"{}"),{'uid':rpc.session.uid})
272 for k,v in attrs_changes.items():
273 result = False
274- for condition in v:
275- result = tools.calc_condition(self,model,condition)
276+ result = tools.calc_condition(self,model,v)
277 if result:
278 if k == 'invisible':
279 return 'hide'