Follow PEP-0249 for Transaction and backends

issue4949
review19781002
This commit is contained in:
Nicolas Évrard
2016-03-03 21:55:39 +01:00
parent 2e04a068ee
commit 94b0ab55e6
4 changed files with 42 additions and 43 deletions
+3 -4
View File
@@ -76,10 +76,9 @@ class Inventory(Workflow, ModelSQL, ModelView):
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
super(Inventory, cls).__register__(module_name)
cursor = Transaction().cursor
# Add index on create_date
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.index_action('create_date', action='add')
@staticmethod
@@ -279,7 +278,7 @@ class InventoryLine(ModelSQL, ModelView):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
cursor = Transaction().connection.cursor()
pool = Pool()
Move = pool.get('stock.move')
sql_table = cls.__table__()
@@ -287,7 +286,7 @@ class InventoryLine(ModelSQL, ModelView):
super(InventoryLine, cls).__register__(module_name)
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
# Migration from 2.8: Remove constraint inventory_product_uniq
table.drop_constraint('inventory_product_uniq')
+1 -2
View File
@@ -160,9 +160,8 @@ class Location(ModelSQL, ModelView):
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
super(Location, cls).__register__(module_name)
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.index_action(['left', 'right'], 'add')
@classmethod
+8 -7
View File
@@ -311,11 +311,12 @@ class Move(Workflow, ModelSQL, ModelView):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
transaction = Transaction()
cursor = transaction.connection.cursor()
sql_table = cls.__table__()
# Migration from 1.2: packing renamed into shipment
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.drop_constraint('check_packing')
for suffix in ('in', 'out', 'in_return', 'out_return', 'internal'):
old_column = 'packing_%s' % suffix
@@ -333,7 +334,7 @@ class Move(Workflow, ModelSQL, ModelView):
# Migration from 1.8: fill new field internal_quantity
if not internal_quantity_exist:
offset = 0
limit = cursor.IN_MAX
limit = transaction.database.IN_MAX
moves = True
while moves:
moves = cls.search([], offset=offset, limit=limit)
@@ -345,11 +346,11 @@ class Move(Workflow, ModelSQL, ModelView):
columns=[sql_table.internal_quantity],
values=[internal_quantity],
where=sql_table.id == move.id))
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.not_null_action('internal_quantity', action='add')
# Migration from 1.0 check_packing_in_out has been removed
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.drop_constraint('check_packing_in_out')
# Migration from 2.6: merge all shipments
@@ -770,7 +771,7 @@ class Move(Workflow, ModelSQL, ModelView):
Date = pool.get('ir.date')
Location = pool.get('stock.location')
Transaction().cursor.lock(cls._table)
Transaction().database.lock(Transaction().connection, cls._table)
if with_childs:
locations = Location.search([
@@ -1157,7 +1158,7 @@ class Move(Workflow, ModelSQL, ModelView):
"Query in Move.compute_quantities() can't be None")
assert 'product' in grouping
cursor = Transaction().cursor
cursor = Transaction().connection.cursor()
cursor.execute(*query)
raw_lines = cursor.fetchall()
+30 -30
View File
@@ -169,7 +169,7 @@ class ShipmentIn(Workflow, ModelSQL, ModelView):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
cursor = Transaction().connection.cursor()
model_data = Table('ir_model_data')
model = Table('ir_model')
model_field = Table('ir_model_field')
@@ -206,9 +206,9 @@ class ShipmentIn(Workflow, ModelSQL, ModelView):
& (model_field.module == module_name)))
old_table = 'stock_packing_in'
if TableHandler.table_exist(cursor, old_table):
TableHandler.table_rename(cursor, old_table, cls._table)
table = TableHandler(cursor, cls, module_name)
if TableHandler.table_exist(old_table):
TableHandler.table_rename(old_table, cls._table)
table = TableHandler(cls, module_name)
for field in ('create_uid', 'write_uid', 'contact_address',
'warehouse', 'supplier'):
table.drop_fk(field, table=old_table)
@@ -223,7 +223,7 @@ class ShipmentIn(Workflow, ModelSQL, ModelView):
# Migration from 2.0:
Move = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, Move._table)):
and TableHandler.table_exist(Move._table)):
move = Move.__table__()
cursor.execute(*sql_table.join(move,
condition=(Concat(cls.__name__ + ',', sql_table.id)
@@ -243,7 +243,7 @@ class ShipmentIn(Workflow, ModelSQL, ModelView):
table.not_null_action('company', action='add')
# Add index on create_date
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.index_action('create_date', action='add')
@staticmethod
@@ -580,13 +580,13 @@ class ShipmentInReturn(Workflow, ModelSQL, ModelView):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
cursor = Transaction().connection.cursor()
sql_table = cls.__table__()
# Migration from 1.2: packing renamed into shipment
old_table = 'stock_packing_in_return'
if TableHandler.table_exist(cursor, old_table):
TableHandler.table_rename(cursor, old_table, cls._table)
table = TableHandler(cursor, cls, module_name)
if TableHandler.table_exist(old_table):
TableHandler.table_rename(old_table, cls._table)
table = TableHandler(cls, module_name)
for field in ('create_uid', 'write_uid', 'from_location',
'to_location'):
table.drop_fk(field, table=old_table)
@@ -601,7 +601,7 @@ class ShipmentInReturn(Workflow, ModelSQL, ModelView):
# Migration from 2.0:
Move = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, Move._table)):
and TableHandler.table_exist(Move._table)):
move = Move.__table__()
cursor.execute(*sql_table.join(move,
condition=(Concat(cls.__name__ + ',', sql_table.id)
@@ -621,7 +621,7 @@ class ShipmentInReturn(Workflow, ModelSQL, ModelView):
table.not_null_action('company', action='add')
# Add index on create_date
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.index_action('create_date', action='add')
@staticmethod
@@ -904,14 +904,14 @@ class ShipmentOut(Workflow, ModelSQL, ModelView):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
cursor = Transaction().connection.cursor()
sql_table = cls.__table__()
# Migration from 1.2: packing renamed into shipment
old_table = 'stock_packing_out'
if TableHandler.table_exist(cursor, old_table):
TableHandler.table_rename(cursor, old_table, cls._table)
if TableHandler.table_exist(old_table):
TableHandler.table_rename(old_table, cls._table)
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
for field in ('create_uid', 'write_uid', 'delivery_address',
'warehouse', 'customer'):
table.drop_fk(field, table=old_table)
@@ -926,7 +926,7 @@ class ShipmentOut(Workflow, ModelSQL, ModelView):
# Migration from 2.0:
Move = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, Move._table)):
and TableHandler.table_exist(Move._table)):
move = Move.__table__()
cursor.execute(*sql_table.join(move,
condition=(Concat(cls.__name__ + ',', sql_table.id)
@@ -946,7 +946,7 @@ class ShipmentOut(Workflow, ModelSQL, ModelView):
table.not_null_action('company', action='add')
# Migration from 1.0 customer_location is no more used
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.drop_column('customer_location', exception=True)
# Add index on create_date
@@ -1437,14 +1437,14 @@ class ShipmentOutReturn(Workflow, ModelSQL, ModelView):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
cursor = Transaction().connection.cursor()
sql_table = cls.__table__()
# Migration from 1.2: packing renamed into shipment
old_table = 'stock_packing_out_return'
if TableHandler.table_exist(cursor, old_table):
TableHandler.table_rename(cursor, old_table, cls._table)
if TableHandler.table_exist(old_table):
TableHandler.table_rename(old_table, cls._table)
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
for field in ('create_uid', 'write_uid', 'delivery_address',
'warehouse', 'customer'):
table.drop_fk(field, table=old_table)
@@ -1459,7 +1459,7 @@ class ShipmentOutReturn(Workflow, ModelSQL, ModelView):
# Migration from 2.0:
Move = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, Move._table)):
and TableHandler.table_exist(Move._table)):
move = Move.__table__()
cursor.execute(*sql_table.join(move,
condition=(Concat(cls.__name__ + ',', sql_table.id)
@@ -1479,7 +1479,7 @@ class ShipmentOutReturn(Workflow, ModelSQL, ModelView):
table.not_null_action('company', action='add')
# Add index on create_date
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.index_action('create_date', action='add')
@staticmethod
@@ -1871,13 +1871,13 @@ class ShipmentInternal(Workflow, ModelSQL, ModelView):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
cursor = Transaction().connection.cursor()
sql_table = cls.__table__()
# Migration from 1.2: packing renamed into shipment
old_table = 'stock_packing_internal'
if TableHandler.table_exist(cursor, old_table):
TableHandler.table_rename(cursor, old_table, cls._table)
table = TableHandler(cursor, cls, module_name)
if TableHandler.table_exist(old_table):
TableHandler.table_rename(old_table, cls._table)
table = TableHandler(cls, module_name)
for field in ('create_uid', 'write_uid', 'from_location',
'to_location'):
table.drop_fk(field, table=old_table)
@@ -1892,7 +1892,7 @@ class ShipmentInternal(Workflow, ModelSQL, ModelView):
# Migration from 2.0:
Move = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, Move._table)):
and TableHandler.table_exist(Move._table)):
move = Move.__table__()
cursor.execute(*sql_table.join(move,
condition=(Concat(cls.__name__ + ',', sql_table.id)
@@ -1912,7 +1912,7 @@ class ShipmentInternal(Workflow, ModelSQL, ModelView):
table.not_null_action('company', action='add')
# Add index on create_date
table = TableHandler(cursor, cls, module_name)
table = TableHandler(cls, module_name)
table.index_action('create_date', action='add')
@staticmethod