Merge lp:~vauxoo/addons-vauxoo/jose_answer_survey into lp:addons-vauxoo/7.0
- jose_answer_survey
- Merge into 7.0
Status: | Superseded |
---|---|
Proposed branch: | lp:~vauxoo/addons-vauxoo/jose_answer_survey |
Merge into: | lp:addons-vauxoo/7.0 |
Diff against target: |
898 lines (+830/-0) 11 files modified
answer_survey/__init__.py (+2/-0) answer_survey/__openerp__.py (+57/-0) answer_survey/model/__init__.py (+1/-0) answer_survey/model/survey.py (+42/-0) answer_survey/security/groups_survey.xml (+10/-0) answer_survey/static/src/css/survey.css (+25/-0) answer_survey/view/answer_survey_menu.xml (+11/-0) answer_survey/wizard/__init__.py (+25/-0) answer_survey/wizard/survey_answer.xml (+16/-0) answer_survey/wizard/survey_selection.py (+475/-0) answer_survey/wizard/survey_send_invitation.py (+166/-0) |
To merge this branch: | bzr merge lp:~vauxoo/addons-vauxoo/jose_answer_survey |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nhomar - Vauxoo | Pending | ||
Review via email:
|
This proposal has been superseded by a proposal from 2014-06-06.
Commit message
Description of the change
Added new branch answer_surver
This brach inherits the features of module survy from main addons, and modify the themes for use the new vauxoo portal theme
To post a comment you must log in.
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'answer_survey' | |||
2 | === added file 'answer_survey/__init__.py' | |||
3 | --- answer_survey/__init__.py 1970-01-01 00:00:00 +0000 | |||
4 | +++ answer_survey/__init__.py 2013-09-27 19:15:29 +0000 | |||
5 | @@ -0,0 +1,2 @@ | |||
6 | 1 | import model | ||
7 | 2 | import wizard | ||
8 | 0 | 3 | ||
9 | === added file 'answer_survey/__openerp__.py' | |||
10 | --- answer_survey/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
11 | +++ answer_survey/__openerp__.py 2013-09-27 19:15:29 +0000 | |||
12 | @@ -0,0 +1,57 @@ | |||
13 | 1 | # -*- coding: utf-8 -*- | ||
14 | 2 | ############################################################################## | ||
15 | 3 | # | ||
16 | 4 | # OpenERP, Open Source Management Solution | ||
17 | 5 | # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). | ||
18 | 6 | # | ||
19 | 7 | # This program is free software: you can redistribute it and/or modify | ||
20 | 8 | # it under the terms of the GNU Affero General Public License as | ||
21 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
22 | 10 | # License, or (at your option) any later version. | ||
23 | 11 | # | ||
24 | 12 | # This program is distributed in the hope that it will be useful, | ||
25 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
26 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
27 | 15 | # GNU Affero General Public License for more details. | ||
28 | 16 | # | ||
29 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
30 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
31 | 19 | # | ||
32 | 20 | ############################################################################## | ||
33 | 21 | { | ||
34 | 22 | 'name' : 'Answer Survey', | ||
35 | 23 | 'version' : '0.1', | ||
36 | 24 | 'author' : 'Vauxoo', | ||
37 | 25 | 'category' : '', | ||
38 | 26 | 'description' : """ | ||
39 | 27 | |||
40 | 28 | """, | ||
41 | 29 | 'website': 'http://www.vauxoo.com', | ||
42 | 30 | 'images' : [], | ||
43 | 31 | 'depends' : [ | ||
44 | 32 | 'survey', | ||
45 | 33 | 'web_bootstrap3', | ||
46 | 34 | 'portal_crm_vauxoo', | ||
47 | 35 | 'web_fontawesome', | ||
48 | 36 | ], | ||
49 | 37 | 'data': [ | ||
50 | 38 | 'security/groups_survey.xml', | ||
51 | 39 | 'wizard/survey_answer.xml', | ||
52 | 40 | 'view/answer_survey_menu.xml', | ||
53 | 41 | ], | ||
54 | 42 | 'js': [ | ||
55 | 43 | ], | ||
56 | 44 | 'qweb' : [ | ||
57 | 45 | ], | ||
58 | 46 | 'css':[ | ||
59 | 47 | 'static/src/css/survey.css', | ||
60 | 48 | ], | ||
61 | 49 | 'demo': [ | ||
62 | 50 | ], | ||
63 | 51 | 'test': [ | ||
64 | 52 | ], | ||
65 | 53 | 'installable': True, | ||
66 | 54 | 'auto_install': False, | ||
67 | 55 | } | ||
68 | 56 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | ||
69 | 57 | |||
70 | 0 | 58 | ||
71 | === added directory 'answer_survey/data' | |||
72 | === added directory 'answer_survey/demo' | |||
73 | === added directory 'answer_survey/i18n' | |||
74 | === added directory 'answer_survey/model' | |||
75 | === added file 'answer_survey/model/__init__.py' | |||
76 | --- answer_survey/model/__init__.py 1970-01-01 00:00:00 +0000 | |||
77 | +++ answer_survey/model/__init__.py 2013-09-27 19:15:29 +0000 | |||
78 | @@ -0,0 +1,1 @@ | |||
79 | 1 | import survey | ||
80 | 0 | 2 | ||
81 | === added file 'answer_survey/model/survey.py' | |||
82 | --- answer_survey/model/survey.py 1970-01-01 00:00:00 +0000 | |||
83 | +++ answer_survey/model/survey.py 2013-09-27 19:15:29 +0000 | |||
84 | @@ -0,0 +1,42 @@ | |||
85 | 1 | # -*- encoding: utf-8 -*- | ||
86 | 2 | ############################################################################## | ||
87 | 3 | # | ||
88 | 4 | # OpenERP, Open Source Management Solution | ||
89 | 5 | # Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com> | ||
90 | 6 | # | ||
91 | 7 | # This program is free software: you can redistribute it and/or modify | ||
92 | 8 | # it under the terms of the GNU Affero General Public License as | ||
93 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
94 | 10 | # License, or (at your option) any later version. | ||
95 | 11 | # | ||
96 | 12 | # This program is distributed in the hope that it will be useful, | ||
97 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
98 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
99 | 15 | # GNU Affero General Public License for more details. | ||
100 | 16 | # | ||
101 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
102 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
103 | 19 | # | ||
104 | 20 | ############################################################################## | ||
105 | 21 | |||
106 | 22 | import copy | ||
107 | 23 | from datetime import datetime | ||
108 | 24 | from dateutil.relativedelta import relativedelta | ||
109 | 25 | from time import strftime | ||
110 | 26 | import os | ||
111 | 27 | |||
112 | 28 | from openerp import netsvc, tools | ||
113 | 29 | from openerp.osv import fields, osv | ||
114 | 30 | from openerp.tools.translate import _ | ||
115 | 31 | |||
116 | 32 | |||
117 | 33 | class survey(osv.Model): | ||
118 | 34 | _inherit = 'survey' | ||
119 | 35 | |||
120 | 36 | def fill_survey(self, cr, uid, ids, context=None): | ||
121 | 37 | res = super(survey,self).fill_survey(cr, uid, ids, context) | ||
122 | 38 | res.update( { | ||
123 | 39 | 'target': 'inline', | ||
124 | 40 | }) | ||
125 | 41 | return res | ||
126 | 42 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | ||
127 | 0 | 43 | ||
128 | === added directory 'answer_survey/report' | |||
129 | === added directory 'answer_survey/security' | |||
130 | === added file 'answer_survey/security/groups_survey.xml' | |||
131 | --- answer_survey/security/groups_survey.xml 1970-01-01 00:00:00 +0000 | |||
132 | +++ answer_survey/security/groups_survey.xml 2013-09-27 19:15:29 +0000 | |||
133 | @@ -0,0 +1,10 @@ | |||
134 | 1 | <?xml version='1.0' encoding='utf-8'?> | ||
135 | 2 | <openerp> | ||
136 | 3 | <data noupdate="1"> | ||
137 | 4 | |||
138 | 5 | <record id="only_answer_menu" model="res.groups"> | ||
139 | 6 | <field name="name">Answer Survey Menu</field> | ||
140 | 7 | </record> | ||
141 | 8 | |||
142 | 9 | </data> | ||
143 | 10 | </openerp> | ||
144 | 0 | 11 | ||
145 | === added directory 'answer_survey/static' | |||
146 | === added directory 'answer_survey/static/src' | |||
147 | === added directory 'answer_survey/static/src/css' | |||
148 | === added file 'answer_survey/static/src/css/survey.css' | |||
149 | --- answer_survey/static/src/css/survey.css 1970-01-01 00:00:00 +0000 | |||
150 | +++ answer_survey/static/src/css/survey.css 2013-09-27 19:15:29 +0000 | |||
151 | @@ -0,0 +1,25 @@ | |||
152 | 1 | .icon-3x { | ||
153 | 2 | padding:10px; | ||
154 | 3 | } | ||
155 | 4 | |||
156 | 5 | .btn.btn-large.btn-primary { | ||
157 | 6 | color:black; | ||
158 | 7 | height:28px; | ||
159 | 8 | width:140px; | ||
160 | 9 | position:relative; | ||
161 | 10 | } | ||
162 | 11 | .oe_e span{ | ||
163 | 12 | height:32px; | ||
164 | 13 | line-height:25px; | ||
165 | 14 | text-align:center; | ||
166 | 15 | left:60px; | ||
167 | 16 | position:absolute; | ||
168 | 17 | top:0; | ||
169 | 18 | font-size: 34px; | ||
170 | 19 | } | ||
171 | 20 | button.answer_exit.btn.btn-large.btn-primary { | ||
172 | 21 | color:black; | ||
173 | 22 | background-color:red; | ||
174 | 23 | width:10em; | ||
175 | 24 | height:28px; | ||
176 | 25 | } | ||
177 | 0 | 26 | ||
178 | === added directory 'answer_survey/static/src/js' | |||
179 | === added directory 'answer_survey/static/src/xml' | |||
180 | === added directory 'answer_survey/view' | |||
181 | === added file 'answer_survey/view/answer_survey_menu.xml' | |||
182 | --- answer_survey/view/answer_survey_menu.xml 1970-01-01 00:00:00 +0000 | |||
183 | +++ answer_survey/view/answer_survey_menu.xml 2013-09-27 19:15:29 +0000 | |||
184 | @@ -0,0 +1,11 @@ | |||
185 | 1 | <?xml version="1.0" ?> | ||
186 | 2 | <openerp> | ||
187 | 3 | <data> | ||
188 | 4 | |||
189 | 5 | <menuitem id="answer_survey_only_menu" | ||
190 | 6 | groups='answer_survey.only_answer_menu' | ||
191 | 7 | sequence='1' | ||
192 | 8 | name='Answer Your Survies' | ||
193 | 9 | action="survey.action_view_survey_name"/> | ||
194 | 10 | </data> | ||
195 | 11 | </openerp> | ||
196 | 0 | 12 | ||
197 | === added directory 'answer_survey/wizard' | |||
198 | === added file 'answer_survey/wizard/__init__.py' | |||
199 | --- answer_survey/wizard/__init__.py 1970-01-01 00:00:00 +0000 | |||
200 | +++ answer_survey/wizard/__init__.py 2013-09-27 19:15:29 +0000 | |||
201 | @@ -0,0 +1,25 @@ | |||
202 | 1 | # -*- encoding: utf-8 -*- | ||
203 | 2 | ############################################################################## | ||
204 | 3 | # | ||
205 | 4 | # OpenERP, Open Source Management Solution | ||
206 | 5 | # Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com> | ||
207 | 6 | # | ||
208 | 7 | # This program is free software: you can redistribute it and/or modify | ||
209 | 8 | # it under the terms of the GNU Affero General Public License as | ||
210 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
211 | 10 | # License, or (at your option) any later version. | ||
212 | 11 | # | ||
213 | 12 | # This program is distributed in the hope that it will be useful, | ||
214 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
215 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
216 | 15 | # GNU Affero General Public License for more details. | ||
217 | 16 | # | ||
218 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
219 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
220 | 19 | # | ||
221 | 20 | ############################################################################## | ||
222 | 21 | |||
223 | 22 | import survey_send_invitation | ||
224 | 23 | import survey_selection | ||
225 | 24 | |||
226 | 25 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | ||
227 | 0 | 26 | ||
228 | === added file 'answer_survey/wizard/survey_answer.xml' | |||
229 | --- answer_survey/wizard/survey_answer.xml 1970-01-01 00:00:00 +0000 | |||
230 | +++ answer_survey/wizard/survey_answer.xml 2013-09-27 19:15:29 +0000 | |||
231 | @@ -0,0 +1,16 @@ | |||
232 | 1 | <?xml version="1.0" ?> | ||
233 | 2 | <openerp> | ||
234 | 3 | <data> | ||
235 | 4 | |||
236 | 5 | <record id="survey.action_view_survey_name" | ||
237 | 6 | model="ir.actions.act_window"> | ||
238 | 7 | <field name="name">Give Survey Answer</field> | ||
239 | 8 | <field name="type">ir.actions.act_window</field> | ||
240 | 9 | <field name="res_model">survey.name.wiz</field> | ||
241 | 10 | <field name="view_type">form</field> | ||
242 | 11 | <field name="view_mode">form</field> | ||
243 | 12 | <field name="target">inline</field> | ||
244 | 13 | </record> | ||
245 | 14 | |||
246 | 15 | </data> | ||
247 | 16 | </openerp> | ||
248 | 0 | 17 | ||
249 | === added file 'answer_survey/wizard/survey_selection.py' | |||
250 | --- answer_survey/wizard/survey_selection.py 1970-01-01 00:00:00 +0000 | |||
251 | +++ answer_survey/wizard/survey_selection.py 2013-09-27 19:15:29 +0000 | |||
252 | @@ -0,0 +1,475 @@ | |||
253 | 1 | # -*- encoding: utf-8 -*- | ||
254 | 2 | ############################################################################## | ||
255 | 3 | # | ||
256 | 4 | # OpenERP, Open Source Management Solution | ||
257 | 5 | # Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com> | ||
258 | 6 | # | ||
259 | 7 | # This program is free software: you can redistribute it and/or modify | ||
260 | 8 | # it under the terms of the GNU Affero General Public License as | ||
261 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
262 | 10 | # License, or (at your option) any later version. | ||
263 | 11 | # | ||
264 | 12 | # This program is distributed in the hope that it will be useful, | ||
265 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
266 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
267 | 15 | # GNU Affero General Public License for more details. | ||
268 | 16 | # | ||
269 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
270 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
271 | 19 | # | ||
272 | 20 | ############################################################################## | ||
273 | 21 | |||
274 | 22 | from lxml import etree | ||
275 | 23 | import os | ||
276 | 24 | from openerp import addons, netsvc, tools | ||
277 | 25 | from openerp.tools import to_xml | ||
278 | 26 | from openerp.tools.safe_eval import safe_eval | ||
279 | 27 | from openerp.osv import fields, osv | ||
280 | 28 | from openerp.tools.translate import _ | ||
281 | 29 | |||
282 | 30 | class survey_name_wiz(osv.TransientModel): | ||
283 | 31 | _inherit = 'survey.name.wiz' | ||
284 | 32 | |||
285 | 33 | def action_next(self, cr, uid, ids, context=None): | ||
286 | 34 | res = super(survey_name_wiz, self).action_next(cr, uid, ids, context) | ||
287 | 35 | |||
288 | 36 | res.update( { | ||
289 | 37 | 'target': 'inline', | ||
290 | 38 | }) | ||
291 | 39 | return res | ||
292 | 40 | |||
293 | 41 | class survey_question_wiz(osv.TransientModel): | ||
294 | 42 | _inherit = 'survey.question.wiz' | ||
295 | 43 | |||
296 | 44 | def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): | ||
297 | 45 | """ | ||
298 | 46 | Fields View Get method :- generate the new view and display the survey pages of selected survey. | ||
299 | 47 | """ | ||
300 | 48 | |||
301 | 49 | if context is None: | ||
302 | 50 | context = {} | ||
303 | 51 | result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, \ | ||
304 | 52 | view_type, {}, toolbar,submenu) | ||
305 | 53 | |||
306 | 54 | surv_name_wiz = self.pool.get('survey.name.wiz') | ||
307 | 55 | survey_obj = self.pool.get('survey') | ||
308 | 56 | page_obj = self.pool.get('survey.page') | ||
309 | 57 | que_obj = self.pool.get('survey.question') | ||
310 | 58 | ans_obj = self.pool.get('survey.answer') | ||
311 | 59 | sur_response_obj = self.pool.get('survey.response') | ||
312 | 60 | que_col_head = self.pool.get('survey.question.column.heading') | ||
313 | 61 | user_obj = self.pool.get('res.users') | ||
314 | 62 | mail_message = self.pool.get('mail.message') | ||
315 | 63 | |||
316 | 64 | if view_type in ['form']: | ||
317 | 65 | wiz_id = 0 | ||
318 | 66 | sur_name_rec = None | ||
319 | 67 | if 'sur_name_id' in context: | ||
320 | 68 | sur_name_rec = surv_name_wiz.browse(cr, uid, context['sur_name_id'], context=context) | ||
321 | 69 | elif 'survey_id' in context: | ||
322 | 70 | res_data = { | ||
323 | 71 | 'survey_id': context.get('survey_id', False), | ||
324 | 72 | 'page_no': -1, | ||
325 | 73 | 'page': 'next', | ||
326 | 74 | 'transfer': 1, | ||
327 | 75 | 'response': 0 | ||
328 | 76 | } | ||
329 | 77 | wiz_id = surv_name_wiz.create(cr, uid, res_data) | ||
330 | 78 | sur_name_rec = surv_name_wiz.browse(cr, uid, wiz_id, context=context) | ||
331 | 79 | context.update({'sur_name_id' :wiz_id}) | ||
332 | 80 | |||
333 | 81 | if context.has_key('active_id'): | ||
334 | 82 | context.pop('active_id') | ||
335 | 83 | |||
336 | 84 | survey_id = context.get('survey_id', False) | ||
337 | 85 | if not survey_id: | ||
338 | 86 | # Try one more time to find it | ||
339 | 87 | if sur_name_rec and sur_name_rec.survey_id: | ||
340 | 88 | survey_id = sur_name_rec.survey_id.id | ||
341 | 89 | else: | ||
342 | 90 | # raise osv.except_osv(_('Error!'), _("Cannot locate survey for the question wizard!")) | ||
343 | 91 | # If this function is called without a survey_id in | ||
344 | 92 | # its context, it makes no sense to return any view. | ||
345 | 93 | # Just return the default, empty view for this object, | ||
346 | 94 | # in order to please random calls to this fn(). | ||
347 | 95 | return super(survey_question_wiz, self).\ | ||
348 | 96 | fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, | ||
349 | 97 | toolbar=toolbar, submenu=submenu) | ||
350 | 98 | sur_rec = survey_obj.browse(cr, uid, survey_id, context=context) | ||
351 | 99 | p_id = map(lambda x:x.id, sur_rec.page_ids) | ||
352 | 100 | total_pages = len(p_id) | ||
353 | 101 | pre_button = False | ||
354 | 102 | readonly = 0 | ||
355 | 103 | |||
356 | 104 | if context.get('response_id', False) \ | ||
357 | 105 | and int(context['response_id'][0]) > 0: | ||
358 | 106 | readonly = 1 | ||
359 | 107 | |||
360 | 108 | if not sur_name_rec.page_no + 1 : | ||
361 | 109 | surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'store_ans':{}}) | ||
362 | 110 | |||
363 | 111 | sur_name_read = surv_name_wiz.browse(cr, uid, context['sur_name_id'], context=context) | ||
364 | 112 | page_number = int(sur_name_rec.page_no) | ||
365 | 113 | if sur_name_read.transfer or not sur_name_rec.page_no + 1: | ||
366 | 114 | surv_name_wiz.write(cr, uid, [context['sur_name_id']], {'transfer':False}) | ||
367 | 115 | flag = False | ||
368 | 116 | fields = {} | ||
369 | 117 | if sur_name_read.page == "next" or sur_name_rec.page_no == -1: | ||
370 | 118 | if total_pages > sur_name_rec.page_no + 1: | ||
371 | 119 | if ((context.has_key('active') and not context.get('active', False)) \ | ||
372 | 120 | or not context.has_key('active')) and not sur_name_rec.page_no + 1: | ||
373 | 121 | if sur_rec.state != "open" : | ||
374 | 122 | raise osv.except_osv(_('Warning!'),_("You cannot answer because the survey is not open.")) | ||
375 | 123 | cr.execute('select count(id) from survey_history where user_id=%s\ | ||
376 | 124 | and survey_id=%s', (uid,survey_id)) | ||
377 | 125 | res = cr.fetchone()[0] | ||
378 | 126 | user_limit = survey_obj.browse(cr, uid, survey_id) | ||
379 | 127 | user_limit = user_limit.response_user | ||
380 | 128 | if user_limit and res >= user_limit: | ||
381 | 129 | raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (user_limit)) | ||
382 | 130 | |||
383 | 131 | if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey and not sur_name_rec.page_no + 1: | ||
384 | 132 | survey_obj.write(cr, uid, survey_id, {'state':'close', 'date_close':strftime("%Y-%m-%d %H:%M:%S")}) | ||
385 | 133 | |||
386 | 134 | p_id = p_id[sur_name_rec.page_no + 1] | ||
387 | 135 | surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'page_no' : sur_name_rec.page_no + 1}) | ||
388 | 136 | flag = True | ||
389 | 137 | page_number += 1 | ||
390 | 138 | if sur_name_rec.page_no > - 1: | ||
391 | 139 | pre_button = True | ||
392 | 140 | else: | ||
393 | 141 | flag = True | ||
394 | 142 | else: | ||
395 | 143 | if sur_name_rec.page_no != 0: | ||
396 | 144 | p_id = p_id[sur_name_rec.page_no - 1] | ||
397 | 145 | surv_name_wiz.write(cr, uid, [context['sur_name_id'],],\ | ||
398 | 146 | {'page_no' : sur_name_rec.page_no - 1}) | ||
399 | 147 | flag = True | ||
400 | 148 | page_number -= 1 | ||
401 | 149 | |||
402 | 150 | if sur_name_rec.page_no > 1: | ||
403 | 151 | pre_button = True | ||
404 | 152 | if flag: | ||
405 | 153 | pag_rec = page_obj.browse(cr, uid, p_id, context=context) | ||
406 | 154 | note = False | ||
407 | 155 | question_ids = [] | ||
408 | 156 | if pag_rec: | ||
409 | 157 | title = pag_rec.title | ||
410 | 158 | note = pag_rec.note | ||
411 | 159 | question_ids = pag_rec.question_ids | ||
412 | 160 | else: | ||
413 | 161 | title = sur_rec.title | ||
414 | 162 | form = etree.Element('form', {'class':'bs3 bs3-form-bg bs3-footer','string': tools.ustr(title)}) | ||
415 | 163 | section = etree.SubElement(form, 'section', {'class': 'bgvauxoo'}) | ||
416 | 164 | xml_form = etree.SubElement(section, 'div', {'class': 'container'}) | ||
417 | 165 | if context.has_key('active') and context.get('active',False) and context.has_key('edit'): | ||
418 | 166 | context.update({'page_id' : tools.ustr(p_id),'page_number' : sur_name_rec.page_no , 'transfer' : sur_name_read.transfer}) | ||
419 | 167 | xml_group3 = etree.SubElement(xml_form, 'group', {'col': '4', 'colspan': '4'}) | ||
420 | 168 | etree.SubElement(xml_group3, 'button', {'string' :'Add Page','icon': "gtk-new", 'type' :'object','name':"action_new_page", 'context' : tools.ustr(context)}) | ||
421 | 169 | etree.SubElement(xml_group3, 'button', {'string' :'Edit Page','icon': "gtk-edit", 'type' :'object','name':"action_edit_page", 'context' : tools.ustr(context)}) | ||
422 | 170 | etree.SubElement(xml_group3, 'button', {'string' :'Delete Page','icon': "gtk-delete", 'type' :'object','name':"action_delete_page", 'context' : tools.ustr(context)}) | ||
423 | 171 | etree.SubElement(xml_group3, 'button', {'string' :'Add Question','icon': "gtk-new", 'type' :'object','name':"action_new_question", 'context' : tools.ustr(context)}) | ||
424 | 172 | |||
425 | 173 | # FP Note | ||
426 | 174 | xml_group = xml_form | ||
427 | 175 | |||
428 | 176 | if context.has_key('response_id') and context.get('response_id', False) \ | ||
429 | 177 | and int(context.get('response_id',0)[0]) > 0: | ||
430 | 178 | # TODO: l10n, cleanup this code to make it readable. Or template? | ||
431 | 179 | xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'}) | ||
432 | 180 | record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) | ||
433 | 181 | etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of :- ' + record.user_id.name + ', Date :- ' + record.date_create.split('.')[0] )), 'align':"0.0"}) | ||
434 | 182 | etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(" Answer :- " + str(context.get('response_no',0) + 1) +"/" + str(len(context.get('response_id',0))) )), 'align':"0.0"}) | ||
435 | 183 | if context.get('response_no',0) > 0: | ||
436 | 184 | etree.SubElement(xml_group, 'button', {'colspan':"1",'icon':"gtk-go-back",'name':"action_forward_previous",'string': tools.ustr("Previous Answer"),'type':"object"}) | ||
437 | 185 | if context.get('response_no',0) + 1 < len(context.get('response_id',0)): | ||
438 | 186 | etree.SubElement(xml_group, 'button', {'colspan':"1",'icon': "gtk-go-forward", 'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context)}) | ||
439 | 187 | |||
440 | 188 | if wiz_id: | ||
441 | 189 | fields["wizardid_" + str(wiz_id)] = {'type':'char', 'size' : 255, 'string':"", 'views':{}} | ||
442 | 190 | etree.SubElement(xml_form, 'field', {'widget':'FieldCharBS3','invisible':'1','name': "wizardid_" + str(wiz_id),'default':str(lambda *a: 0),'modifiers':'{"invisible":true}'}) | ||
443 | 191 | |||
444 | 192 | if note: | ||
445 | 193 | xml_group_note = etree.SubElement(xml_form, 'group', {'col': '1','colspan': '4'}) | ||
446 | 194 | for que_test in note.split('\n'): | ||
447 | 195 | etree.SubElement(xml_group_note, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) | ||
448 | 196 | que_ids = question_ids | ||
449 | 197 | qu_no = 0 | ||
450 | 198 | |||
451 | 199 | for que in que_ids: | ||
452 | 200 | qu_no += 1 | ||
453 | 201 | que_rec = que_obj.browse(cr, uid, que.id, context=context) | ||
454 | 202 | descriptive_text = "" | ||
455 | 203 | separator_string = tools.ustr(qu_no) + "." + tools.ustr(que_rec.question) | ||
456 | 204 | if ((context.has_key('active') and not context.get('active',False)) or not context.has_key('active')) and que_rec.is_require_answer: | ||
457 | 205 | star = '*' | ||
458 | 206 | else: | ||
459 | 207 | star = '' | ||
460 | 208 | if context.has_key('active') and context.get('active',False) and \ | ||
461 | 209 | context.has_key('edit'): | ||
462 | 210 | etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) | ||
463 | 211 | |||
464 | 212 | xml_group1 = etree.SubElement(xml_form, 'group', {'col': '2', | ||
465 | 213 | 'colspan': '2'}) | ||
466 | 214 | context.update({'question_id' : tools.ustr(que.id),'page_number': sur_name_rec.page_no , 'transfer' : sur_name_read.transfer, 'page_id' : p_id}) | ||
467 | 215 | etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-edit", 'type' :'object', 'name':"action_edit_question", 'context' : tools.ustr(context)}) | ||
468 | 216 | etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-delete", 'type' :'object','name':"action_delete_question", 'context' : tools.ustr(context)}) | ||
469 | 217 | else: | ||
470 | 218 | etree.SubElement(xml_form, 'newline') | ||
471 | 219 | etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) | ||
472 | 220 | |||
473 | 221 | ans_ids = que_rec.answer_choice_ids | ||
474 | 222 | xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) | ||
475 | 223 | |||
476 | 224 | if que_rec.type == 'multiple_choice_only_one_ans': | ||
477 | 225 | selection = [] | ||
478 | 226 | for ans in ans_ids: | ||
479 | 227 | selection.append((tools.ustr(ans.id), ans.answer)) | ||
480 | 228 | xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'}) | ||
481 | 229 | etree.SubElement(xml_group, 'field', {'nolabel':'True','class':'dropdown-menus','readonly':str(readonly), 'name': tools.ustr(que.id) + "_selection"}) | ||
482 | 230 | fields[tools.ustr(que.id) + "_selection"] = {'type':'selection', 'selection' :selection, 'string':"Answer"} | ||
483 | 231 | |||
484 | 232 | elif que_rec.type == 'multiple_choice_multiple_ans': | ||
485 | 233 | xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) | ||
486 | 234 | for ans in ans_ids: | ||
487 | 235 | etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) | ||
488 | 236 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'boolean', 'string':ans.answer} | ||
489 | 237 | |||
490 | 238 | elif que_rec.type in ['matrix_of_choices_only_one_ans', 'rating_scale']: | ||
491 | 239 | if que_rec.comment_column: | ||
492 | 240 | col = "4" | ||
493 | 241 | colspan = "4" | ||
494 | 242 | else: | ||
495 | 243 | col = "2" | ||
496 | 244 | colspan = "2" | ||
497 | 245 | xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': tools.ustr(colspan)}) | ||
498 | 246 | for row in ans_ids: | ||
499 | 247 | etree.SubElement(xml_group, 'newline') | ||
500 | 248 | etree.SubElement(xml_group, 'field', {'nolabel':'True','readonly': str(readonly), 'class':'dropdown-menus','name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id),'string':to_xml(tools.ustr(row.answer))}) | ||
501 | 249 | selection = [('','')] | ||
502 | 250 | for col in que_rec.column_heading_ids: | ||
503 | 251 | selection.append((str(col.id), col.title)) | ||
504 | 252 | fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type':'selection', 'selection' : selection, 'string': "Answer"} | ||
505 | 253 | if que_rec.comment_column: | ||
506 | 254 | fields[tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec.column_name), 'views':{}} | ||
507 | 255 | etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id)+ "_field"}) | ||
508 | 256 | |||
509 | 257 | elif que_rec.type == 'matrix_of_choices_only_multi_ans': | ||
510 | 258 | xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) | ||
511 | 259 | etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) | ||
512 | 260 | for col in que_rec.column_heading_ids: | ||
513 | 261 | etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) | ||
514 | 262 | for row in ans_ids: | ||
515 | 263 | etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) +' :-', 'align': '0.0'}) | ||
516 | 264 | for col in que_col_head.browse(cr, uid, [head.id for head in que_rec.column_heading_ids]): | ||
517 | 265 | etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"}) | ||
518 | 266 | fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title} | ||
519 | 267 | |||
520 | 268 | elif que_rec.type == 'matrix_of_drop_down_menus': | ||
521 | 269 | xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) | ||
522 | 270 | etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) | ||
523 | 271 | for col in que_rec.column_heading_ids: | ||
524 | 272 | etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) | ||
525 | 273 | for row in ans_ids: | ||
526 | 274 | etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer))+' :-', 'align': '0.0'}) | ||
527 | 275 | for col in que_rec.column_heading_ids: | ||
528 | 276 | selection = [] | ||
529 | 277 | if col.menu_choice: | ||
530 | 278 | for item in col.menu_choice.split('\n'): | ||
531 | 279 | if item and not item.strip() == '': selection.append((item ,item)) | ||
532 | 280 | etree.SubElement(xml_group, 'field', {'nolabel':'True','class':'dropdown-menus','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id),'nolabel':'1'}) | ||
533 | 281 | fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'selection', 'string': col.title, 'selection':selection} | ||
534 | 282 | |||
535 | 283 | elif que_rec.type == 'multiple_textboxes': | ||
536 | 284 | xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) | ||
537 | 285 | type = "char" | ||
538 | 286 | if que_rec.is_validation_require: | ||
539 | 287 | if que_rec.validation_type in ['must_be_whole_number']: | ||
540 | 288 | type = "integer" | ||
541 | 289 | elif que_rec.validation_type in ['must_be_decimal_number']: | ||
542 | 290 | type = "float" | ||
543 | 291 | elif que_rec.validation_type in ['must_be_date']: | ||
544 | 292 | type = "date" | ||
545 | 293 | for ans in ans_ids: | ||
546 | 294 | etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) | ||
547 | 295 | if type == "char" : | ||
548 | 296 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} | ||
549 | 297 | else: | ||
550 | 298 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string':ans.answer} | ||
551 | 299 | |||
552 | 300 | elif que_rec.type == 'numerical_textboxes': | ||
553 | 301 | xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) | ||
554 | 302 | for ans in ans_ids: | ||
555 | 303 | etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) | ||
556 | 304 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type':'integer', 'string':ans.answer} | ||
557 | 305 | |||
558 | 306 | elif que_rec.type == 'date': | ||
559 | 307 | xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) | ||
560 | 308 | for ans in ans_ids: | ||
561 | 309 | etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) | ||
562 | 310 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'date', 'string':ans.answer} | ||
563 | 311 | |||
564 | 312 | elif que_rec.type == 'date_and_time': | ||
565 | 313 | xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) | ||
566 | 314 | for ans in ans_ids: | ||
567 | 315 | etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) | ||
568 | 316 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'datetime', 'string':ans.answer} | ||
569 | 317 | |||
570 | 318 | elif que_rec.type == 'descriptive_text': | ||
571 | 319 | if que_rec.descriptive_text: | ||
572 | 320 | for que_test in que_rec.descriptive_text.split('\n'): | ||
573 | 321 | etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) | ||
574 | 322 | |||
575 | 323 | elif que_rec.type == 'single_textbox': | ||
576 | 324 | etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel':"1" ,'colspan':"4"}) | ||
577 | 325 | fields[tools.ustr(que.id) + "_single"] = {'type':'char', 'size': 255, 'string':"single_textbox", 'views':{}} | ||
578 | 326 | |||
579 | 327 | elif que_rec.type == 'comment': | ||
580 | 328 | etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel':"1" ,'colspan':"4"}) | ||
581 | 329 | fields[tools.ustr(que.id) + "_comment"] = {'type':'text', 'string':"Comment/Eassy Box", 'views':{}} | ||
582 | 330 | |||
583 | 331 | elif que_rec.type == 'table': | ||
584 | 332 | xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'}) | ||
585 | 333 | for col in que_rec.column_heading_ids: | ||
586 | 334 | etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) | ||
587 | 335 | for row in range(0,que_rec.no_of_rows): | ||
588 | 336 | for col in que_rec.column_heading_ids: | ||
589 | 337 | etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row), 'nolabel':"1"}) | ||
590 | 338 | fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}} | ||
591 | 339 | |||
592 | 340 | elif que_rec.type == 'multiple_textboxes_diff_type': | ||
593 | 341 | xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) | ||
594 | 342 | for ans in ans_ids: | ||
595 | 343 | if ans.type == "email" : | ||
596 | 344 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} | ||
597 | 345 | etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly': str(readonly), 'widget':'email','width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) | ||
598 | 346 | else: | ||
599 | 347 | etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) | ||
600 | 348 | if ans.type == "char" : | ||
601 | 349 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} | ||
602 | 350 | elif ans.type in ['integer','float','date','datetime']: | ||
603 | 351 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string':ans.answer} | ||
604 | 352 | else: | ||
605 | 353 | selection = [] | ||
606 | 354 | if ans.menu_choice: | ||
607 | 355 | for item in ans.menu_choice.split('\n'): | ||
608 | 356 | if item and not item.strip() == '': selection.append((item ,item)) | ||
609 | 357 | fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer} | ||
610 | 358 | |||
611 | 359 | if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale'] and que_rec.is_comment_require: | ||
612 | 360 | if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: | ||
613 | 361 | etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) | ||
614 | 362 | fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} | ||
615 | 363 | if que_rec.comment_field_type == 'char': | ||
616 | 364 | etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) | ||
617 | 365 | fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} | ||
618 | 366 | elif que_rec.comment_field_type == 'text': | ||
619 | 367 | etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) | ||
620 | 368 | fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} | ||
621 | 369 | else: | ||
622 | 370 | if que_rec.comment_field_type == 'char': | ||
623 | 371 | etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) | ||
624 | 372 | etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) | ||
625 | 373 | fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} | ||
626 | 374 | elif que_rec.comment_field_type == 'text': | ||
627 | 375 | etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) | ||
628 | 376 | etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) | ||
629 | 377 | fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} | ||
630 | 378 | |||
631 | 379 | xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width':"100%"}) | ||
632 | 380 | |||
633 | 381 | if pre_button: | ||
634 | 382 | etree.SubElement(xml_footer, 'label', {'string': ""}) | ||
635 | 383 | etree.SubElement(xml_footer, 'button', {'name':"action_previous",'string':"e",'type':"object",'class':"answer_exit btn btn-primary btn-large oe_e"}) | ||
636 | 384 | but_string = "Next" | ||
637 | 385 | if int(page_number) + 1 == total_pages: | ||
638 | 386 | but_string = "Done" | ||
639 | 387 | if context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages and context.has_key('response_id') and context.has_key('response_no') and context.get('response_no',0) + 1 == len(context.get('response_id',0)): | ||
640 | 388 | etree.SubElement(xml_footer, 'label', {'string': ""}) | ||
641 | 389 | etree.SubElement(xml_footer, 'button', {'special' : 'cancel','string': tools.ustr("Done") ,'context' : tools.ustr(context), 'class':"oe_highlight"}) | ||
642 | 390 | elif context.has_key('active') and context.get('active', False) and int(page_number) + 1 == total_pages and context.has_key('response_id'): | ||
643 | 391 | etree.SubElement(xml_footer, 'label', {'string': ""}) | ||
644 | 392 | etree.SubElement(xml_footer, 'button', {'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) | ||
645 | 393 | elif context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages: | ||
646 | 394 | etree.SubElement(xml_footer, 'label', {'string': ""}) | ||
647 | 395 | etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string' : 'Done', 'context' : tools.ustr(context), 'class':"answer_exit btn btn-primary btn-large"}) | ||
648 | 396 | else: | ||
649 | 397 | etree.SubElement(xml_footer, 'label', {'string': ""}) | ||
650 | 398 | etree.SubElement(xml_footer, 'button', {'class': "btn btn-primary btn-large oe_e",'name':"action_next",'string':but_string == 'Next'and '/' or '8','type':"object",'context' : tools.ustr(context)}) | ||
651 | 399 | etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':"c",'class':"answer_exit btn btn-primary btn-large oe_e"}) | ||
652 | 400 | etree.SubElement(xml_footer, 'label', {'string': tools.ustr(page_number+ 1) + "/" + tools.ustr(total_pages), 'class':"oe_survey_title_page oe_right"}) | ||
653 | 401 | |||
654 | 402 | root = form.getroottree() | ||
655 | 403 | result['arch'] = etree.tostring(root) | ||
656 | 404 | result['fields'] = fields | ||
657 | 405 | print 'rooooooooot',etree.tostring(root) | ||
658 | 406 | print 'fields', fields | ||
659 | 407 | result['context'] = context | ||
660 | 408 | else: | ||
661 | 409 | survey_obj.write(cr, uid, survey_id, {'tot_comp_survey' : sur_rec.tot_comp_survey + 1}) | ||
662 | 410 | sur_response_obj.write(cr, uid, [sur_name_read.response], {'state' : 'done'}) | ||
663 | 411 | |||
664 | 412 | # mark the survey request as done; call 'survey_req_done' on its actual model | ||
665 | 413 | survey_req_obj = self.pool.get(context.get('active_model')) | ||
666 | 414 | if survey_req_obj and hasattr(survey_req_obj, 'survey_req_done'): | ||
667 | 415 | survey_req_obj.survey_req_done(cr, uid, context.get('active_ids', []), context=context) | ||
668 | 416 | |||
669 | 417 | if sur_rec.send_response: | ||
670 | 418 | survey_data = survey_obj.browse(cr, uid, survey_id) | ||
671 | 419 | response_id = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False))['response'] | ||
672 | 420 | report = self.create_report(cr, uid, [survey_id], 'report.survey.browse.response', survey_data.title,context) | ||
673 | 421 | attachments = {} | ||
674 | 422 | pdf_filename = addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf" | ||
675 | 423 | if os.path.exists(pdf_filename): | ||
676 | 424 | file = open(pdf_filename) | ||
677 | 425 | file_data = "" | ||
678 | 426 | while 1: | ||
679 | 427 | line = file.readline() | ||
680 | 428 | file_data += line | ||
681 | 429 | if not line: | ||
682 | 430 | break | ||
683 | 431 | |||
684 | 432 | attachments[survey_data.title + ".pdf"] = file_data | ||
685 | 433 | file.close() | ||
686 | 434 | os.remove(addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf") | ||
687 | 435 | context.update({'response_id':response_id}) | ||
688 | 436 | user_email = user_obj.browse(cr, uid, uid, context).email | ||
689 | 437 | resp_email = survey_data.responsible_id and survey_data.responsible_id.email or False | ||
690 | 438 | |||
691 | 439 | if user_email and resp_email: | ||
692 | 440 | user_name = user_obj.browse(cr, uid, uid, context=context).name | ||
693 | 441 | mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(user_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks." | ||
694 | 442 | vals = {'state': 'outgoing', | ||
695 | 443 | 'subject': "Survey Answer Of " + user_name, | ||
696 | 444 | 'body_html': '<pre>%s</pre>' % mail, | ||
697 | 445 | 'email_to': [resp_email], | ||
698 | 446 | 'email_from': user_email} | ||
699 | 447 | if attachments: | ||
700 | 448 | vals['attachment_ids'] = [(0,0,{'name': a_name, | ||
701 | 449 | 'datas_fname': a_name, | ||
702 | 450 | 'datas': str(a_content).encode('base64')}) | ||
703 | 451 | for a_name, a_content in attachments.items()] | ||
704 | 452 | self.pool.get('mail.mail').create(cr, uid, vals, context=context) | ||
705 | 453 | |||
706 | 454 | xml_form = etree.Element('form', {'string': _('Complete Survey Answer')}) | ||
707 | 455 | xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4' ,'class': 'oe_survey_title_height'}) | ||
708 | 456 | |||
709 | 457 | etree.SubElement(xml_form, 'separator', {'string': 'Survey Completed', 'colspan': "4"}) | ||
710 | 458 | etree.SubElement(xml_form, 'label', {'string': 'Thanks for your Answer'}) | ||
711 | 459 | etree.SubElement(xml_form, 'newline') | ||
712 | 460 | etree.SubElement(xml_footer, 'button', {'special':"cancel",'string':"OK",'colspan':"2",'class':'oe_highlight'}) | ||
713 | 461 | root = xml_form.getroottree() | ||
714 | 462 | result['arch'] = etree.tostring(root) | ||
715 | 463 | result['fields'] = {} | ||
716 | 464 | result['context'] = context | ||
717 | 465 | return result | ||
718 | 466 | |||
719 | 467 | |||
720 | 468 | def action_next(self, cr, uid, ids, context=None): | ||
721 | 469 | res = super(survey_question_wiz, self).action_next(cr, uid, ids, context) | ||
722 | 470 | |||
723 | 471 | res.update( { | ||
724 | 472 | 'target': 'inline', | ||
725 | 473 | }) | ||
726 | 474 | return res | ||
727 | 475 | |||
728 | 0 | 476 | ||
729 | === added file 'answer_survey/wizard/survey_send_invitation.py' | |||
730 | --- answer_survey/wizard/survey_send_invitation.py 1970-01-01 00:00:00 +0000 | |||
731 | +++ answer_survey/wizard/survey_send_invitation.py 2013-09-27 19:15:29 +0000 | |||
732 | @@ -0,0 +1,166 @@ | |||
733 | 1 | # -*- coding: utf-8 -*- | ||
734 | 2 | ############################################################################## | ||
735 | 3 | # | ||
736 | 4 | # OpenERP, Open Source Management Solution | ||
737 | 5 | # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>) | ||
738 | 6 | # | ||
739 | 7 | # This program is free software: you can redistribute it and/or modify | ||
740 | 8 | # it under the terms of the GNU Affero General Public License as | ||
741 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
742 | 10 | # License, or (at your option) any later version | ||
743 | 11 | # | ||
744 | 12 | # This program is distributed in the hope that it will be useful, | ||
745 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
746 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
747 | 15 | # GNU Affero General Public License for more details | ||
748 | 16 | # | ||
749 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
750 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/> | ||
751 | 19 | # | ||
752 | 20 | ############################################################################## | ||
753 | 21 | |||
754 | 22 | import time | ||
755 | 23 | from random import choice | ||
756 | 24 | import string | ||
757 | 25 | import os | ||
758 | 26 | import datetime | ||
759 | 27 | import socket | ||
760 | 28 | |||
761 | 29 | from openerp import addons, netsvc, tools | ||
762 | 30 | from openerp.osv import fields, osv | ||
763 | 31 | from openerp.tools.translate import _ | ||
764 | 32 | |||
765 | 33 | |||
766 | 34 | class survey_send_invitation(osv.TransientModel): | ||
767 | 35 | _inherit = 'survey.send.invitation' | ||
768 | 36 | |||
769 | 37 | def action_send(self, cr, uid, ids, context=None): | ||
770 | 38 | if context is None: | ||
771 | 39 | context = {} | ||
772 | 40 | record = self.read(cr, uid, ids, [],context=context) | ||
773 | 41 | survey_ids = context.get('active_ids', []) | ||
774 | 42 | record = record and record[0] | ||
775 | 43 | partner_ids = record['partner_ids'] | ||
776 | 44 | user_ref= self.pool.get('res.users') | ||
777 | 45 | survey_ref= self.pool.get('survey') | ||
778 | 46 | mail_message = self.pool.get('mail.message') | ||
779 | 47 | |||
780 | 48 | model_data_obj = self.pool.get('ir.model.data') | ||
781 | 49 | group_ids = [] | ||
782 | 50 | group_id = model_data_obj._get_id(cr, uid, 'base', 'group_survey_user') | ||
783 | 51 | group_id and group_ids.append(model_data_obj.browse(cr, uid, group_id, context).res_id) | ||
784 | 52 | group_id = model_data_obj._get_id(cr, uid, 'answer_survey', 'only_answer_menu') | ||
785 | 53 | group_id and group_ids.append(model_data_obj.browse(cr, uid, group_id, context).res_id) | ||
786 | 54 | group_id = model_data_obj._get_id(cr, uid, 'portal', 'group_portal') | ||
787 | 55 | group_id and group_ids.append(model_data_obj.browse(cr, uid, group_id, context).res_id) | ||
788 | 56 | |||
789 | 57 | act_id = self.pool.get('ir.actions.act_window') | ||
790 | 58 | act_id = act_id.search(cr, uid, [('res_model', '=' , 'survey.name.wiz'), \ | ||
791 | 59 | ('view_type', '=', 'form')]) | ||
792 | 60 | out = "login,password\n" | ||
793 | 61 | skipped = 0 | ||
794 | 62 | existing = "" | ||
795 | 63 | created = "" | ||
796 | 64 | error = "" | ||
797 | 65 | new_user = [] | ||
798 | 66 | attachments = {} | ||
799 | 67 | current_sur = survey_ref.browse(cr, uid, context.get('active_id'), context=context) | ||
800 | 68 | exist_user = current_sur.invited_user_ids | ||
801 | 69 | if exist_user: | ||
802 | 70 | for use in exist_user: | ||
803 | 71 | new_user.append(use.id) | ||
804 | 72 | for id in survey_ref.browse(cr, uid, survey_ids): | ||
805 | 73 | report = self.create_report(cr, uid, [id.id], 'report.survey.form', id.title) | ||
806 | 74 | file = open(addons.get_module_resource('survey', 'report') + id.title +".pdf") | ||
807 | 75 | file_data = "" | ||
808 | 76 | while 1: | ||
809 | 77 | line = file.readline() | ||
810 | 78 | file_data += line | ||
811 | 79 | if not line: | ||
812 | 80 | break | ||
813 | 81 | file.close() | ||
814 | 82 | attachments[id.title +".pdf"] = file_data | ||
815 | 83 | os.remove(addons.get_module_resource('survey', 'report') + id.title +".pdf") | ||
816 | 84 | |||
817 | 85 | for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids): | ||
818 | 86 | if not partner.email: | ||
819 | 87 | skipped+= 1 | ||
820 | 88 | continue | ||
821 | 89 | user = user_ref.search(cr, uid, [('login', "=", partner.email)]) | ||
822 | 90 | if user: | ||
823 | 91 | if user[0] not in new_user: | ||
824 | 92 | new_user.append(user[0]) | ||
825 | 93 | user = user_ref.browse(cr, uid, user[0]) | ||
826 | 94 | user_ref.write(cr, uid, user.id, {'survey_id':[[6, 0, survey_ids]]}) | ||
827 | 95 | mail = record['mail']%{'login':partner.email, 'passwd':user.password, \ | ||
828 | 96 | 'name' : partner.name} | ||
829 | 97 | if record['send_mail_existing']: | ||
830 | 98 | vals = { | ||
831 | 99 | 'state': 'outgoing', | ||
832 | 100 | 'subject': record['mail_subject_existing'], | ||
833 | 101 | 'body_html': '<pre>%s</pre>' % mail, | ||
834 | 102 | 'email_to': partner.email, | ||
835 | 103 | 'email_from': record['mail_from'], | ||
836 | 104 | } | ||
837 | 105 | self.pool.get('mail.mail').create(cr, uid, vals, context=context) | ||
838 | 106 | existing+= "- %s (Login: %s, Password: %s)\n" % (user.name, partner.email, \ | ||
839 | 107 | user.password) | ||
840 | 108 | continue | ||
841 | 109 | |||
842 | 110 | passwd= self.genpasswd() | ||
843 | 111 | out+= partner.email + ',' + passwd + '\n' | ||
844 | 112 | mail= record['mail'] % {'login' : partner.email, 'passwd' : passwd, 'name' : partner.name} | ||
845 | 113 | if record['send_mail']: | ||
846 | 114 | vals = { | ||
847 | 115 | 'state': 'outgoing', | ||
848 | 116 | 'subject': record['mail_subject'], | ||
849 | 117 | 'body_html': '<pre>%s</pre>' % mail, | ||
850 | 118 | 'email_to': partner.email, | ||
851 | 119 | 'email_from': record['mail_from'], | ||
852 | 120 | } | ||
853 | 121 | if attachments: | ||
854 | 122 | vals['attachment_ids'] = [(0,0,{'name': a_name, | ||
855 | 123 | 'datas_fname': a_name, | ||
856 | 124 | 'datas': str(a_content).encode('base64')}) | ||
857 | 125 | for a_name, a_content in attachments.items()] | ||
858 | 126 | ans = self.pool.get('mail.mail').create(cr, uid, vals, context=context) | ||
859 | 127 | if ans: | ||
860 | 128 | res_data = {'name': partner.name or _('Unknown'), | ||
861 | 129 | 'login': partner.email, | ||
862 | 130 | 'password': passwd, | ||
863 | 131 | 'address_id': partner.id, | ||
864 | 132 | 'groups_id': [[6, 0, group_ids]], | ||
865 | 133 | 'action_id': act_id[0], | ||
866 | 134 | 'survey_id': [[6, 0, survey_ids]] | ||
867 | 135 | } | ||
868 | 136 | user = user_ref.create(cr, uid, res_data) | ||
869 | 137 | if user not in new_user: | ||
870 | 138 | new_user.append(user) | ||
871 | 139 | created+= "- %s (Login: %s, Password: %s)\n" % (partner.name or _('Unknown'),\ | ||
872 | 140 | partner.email, passwd) | ||
873 | 141 | else: | ||
874 | 142 | error+= "- %s (Login: %s, Password: %s)\n" % (partner.name or _('Unknown'),\ | ||
875 | 143 | partner.email, passwd) | ||
876 | 144 | |||
877 | 145 | new_vals = {} | ||
878 | 146 | new_vals.update({'invited_user_ids':[[6,0,new_user]]}) | ||
879 | 147 | survey_ref.write(cr, uid, context.get('active_id'),new_vals) | ||
880 | 148 | note= "" | ||
881 | 149 | if created: | ||
882 | 150 | note += 'Created users:\n%s\n\n' % (created) | ||
883 | 151 | if existing: | ||
884 | 152 | note +='Already existing users:\n%s\n\n' % (existing) | ||
885 | 153 | if skipped: | ||
886 | 154 | note += "%d contacts where ignored (an email address is missing).\n\n" % (skipped) | ||
887 | 155 | if error: | ||
888 | 156 | note += 'Email not send successfully:\n====================\n%s\n' % (error) | ||
889 | 157 | context.update({'note' : note}) | ||
890 | 158 | return { | ||
891 | 159 | 'view_type': 'form', | ||
892 | 160 | "view_mode": 'form', | ||
893 | 161 | 'res_model': 'survey.send.invitation.log', | ||
894 | 162 | 'type': 'ir.actions.act_window', | ||
895 | 163 | 'target': 'new', | ||
896 | 164 | 'context': context | ||
897 | 165 | } | ||
898 | 166 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |