From dc7136b5657526e87a07434b8420199233ecc4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 3 Jul 2011 13:18:47 +0200 Subject: [PATCH] Change Pool into a Singleton --- account.py | 21 +++++++++++---------- line.py | 11 ++++++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/account.py b/account.py index fd7be9c8b1..1d3ff2dba2 100644 --- a/account.py +++ b/account.py @@ -6,6 +6,7 @@ from trytond.model import ModelView, ModelSQL, fields from trytond.wizard import Wizard from trytond.pyson import Equal, Eval, Not, PYSONEncoder from trytond.transaction import Transaction +from trytond.pool import Pool class Account(ModelSQL, ModelView): @@ -78,8 +79,8 @@ class Account(ModelSQL, ModelView): return Transaction().context.get('company') or False def default_currency(self): - company_obj = self.pool.get('company.company') - currency_obj = self.pool.get('currency.currency') + company_obj = Pool().get('company.company') + currency_obj = Pool().get('currency.currency') if Transaction().context.get('company'): company = company_obj.browse(Transaction().context['company']) return company.currency.id @@ -98,7 +99,7 @@ class Account(ModelSQL, ModelView): return False def on_change_with_currency_digits(self, vals): - currency_obj = self.pool.get('currency.currency') + currency_obj = Pool().get('currency.currency') if vals.get('currency'): currency = currency_obj.browse(vals['currency']) return currency.digits @@ -112,8 +113,8 @@ class Account(ModelSQL, ModelView): def get_balance(self, ids, name): res = {} - line_obj = self.pool.get('analytic_account.line') - currency_obj = self.pool.get('currency.currency') + line_obj = Pool().get('analytic_account.line') + currency_obj = Pool().get('currency.currency') cursor = Transaction().cursor child_ids = self.search([('parent', 'child_of', ids)]) @@ -178,8 +179,8 @@ class Account(ModelSQL, ModelView): def get_credit_debit(self, ids, name): res = {} - line_obj = self.pool.get('analytic_account.line') - currency_obj = self.pool.get('currency.currency') + line_obj = Pool().get('analytic_account.line') + currency_obj = Pool().get('currency.currency') cursor = Transaction().cursor if name not in ('credit', 'debit'): @@ -326,8 +327,8 @@ class OpenChartAccount(Wizard): } def _action_open_chart(self, data): - model_data_obj = self.pool.get('ir.model.data') - act_window_obj = self.pool.get('ir.action.act_window') + model_data_obj = Pool().get('ir.model.data') + act_window_obj = Pool().get('ir.action.act_window') act_window_id = model_data_obj.get_id('analytic_account', 'act_account_tree2') res = act_window_obj.read(act_window_id) @@ -362,7 +363,7 @@ class AccountSelection(ModelSQL, ModelView): def check_root(self, ids): "Check Root" - account_obj = self.pool.get('analytic_account.account') + account_obj = Pool().get('analytic_account.account') root_account_ids = account_obj.search([ ('parent', '=', False), diff --git a/line.py b/line.py index b01478f8e2..2b0b5faa0f 100644 --- a/line.py +++ b/line.py @@ -6,6 +6,7 @@ from trytond.wizard import Wizard from trytond.backend import TableHandler from trytond.pyson import Eval, PYSONEncoder from trytond.transaction import Transaction +from trytond.pool import Pool class Line(ModelSQL, ModelView): @@ -58,14 +59,14 @@ class Line(ModelSQL, ModelView): table.not_null_action('currency', action='remove') def default_date(self): - date_obj = self.pool.get('ir.date') + date_obj = Pool().get('ir.date') return date_obj.today() def default_active(self): return True def on_change_with_currency(self, vals): - move_line_obj = self.pool.get('account.move.line') + move_line_obj = Pool().get('account.move.line') if vals.get('move_line'): move_line = move_line_obj.browse(vals['move_line']) return move_line.account.company.currency.id @@ -78,7 +79,7 @@ class Line(ModelSQL, ModelView): return res def on_change_with_currency_digits(self, vals): - move_line_obj = self.pool.get('account.move.line') + move_line_obj = Pool().get('account.move.line') if vals.get('move_line'): move_line = move_line_obj.browse(vals['move_line']) return move_line.account.company.currency.digits @@ -141,8 +142,8 @@ class OpenAccount(Wizard): } def _action_open_account(self, data): - model_data_obj = self.pool.get('ir.model.data') - act_window_obj = self.pool.get('ir.action.act_window') + model_data_obj = Pool().get('ir.model.data') + act_window_obj = Pool().get('ir.action.act_window') act_window_id = model_data_obj.get_id('analytic_account', 'act_line_form')