From 41d599b492d70feb5986cccc664d6121fe7ea79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 6 Sep 2013 22:34:56 +0200 Subject: [PATCH] Migration to python-sql review1001002 --- INSTALL | 1 + order_point.py | 3 ++- purchase_request.py | 8 +++++--- setup.py | 2 +- shipment.py | 27 +++++++++++++++++++-------- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/INSTALL b/INSTALL index dea2748149..cf3c35d062 100644 --- a/INSTALL +++ b/INSTALL @@ -5,6 +5,7 @@ Prerequisites ------------- * Python 2.6 or later (http://www.python.org/) + * python-sql (http://code.google.com/p/python-sql/) * trytond (http://www.tryton.org/) * trytond_party (http://www.tryton.org/) * trytond_product (http://www.tryton.org/) diff --git a/order_point.py b/order_point.py index 75ff205038..917ddc2f92 100644 --- a/order_point.py +++ b/order_point.py @@ -3,7 +3,7 @@ from trytond.model import ModelView, ModelSQL, fields from trytond.pyson import If, Equal, Eval, Not, In, Get from trytond.transaction import Transaction -from trytond.backend import TableHandler +from trytond import backend __all__ = ['OrderPoint'] @@ -87,6 +87,7 @@ class OrderPoint(ModelSQL, ModelView): @classmethod def __register__(cls, module_name): + TableHandler = backend.get('TableHandler') cursor = Transaction().cursor # Migration from 2.2 table = TableHandler(cursor, cls, module_name) diff --git a/purchase_request.py b/purchase_request.py index c00615966b..3788440068 100644 --- a/purchase_request.py +++ b/purchase_request.py @@ -84,12 +84,14 @@ class PurchaseRequest(ModelSQL, ModelView): @classmethod def __register__(cls, module_name): cursor = Transaction().cursor + sql_table = cls.__table__() super(PurchaseRequest, cls).__register__(module_name) # Migration from 2.0: empty order point origin is -1 instead of 0 - cursor.execute('UPDATE "%s" ' - 'SET origin = %%s WHERE origin = %%s' % cls._table, - ('stock.order_point,-1', 'stock.order_point,0')) + cursor.execute(*sql_table.update( + columns=[sql_table.origin], + values=['stock.order_point,-1'], + where=sql_table.origin == 'stock.order_point,0')) def get_rec_name(self, name): if self.warehouse: diff --git a/setup.py b/setup.py index 014db6cb75..8b18241d19 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ major_version, minor_version, _ = info.get('version', '0.0.1').split('.', 2) major_version = int(major_version) minor_version = int(minor_version) -requires = [] +requires = ['python-sql'] for dep in info.get('depends', []): if not re.match(r'(ir|res|webdav)(\W|$)', dep): requires.append('trytond_%s >= %s.%s, < %s.%s' % diff --git a/shipment.py b/shipment.py index 3d048e5920..f1cfff73c4 100644 --- a/shipment.py +++ b/shipment.py @@ -1,5 +1,8 @@ #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 sql import Table +from sql.functions import Overlay, Position + from trytond.model import ModelView, ModelSQL from trytond.wizard import Wizard, StateView, StateAction, Button from trytond.transaction import Transaction @@ -16,15 +19,23 @@ class ShipmentInternal(ModelSQL, ModelView): @classmethod def __register__(cls, module_name): cursor = Transaction().cursor + model_data = Table('ir_model_data') + model = Table('ir_model') # Migration from 1.2: packing renamed into shipment - cursor.execute("UPDATE ir_model_data " - "SET fs_id = REPLACE(fs_id, 'packing', 'shipment') " - "WHERE fs_id like '%%packing%%' AND module = %s", - (module_name,)) - cursor.execute("UPDATE ir_model " - "SET model = REPLACE(model, 'packing', 'shipment') " - "WHERE model like '%%packing%%' AND module = %s", - (module_name,)) + cursor.execute(*model_data.update( + columns=[model_data.fs_id], + values=[Overlay(model_data.fs_id, 'shipment', + Position('packing', model_data.fs_id), + len('packing'))], + where=model_data.fs_id.like('%packing%') + & (model_data.module == module_name))) + cursor.execute(*model.update( + columns=[model.model], + values=[Overlay(model.model, 'shipment', + Position('packing', model.model), + len('packing'))], + where=model.model.like('%packing%') + & (model.module == module_name))) super(ShipmentInternal, cls).__register__(module_name) @classmethod