From: Alicia FLOREZ Date: Tue, 26 Mar 2013 09:51:07 +0000 (+0100) Subject: Modification de la dupplication des container X-Git-Url: http://git.inspyration.org/?p=OpenERP%2Ftodolist.git;a=commitdiff_plain;h=1956444d7225153c63171bac049e2e69bfe87d78 Modification de la dupplication des container --- diff --git a/sql/COPIER_CONTAINERS.SQL b/sql/COPIER_CONTAINERS.SQL new file mode 100644 index 0000000..075db64 --- /dev/null +++ b/sql/COPIER_CONTAINERS.SQL @@ -0,0 +1,30 @@ +CREATE OR REPLACE FUNCTION copierContainer (id_container todolist_container.id%TYPE) RETURNS INTEGER AS $copierContainer$ +DECLARE copy_id todolist_container.id%TYPE; + +BEGIN + INSERT INTO todolist_container (name, description, state) ( + SELECT 'Copy of ' || name, description, 'draft' + FROM todolist_container + WHERE id = id_container + ); + + SELECT currval(pg_get_serial_sequence('todolist_container', 'id')) INTO copy_id; + + INSERT INTO todolist_task (name, description, container_id, milestone, planned, manday, priority) ( + SELECT name, description, copy_id, milestone, planned, manday, priority + FROM todolist_task + WHERE container_id = id_container + ); + + INSERT INTO todolist_container_topic_rel (container_id, topic_id) ( + SELECT copy_id, topic_id + FROM todolist_container_topic_rel + WHERE container_id = id_container + ); + RETURN copy_id; +END; +$copierContainer$ LANGUAGE plpgsql; + +-- Appel : +-- SELECT copierContainer(3); + diff --git a/todolist.py b/todolist.py index 10f855f..5d0c666 100644 --- a/todolist.py +++ b/todolist.py @@ -30,16 +30,24 @@ class Container(osv.Model): 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) + #================================================================================ + + 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) + cr.execute("SELECT copierContainer (%s);", (id,)) + return cr.fetchone()[0] + def _get_manday(self, cr, uid, ids, field, arg, context=None): result={}