X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=todolist.py;h=a555d79540ea9d183799ec6976e9077123532e44;hb=54f914e4dbd55bae9b8899388fa7aa70390d84ee;hp=8acbe8b9b2fdccc48cbca9baadb646c940b813fb;hpb=4a31ce3f25439300f3be631858356578d79c3a31;p=OpenERP%2Ftodolist.git diff --git a/todolist.py b/todolist.py index 8acbe8b..a555d79 100644 --- a/todolist.py +++ b/todolist.py @@ -8,13 +8,13 @@ from openerp.osv import osv, fields class Container(osv.Model): """TODO List : Tasks container""" - def _get_nb_tasks(self, cr, uid, ids, field, arg, context=None): result = {} for container in self.browse(cr, uid, ids, context=context): result[container.id] = len(container.tasks) return result -# return dict((c.id, len(c.tasks)) for c in self.browse(cr, uid, ids, context=context)) +# OR : return dict((c.id, len(c.tasks)) for c in self.browse(cr, uid, ids, context=context)) + def _get_nb_tasks_done(self, cr, uid, ids, field, arg, context=None): result={} @@ -22,12 +22,26 @@ class Container(osv.Model): result[c.id] = len([t for t in c.tasks if t.state == "done"]) return result + def _tasks_progress(self, cr, uid, ids, field, arg, context=None): result = {} for c in self.browse(cr, uid, ids, context=context): result[c.id] = c.number_tasks and c.number_tasks_done*100./c.number_tasks or 0. return result + + def copy(self, cr, uid, id, default, context=None): + container = self.browse(cr, uid, id, context=context) + new_name = "Copy of %s" % container.name + # =like is the original LIKE operator from SQL + others_count = self.search(cr, uid, [('name', '=like', new_name+'%')], + count=True, context=context) + if others_count > 0: + new_name = "%s (%s)" % (new_name, others_count+1) + default['name'] = new_name + return osv.Model.copy(self, cr, uid, id, default, context=context) + + _name = "todolist.container" _status = [("draft", "Draft"), ("pending", "Pending"), ("done", "Done")] @@ -42,7 +56,7 @@ class Container(osv.Model): "tasks": fields.one2many("todolist.task", "container_id", string="Tasks"), "topics_id": fields.many2many("todolist.topic", "todolist_container_topic_rel", "container_id", "topic_id", string="Topics", domain=[("activated", "=","Active")]), "number_tasks": fields.function(_get_nb_tasks, type="integer", string="Number of tasks"), - "number_tasks_done": fields.function(_get_nb_tasks_done, type="integer", string="Number of tasks"), + "number_tasks_done": fields.function(_get_nb_tasks_done, type="integer", string="Number of tasks done"), "progress_tasks": fields.function(_tasks_progress, type="float", string="Progression"), } @@ -181,8 +195,8 @@ class Topic(osv.Model): "activated": fields.selection(_states, string="State", select=True), "todolist_ids": fields.many2many("todolist.container", "todolist_container_topic_rel", "topic_id", "Container_id", string="TO DO Lists"), "nb_lists": fields.function(_get_nb_lists, type="integer", string="Number of lists"), - "number_tasks": fields.function(_get_number_tasks, type="integer", string="Number of lists"), - "number_tasks_done": fields.function(_get_number_tasks_done, type="integer", string="Number of lists"), + "number_tasks": fields.function(_get_number_tasks, type="integer", string="Number of tasks"), + "number_tasks_done": fields.function(_get_number_tasks_done, type="integer", string="Number of tasks done"), "progress_tasks": fields.function(_progress_tasks, type="float", string="Number of lists"), }