From 5f5a799ac6abeca174025317fb6f4e8b8c002be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 3 Jul 2011 13:19:07 +0200 Subject: [PATCH] Change Pool into a Singleton --- allocation.py | 7 ++++--- work.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/allocation.py b/allocation.py index fd4d5b27ad..c4910b0bd6 100644 --- a/allocation.py +++ b/allocation.py @@ -1,6 +1,7 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields +from trytond.pool import Pool class Allocation(ModelSQL, ModelView): @@ -19,7 +20,7 @@ class Allocation(ModelSQL, ModelView): return 100 def write(self, ids, values): - work_obj = self.pool.get('project.work') + work_obj = Pool().get('project.work') res = super(Allocation, self).write(ids, values) if isinstance(ids, (int, long)): @@ -36,14 +37,14 @@ class Allocation(ModelSQL, ModelView): return res def create(self, values): - work_obj = self.pool.get('project.work') + work_obj = Pool().get('project.work') allocation_id = super(Allocation, self).create(values) allocation = self.browse(allocation_id) work_obj.reset_leveling(allocation.work.id) work_obj.compute_dates(allocation.work.id) def delete(self, ids): - work_obj = self.pool.get('project.work') + work_obj = Pool().get('project.work') allocations = self.browse(ids) work_ids = [a.work.id for a in allocations] res = super(Allocation, self).delete(ids) diff --git a/work.py b/work.py index c0f8b8e5ed..f67eb90b01 100644 --- a/work.py +++ b/work.py @@ -7,6 +7,7 @@ from trytond.model import ModelView, ModelSQL, fields from trytond.wizard import Wizard from trytond.pyson import Eval, Not, Equal from trytond.transaction import Transaction +from trytond.pool import Pool def intfloor(x): @@ -86,7 +87,7 @@ class Work(ModelSQL, ModelView): :return: a dictionary with all field names as key and a dictionary as value with id as key ''' - req_ref_obj = self.pool.get('res.request.reference') + req_ref_obj = Pool().get('res.request.reference') cursor = Transaction().cursor @@ -171,8 +172,8 @@ class Work(ModelSQL, ModelView): return res def set_function_fields(self, ids, name, value): - request_obj = self.pool.get('res.request') - req_ref_obj = self.pool.get('res.request.reference') + request_obj = Pool().get('res.request') + req_ref_obj = Pool().get('res.request.reference') if name == 'requests': works = self.browse(ids) @@ -654,7 +655,7 @@ class PredecessorSuccessor(ModelSQL): ondelete='CASCADE', required=True, select=1) def write(self, ids, values): - work_obj = self.pool.get('project.work') + work_obj = Pool().get('project.work') res = super(PredecessorSuccessor, self).write(ids, values) for work_id in values.itervalues(): @@ -664,7 +665,7 @@ class PredecessorSuccessor(ModelSQL): return res def delete(self, ids): - work_obj = self.pool.get('project.work') + work_obj = Pool().get('project.work') if isinstance(ids, (int, long)): ids = [ids] @@ -689,7 +690,7 @@ class PredecessorSuccessor(ModelSQL): return res def create(self, values): - work_obj = self.pool.get('project.work') + work_obj = Pool().get('project.work') ps_id = super(PredecessorSuccessor, self).create(values) pred_succ = self.browse(ps_id) @@ -718,7 +719,7 @@ class Leveling(Wizard): } def _leveling(self, data): - work_obj = self.pool.get('project.work') + work_obj = Pool().get('project.work') work_obj.create_leveling(data['id']) return {}