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={}
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")]
"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"),
}
"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"),
}