From: Sébastien CHAZALLET Date: Wed, 20 Mar 2013 14:28:11 +0000 (+0100) Subject: Merge branch 'master' X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=92cf47a2a54e86aeca15ae7c276d2b72e285edce;hp=-c;p=OpenERP%2Ftodolist.git Merge branch 'master' --- 92cf47a2a54e86aeca15ae7c276d2b72e285edce diff --combined todolist.py index 13a208c,5a40890..fee9aea --- a/todolist.py +++ b/todolist.py @@@ -8,6 -8,37 +8,37 @@@ from openerp.osv import osv, field class Container(osv.Model): """TODO List : Tasks container""" + + def _get_nb_task(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)) + + + def _task_progress(self, cr, uid, ids, field, arg, context=None): + result = {} + for container in self.browse(cr, uid, ids, context=context): + done = total = 0 + for task in container.tasks.browse(cr, uid, ids, context=context): + total += 1 + if task.state == "done": + done += 1 + result[container.id] = total and done/total or 0. + return result + + + def _task_progress2(self, cr, uid, ids, field, arg, context=None): + result = {} + for container in self.browse(cr, uid, ids, context=context): + tasks = container.tasks + total = len(tasks) + done = len([t for t in tasks if t.state == "done"]) + result[container.id] = total and done/total or 0. + return result + + _name = "todolist.container" _status = [("draft", "Draft"), ("pending", "Pending"), ("done", "Done")] @@@ -21,6 -52,8 +52,8 @@@ "state": fields.selection(_status, string="State", select=True), "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_task, type="integer", string="Number of tasks"), + "progress_tasks": fields.function(_task_progress2, type="float", string="Progression"), } _defaults = { @@@ -40,6 -73,8 +73,8 @@@ ), ] + _order = "name" + def action_start(self, cr, uid, ids, context=None): self.write(cr, uid, ids, {"state": "pending"}, context=context) return self @@@ -55,11 -90,6 +90,11 @@@ return self + def search(self, cr, user, args=[], offset=0, limit=None, order=None, context=None, count=False): + args.append(("create_uid", "=", user)) + if len(args) != 1: + args.insert(0, "&") + return osv.Model.search(self, cr, user, args, offset, limit, order, context, count) class Task(osv.Model): @@@ -106,14 -136,8 +141,14 @@@ self.write(cr, uid, ids, {"state": "done"}, context=context) return self + def search(self, cr, user, args=[], offset=0, limit=None, order=None, context=None, count=False): + args.append(("create_uid", "=", user)) + if len(args) != 1: + args.insert(0, "&") + return osv.Model.search(self, cr, user, args, offset, limit, order, context, count) + + -# ------------------- class Theme ------------------- # class Topic(osv.Model): """TODO List : Container"s Topic"""