Merge lp:~domsense/domsense-agilebg-addons/adding_super_calendar into lp:domsense-agilebg-addons/6.0
- adding_super_calendar
- Merge into 6.0
Proposed by
Lorenzo Battistini
Status: | Merged |
---|---|
Merged at revision: | 129 |
Proposed branch: | lp:~domsense/domsense-agilebg-addons/adding_super_calendar |
Merge into: | lp:domsense-agilebg-addons/6.0 |
Diff against target: |
369 lines (+332/-0) 7 files modified
super_calendar/AUTHORS.txt (+1/-0) super_calendar/__init__.py (+22/-0) super_calendar/__openerp__.py (+46/-0) super_calendar/cron_data.xml (+13/-0) super_calendar/security/ir.model.access.csv (+4/-0) super_calendar/super_calendar.py (+113/-0) super_calendar/super_calendar_view.xml (+133/-0) |
To merge this branch: | bzr merge lp:~domsense/domsense-agilebg-addons/adding_super_calendar |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Agile Business Group | Pending | ||
Review via email: mp+92039@code.launchpad.net |
Commit message
Description of the change
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 | === added directory 'super_calendar' |
2 | === added file 'super_calendar/AUTHORS.txt' |
3 | --- super_calendar/AUTHORS.txt 1970-01-01 00:00:00 +0000 |
4 | +++ super_calendar/AUTHORS.txt 2012-02-08 14:37:22 +0000 |
5 | @@ -0,0 +1,1 @@ |
6 | +Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
7 | |
8 | === added file 'super_calendar/__init__.py' |
9 | --- super_calendar/__init__.py 1970-01-01 00:00:00 +0000 |
10 | +++ super_calendar/__init__.py 2012-02-08 14:37:22 +0000 |
11 | @@ -0,0 +1,22 @@ |
12 | +# -*- coding: utf-8 -*- |
13 | +############################################################################## |
14 | +# |
15 | +# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>) |
16 | +# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>) |
17 | +# All Rights Reserved |
18 | +# |
19 | +# This program is free software: you can redistribute it and/or modify |
20 | +# it under the terms of the GNU Affero General Public License as published |
21 | +# by the Free Software Foundation, either version 3 of the License, or |
22 | +# (at your option) any later version. |
23 | +# |
24 | +# This program is distributed in the hope that it will be useful, |
25 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 | +# GNU General Public License for more details. |
28 | +# |
29 | +# You should have received a copy of the GNU Affero General Public License |
30 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
31 | +# |
32 | +############################################################################## |
33 | +import super_calendar |
34 | |
35 | === added file 'super_calendar/__openerp__.py' |
36 | --- super_calendar/__openerp__.py 1970-01-01 00:00:00 +0000 |
37 | +++ super_calendar/__openerp__.py 2012-02-08 14:37:22 +0000 |
38 | @@ -0,0 +1,46 @@ |
39 | +# -*- coding: utf-8 -*- |
40 | +############################################################################## |
41 | +# |
42 | +# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>) |
43 | +# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>) |
44 | +# All Rights Reserved |
45 | +# |
46 | +# This program is free software: you can redistribute it and/or modify |
47 | +# it under the terms of the GNU Affero General Public License as published |
48 | +# by the Free Software Foundation, either version 3 of the License, or |
49 | +# (at your option) any later version. |
50 | +# |
51 | +# This program is distributed in the hope that it will be useful, |
52 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
53 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
54 | +# GNU General Public License for more details. |
55 | +# |
56 | +# You should have received a copy of the GNU Affero General Public License |
57 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
58 | +# |
59 | +############################################################################## |
60 | +{ |
61 | + 'name': "Super Calendar", |
62 | + 'version': '0.1', |
63 | + 'category': 'Generic Modules/Others', |
64 | + 'description': """ |
65 | + This module allows to create configurable calendars. |
66 | + |
67 | + Through the 'calendar configurator' object, you can specify which models have to be merged in the super calendar. For each model, you have to define the 'description' and 'date_start' fields at least. Then you can define 'duration' and the 'user_id' fields. |
68 | + |
69 | + The 'super.calendar' object contains the the merged calendars. The 'super.calendar' can be updated by 'ir.cron' or manually. |
70 | + """, |
71 | + 'author': 'Agile Business Group & Domsense', |
72 | + 'website': 'http://www.agilebg.com', |
73 | + 'license': 'AGPL-3', |
74 | + "depends" : ['base'], |
75 | + "init_xml" : [], |
76 | + "update_xml" : [ |
77 | + 'super_calendar_view.xml', |
78 | + 'cron_data.xml', |
79 | + 'security/ir.model.access.csv', |
80 | + ], |
81 | + "demo_xml" : [], |
82 | + "active": False, |
83 | + "installable": True |
84 | +} |
85 | |
86 | === added file 'super_calendar/cron_data.xml' |
87 | --- super_calendar/cron_data.xml 1970-01-01 00:00:00 +0000 |
88 | +++ super_calendar/cron_data.xml 2012-02-08 14:37:22 +0000 |
89 | @@ -0,0 +1,13 @@ |
90 | +<?xml version="1.0"?> |
91 | +<openerp> |
92 | + <data noupdate="1"> |
93 | + <record model="ir.cron" id="generate_calendar_records_cron"> |
94 | + <field name="name">Generate Calendar Records</field> |
95 | + <field name="interval_number">30</field> |
96 | + <field name="interval_type">minutes</field> |
97 | + <field eval="'super.calendar.configurator'" name="model"/> |
98 | + <field eval="'generate_calendar_records'" name="function"/> |
99 | + <field eval="'[[],{}]'" name="args"/> |
100 | + </record> |
101 | + </data> |
102 | +</openerp> |
103 | |
104 | === added directory 'super_calendar/i18n' |
105 | === added directory 'super_calendar/security' |
106 | === added file 'super_calendar/security/ir.model.access.csv' |
107 | --- super_calendar/security/ir.model.access.csv 1970-01-01 00:00:00 +0000 |
108 | +++ super_calendar/security/ir.model.access.csv 2012-02-08 14:37:22 +0000 |
109 | @@ -0,0 +1,4 @@ |
110 | +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink |
111 | +access_model_super_calendar_configurator,access_model_super_calendar_configurator,model_super_calendar_configurator,base.group_system,1,1,1,1 |
112 | +access_model_super_calendar_configurator_line,access_model_super_calendar_configurator_line,model_super_calendar_configurator_line,base.group_system,1,1,1,1 |
113 | +access_model_super_calendar,access_model_super_calendar,model_super_calendar,base.group_user,1,0,0,0 |
114 | |
115 | === added file 'super_calendar/super_calendar.py' |
116 | --- super_calendar/super_calendar.py 1970-01-01 00:00:00 +0000 |
117 | +++ super_calendar/super_calendar.py 2012-02-08 14:37:22 +0000 |
118 | @@ -0,0 +1,113 @@ |
119 | +# -*- coding: utf-8 -*- |
120 | +############################################################################## |
121 | +# |
122 | +# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>) |
123 | +# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>) |
124 | +# All Rights Reserved |
125 | +# |
126 | +# This program is free software: you can redistribute it and/or modify |
127 | +# it under the terms of the GNU Affero General Public License as published |
128 | +# by the Free Software Foundation, either version 3 of the License, or |
129 | +# (at your option) any later version. |
130 | +# |
131 | +# This program is distributed in the hope that it will be useful, |
132 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
133 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
134 | +# GNU General Public License for more details. |
135 | +# |
136 | +# You should have received a copy of the GNU Affero General Public License |
137 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
138 | +# |
139 | +############################################################################## |
140 | + |
141 | +from osv import fields, osv |
142 | +from tools.translate import _ |
143 | +import netsvc |
144 | + |
145 | +def _models_get(self, cr, uid, context={}): |
146 | + obj = self.pool.get('ir.model') |
147 | + ids = obj.search(cr, uid, []) |
148 | + res = obj.read(cr, uid, ids, ['model', 'name'], context) |
149 | + return [(r['model'], r['name']) for r in res] |
150 | + |
151 | +class super_calendar_configurator(osv.osv): |
152 | + _logger = netsvc.Logger() |
153 | + _name = 'super.calendar.configurator' |
154 | + _columns = { |
155 | + 'name': fields.char('Name', size=64, required=True), |
156 | + 'line_ids': fields.one2many('super.calendar.configurator.line', 'configurator_id', 'Lines'), |
157 | + } |
158 | + |
159 | + def generate_calendar_records(self, cr, uid, ids, context=None): |
160 | + configurator_ids = self.search(cr, uid, []) |
161 | + super_calendar_pool = self.pool.get('super.calendar') |
162 | + |
163 | + # removing old records |
164 | + super_calendar_ids = super_calendar_pool.search(cr, uid, []) |
165 | + super_calendar_pool.unlink(cr, uid, super_calendar_ids) |
166 | + |
167 | + for configurator_id in configurator_ids: |
168 | + configurator = self.browse(cr, uid, configurator_id) |
169 | + for line in configurator.line_ids: |
170 | + current_pool = self.pool.get(line.name.model) |
171 | + current_record_ids = current_pool.search(cr, uid, line.domain and eval(line.domain) or []) |
172 | + for current_record_id in current_record_ids: |
173 | + current_record = current_pool.browse(cr, uid, current_record_id) |
174 | + if line.user_field_id and \ |
175 | + current_record[line.user_field_id.name]._table_name != 'res.users': |
176 | + raise osv.except_osv(_('Error'), |
177 | + _("The 'User' field of record %s (%s) does not refer to res.users") |
178 | + % (current_record[line.description_field_id.name], line.name.model)) |
179 | + super_calendar_values = { |
180 | + 'name': current_record[line.description_field_id.name], |
181 | + 'date_start': current_record[line.date_start_field_id.name], |
182 | + #'date_stop': line.date_stop_field_id and current_record[line.date_stop_field_id.name] or False, |
183 | + 'duration': line.duration_field_id and current_record[line.duration_field_id.name] or False, |
184 | + 'user_id': line.user_field_id and current_record[line.user_field_id.name] and current_record[line.user_field_id.name].id or False, |
185 | + 'configurator_id': configurator.id, |
186 | + 'res_id': line.name.model+','+str(current_record['id']), |
187 | + 'model_id': line.name.id, |
188 | + } |
189 | + super_calendar_pool.create(cr, uid, super_calendar_values) |
190 | + self._logger.notifyChannel('super_calendar', netsvc.LOG_INFO, "Calendar generated") |
191 | + return True |
192 | + |
193 | +super_calendar_configurator() |
194 | + |
195 | +class super_calendar_configurator_line(osv.osv): |
196 | + _name = 'super.calendar.configurator.line' |
197 | + _columns = { |
198 | + 'name': fields.many2one('ir.model', 'Model', required=True), |
199 | + 'domain': fields.char('Domain', size=512), |
200 | + 'configurator_id': fields.many2one('super.calendar.configurator', 'Configurator'), |
201 | + 'description_field_id': fields.many2one('ir.model.fields', 'Description field', |
202 | + domain="[('model_id', '=', name),('ttype', '=', 'char')]", required=True), |
203 | + 'date_start_field_id': fields.many2one('ir.model.fields', 'Start date field', |
204 | + domain="['&',('ttype', '=', 'datetime'),('model_id', '=', name)]", |
205 | + required=True), |
206 | +# 'date_stop_field_id': fields.many2one('ir.model.fields', 'End date field', |
207 | +# domain="['&',('ttype', '=', 'datetime'),('model_id', '=', name)]"), |
208 | + 'duration_field_id': fields.many2one('ir.model.fields', 'Duration field', |
209 | + domain="['&',('ttype', '=', 'float'),('model_id', '=', name)]"), |
210 | + 'user_field_id': fields.many2one('ir.model.fields', 'User field', |
211 | + domain="['&',('ttype', '=', 'many2one'),('model_id', '=', name)]"), |
212 | + } |
213 | + _sql_constraints = [ |
214 | + ('name', 'unique(configurator_id,name)', 'The model must be unique per configurator' ) |
215 | + ] |
216 | +super_calendar_configurator_line() |
217 | + |
218 | +#TODO security and cron |
219 | +class super_calendar(osv.osv): |
220 | + _name = 'super.calendar' |
221 | + _columns = { |
222 | + 'name': fields.char('Description', size=64, required=True), |
223 | + 'date_start':fields.datetime('Start date', required=True), |
224 | + #'date_stop':fields.datetime('End date'), # to be removed? |
225 | + 'duration':fields.float('Duration'), |
226 | + 'user_id': fields.many2one('res.users', 'User'), |
227 | + 'configurator_id': fields.many2one('super.calendar.configurator', 'Configurator'), |
228 | + 'res_id': fields.reference('Resource', selection=_models_get, size=128), |
229 | + 'model_id': fields.many2one('ir.model', 'Model'), |
230 | + } |
231 | +super_calendar() |
232 | |
233 | === added file 'super_calendar/super_calendar_view.xml' |
234 | --- super_calendar/super_calendar_view.xml 1970-01-01 00:00:00 +0000 |
235 | +++ super_calendar/super_calendar_view.xml 2012-02-08 14:37:22 +0000 |
236 | @@ -0,0 +1,133 @@ |
237 | +<?xml version="1.0"?> |
238 | +<openerp> |
239 | + <data> |
240 | + |
241 | + <!-- configurator --> |
242 | + |
243 | + <record model="ir.ui.view" id="super_calendar_configurator_tree"> |
244 | + <field name="name">super_calendar_configurator_tree</field> |
245 | + <field name="model">super.calendar.configurator</field> |
246 | + <field name="type">tree</field> |
247 | + <field name="arch" type="xml"> |
248 | + <tree string="Configurators"> |
249 | + <field name="name"/> |
250 | + </tree> |
251 | + </field> |
252 | + </record> |
253 | + <record model="ir.ui.view" id="super_calendar_configurator_form"> |
254 | + <field name="name">super_calendar_configurator_form</field> |
255 | + <field name="model">super.calendar.configurator</field> |
256 | + <field name="type">form</field> |
257 | + <field name="arch" type="xml"> |
258 | + <form string="Configurator"> |
259 | + <field name="name" select="1" colspan="2"/> |
260 | + <newline/> |
261 | + <field name="line_ids" nolabel="1" colspan="4"> |
262 | + <tree string="Lines"> |
263 | + <field name="name"/> |
264 | + <field name="domain"/> |
265 | + </tree> |
266 | + <form string="Line"> |
267 | + <field name="name"/> |
268 | + <field name="domain"/> |
269 | + <field name="description_field_id"/> |
270 | + <field name="date_start_field_id"/> |
271 | + <!--<field name="date_stop_field_id"/>--> |
272 | + <field name="duration_field_id"/> |
273 | + <field name="user_field_id"/> |
274 | + </form> |
275 | + </field> |
276 | + <newline/> |
277 | + <button name="generate_calendar_records" string="Generate Calendar" type="object" icon="gtk-go-forward" colspan="2"/> |
278 | + </form> |
279 | + </field> |
280 | + </record> |
281 | + |
282 | + <record model="ir.actions.act_window" id="super_calendar_configurator"> |
283 | + <field name="name">Calendar Configurators</field> |
284 | + <field name="res_model">super.calendar.configurator</field> |
285 | + <field name="view_type">form</field> |
286 | + <field name="view_mode">tree,form</field> |
287 | + <field name="view_id" ref="super_calendar_configurator_tree"/> |
288 | + </record> |
289 | + |
290 | + <!-- calendar --> |
291 | + |
292 | + <record model="ir.ui.view" id="super_calendar_tree"> |
293 | + <field name="name">super_calendar_tree</field> |
294 | + <field name="model">super.calendar</field> |
295 | + <field name="type">tree</field> |
296 | + <field name="arch" type="xml"> |
297 | + <tree string="Calendar"> |
298 | + <field name="name"/> |
299 | + <field name="date_start"/> |
300 | + <!--<field name="date_stop"/>--> |
301 | + <field name="duration"/> |
302 | + <field name="user_id"/> |
303 | + <field name="configurator_id"/> |
304 | + <field name="model_id"/> |
305 | + </tree> |
306 | + </field> |
307 | + </record> |
308 | + <record model="ir.ui.view" id="super_calendar_form"> |
309 | + <field name="name">super_calendar_form</field> |
310 | + <field name="model">super.calendar</field> |
311 | + <field name="type">form</field> |
312 | + <field name="arch" type="xml"> |
313 | + <form string="Configurator"> |
314 | + <field name="name" readonly="1"/> |
315 | + <field name="date_start" readonly="1"/> |
316 | + <!--<field name="date_stop" readonly="1"/>--> |
317 | + <field name="duration" readonly="1"/> |
318 | + <field name="user_id" readonly="1"/> |
319 | + <field name="configurator_id" readonly="1"/> |
320 | + <field name="model_id" readonly="1"/> |
321 | + <field name="res_id"/> |
322 | + </form> |
323 | + </field> |
324 | + </record> |
325 | + <record model="ir.ui.view" id="super_calendar"> |
326 | + <field name="name">super_calendar</field> |
327 | + <field name="model">super.calendar</field> |
328 | + <field name="type">calendar</field> |
329 | + <field name="arch" type="xml"> |
330 | + <calendar string="Calendar" color="model_id" date_start="date_start" date_delay="duration"> |
331 | + <field name="name"/> |
332 | + </calendar> |
333 | + </field> |
334 | + </record> |
335 | + <record model="ir.ui.view" id="super_calendar_search"> |
336 | + <field name="name">super_calendar_search</field> |
337 | + <field name="model">super.calendar</field> |
338 | + <field name="type">search</field> |
339 | + <field name="arch" type="xml"> |
340 | + <search string="Search Calendar" > |
341 | + <field name="name"/> |
342 | + <field name="configurator_id" select="1"/> |
343 | + <field name="model_id" select="1"/> |
344 | + <field name="user_id" select="1"> |
345 | + <filter domain="[('user_id','=',uid)]" help="My Items" icon="terp-personal"/> |
346 | + </field> |
347 | + <newline/> |
348 | + <group expand="0" string="Extended Filters..." colspan="4" col="8"> |
349 | + <field name="date_start" /> |
350 | + <!--<field name="date_stop" />--> |
351 | + <field name="duration" /> |
352 | + </group> |
353 | + </search> |
354 | + </field> |
355 | + </record> |
356 | + |
357 | + <record model="ir.actions.act_window" id="super_calendar_action"> |
358 | + <field name="name">Super Calendar</field> |
359 | + <field name="res_model">super.calendar</field> |
360 | + <field name="view_type">form</field> |
361 | + <field name="view_mode">calendar,tree,form</field> |
362 | + <field name="view_id" ref="super_calendar"/> |
363 | + </record> |
364 | + |
365 | + <menuitem id="super_calendar_menu" name="Super Calendar" /> |
366 | + <menuitem id="super_calendar_calendar" name="Calendar" parent="super_calendar_menu" action="super_calendar_action"/> |
367 | + <menuitem id="super_calendar_configurators" name="Configurators" parent="super_calendar_menu" action="super_calendar_configurator"/> |
368 | + </data> |
369 | +</openerp> |