[IMP] odoo: remove LazyCursor
Was specifically created for decimal.precision at f0646cb51b
Should no longer be needed
This commit is contained in:
@@ -1814,18 +1814,9 @@ class TestSinglePicking(TestStockCommon):
|
||||
class TestStockUOM(TestStockCommon):
|
||||
def setUp(self):
|
||||
super(TestStockUOM, self).setUp()
|
||||
self.setUpCache()
|
||||
|
||||
def setUpCache(self):
|
||||
dp = self.env.ref('product.decimal_product_uom')
|
||||
dp.digits = 7
|
||||
|
||||
# Trick: invoke the method 'precision_get' with the current environment.
|
||||
# This fills in the cache of the method with the right value. If we
|
||||
# don't do that, the registry will access the corresponding precision
|
||||
# with a new cursor (LazyCursor), and get a different value!
|
||||
self.assertEqual(dp.precision_get(dp.name), 7)
|
||||
|
||||
def test_pickings_transfer_with_different_uom_and_back_orders(self):
|
||||
""" Picking transfer with diffrent unit of meassure. """
|
||||
# weight category
|
||||
@@ -1852,9 +1843,6 @@ class TestStockUOM(TestStockCommon):
|
||||
'tracking': 'lot',
|
||||
})
|
||||
|
||||
# creating a variant invalidates the cache
|
||||
self.setUpCache()
|
||||
|
||||
picking_in = self.env['stock.picking'].create({
|
||||
'partner_id': self.partner_delta_id,
|
||||
'picking_type_id': self.picking_type_in,
|
||||
|
||||
@@ -22,7 +22,6 @@ except ImportError:
|
||||
|
||||
import psycopg2
|
||||
|
||||
from .sql_db import LazyCursor
|
||||
from .tools import float_repr, float_round, frozendict, html_sanitize, human_size, pg_varchar, \
|
||||
ustr, OrderedSet, pycompat, sql, date_utils, unique, IterableGenerator
|
||||
from .tools import DEFAULT_SERVER_DATE_FORMAT as DATE_FORMAT
|
||||
|
||||
@@ -483,40 +483,6 @@ class TestCursor(object):
|
||||
return value
|
||||
|
||||
|
||||
class LazyCursor(object):
|
||||
""" A proxy object to a cursor. The cursor itself is allocated only if it is
|
||||
needed. This class is useful for cached methods, that use the cursor
|
||||
only in the case of a cache miss.
|
||||
"""
|
||||
def __init__(self, dbname=None):
|
||||
self._dbname = dbname
|
||||
self._cursor = None
|
||||
self._depth = 0
|
||||
|
||||
@property
|
||||
def dbname(self):
|
||||
return self._dbname or threading.currentThread().dbname
|
||||
|
||||
def __getattr__(self, name):
|
||||
cr = self._cursor
|
||||
if cr is None:
|
||||
from odoo import registry
|
||||
cr = self._cursor = registry(self.dbname).cursor()
|
||||
for _ in range(self._depth):
|
||||
cr.__enter__()
|
||||
return getattr(cr, name)
|
||||
|
||||
def __enter__(self):
|
||||
self._depth += 1
|
||||
if self._cursor is not None:
|
||||
self._cursor.__enter__()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self._depth -= 1
|
||||
if self._cursor is not None:
|
||||
self._cursor.__exit__(exc_type, exc_value, traceback)
|
||||
|
||||
class PsycoConnection(psycopg2.extensions.connection):
|
||||
pass
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class _LogTracer(object):
|
||||
|
||||
in_self = frame.f_locals['self']
|
||||
|
||||
if isinstance(in_self, (odoo.sql_db.Cursor, odoo.sql_db.TestCursor, odoo.sql_db.LazyCursor)):
|
||||
if isinstance(in_self, (odoo.sql_db.Cursor, odoo.sql_db.TestCursor)):
|
||||
return self.tracer
|
||||
|
||||
model = getattr(in_self, '_name', None)
|
||||
|
||||
Reference in New Issue
Block a user