From 43e6ae3a0817f6113bf9bedf3451733c4cb0abbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 15 Apr 2012 00:08:15 +0200 Subject: [PATCH] Don't use write in migration to add company write could generate error if some _constraint need some new field not yet created. issue2429 (transplanted from 1499ab8c5a8452fc967774134c6f1aa2c3dd347c) --- shipment.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/shipment.py b/shipment.py index e252150797..d24a423a79 100644 --- a/shipment.py +++ b/shipment.py @@ -9,6 +9,7 @@ from trytond.backend import TableHandler from trytond.pyson import Eval, Not, Equal, If, Or, And, Bool, In, Get from trytond.transaction import Transaction from trytond.pool import Pool +from trytond.tools import reduce_ids STATES = { 'readonly': "state in ('cancel', 'done')", @@ -159,7 +160,12 @@ class ShipmentIn(ModelWorkflow, ModelSQL, ModelView): for company_id, values in itertools.groupby(cursor.fetchall(), operator.itemgetter(1)): shipment_ids = [x[0] for x in values] - self.write(shipment_ids, {'company': company_id}) + for i in range(0, len(shipment_ids), cursor.IN_MAX): + sub_ids = shipment_ids[i:i + cursor.IN_MAX] + red_sql, red_ids = reduce_ids('id', sub_ids) + cursor.execute('UPDATE "' + self._table + '" ' + 'SET company = %s WHERE ' + red_sql, + [company_id] + red_ids) table.not_null_action('company', action='add') # Add index on create_date @@ -520,7 +526,12 @@ class ShipmentInReturn(ModelWorkflow, ModelSQL, ModelView): for company_id, values in itertools.groupby(cursor.fetchall(), operator.itemgetter(1)): shipment_ids = [x[0] for x in values] - self.write(shipment_ids, {'company': company_id}) + for i in range(0, len(shipment_ids), cursor.IN_MAX): + sub_ids = shipment_ids[i:i + cursor.IN_MAX] + red_sql, red_ids = reduce_ids('id', sub_ids) + cursor.execute('UPDATE "' + self._table + '" ' + 'SET company = %s WHERE ' + red_sql, + [company_id] + red_ids) table.not_null_action('company', action='add') # Add index on create_date @@ -797,7 +808,12 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView): for company_id, values in itertools.groupby(cursor.fetchall(), operator.itemgetter(1)): shipment_ids = [x[0] for x in values] - self.write(shipment_ids, {'company': company_id}) + for i in range(0, len(shipment_ids), cursor.IN_MAX): + sub_ids = shipment_ids[i:i + cursor.IN_MAX] + red_sql, red_ids = reduce_ids('id', sub_ids) + cursor.execute('UPDATE "' + self._table + '" ' + 'SET company = %s WHERE ' + red_sql, + [company_id] + red_ids) table.not_null_action('company', action='add') # Migration from 1.0 customer_location is no more used @@ -1286,7 +1302,12 @@ class ShipmentOutReturn(ModelWorkflow, ModelSQL, ModelView): for company_id, values in itertools.groupby(cursor.fetchall(), operator.itemgetter(1)): shipment_ids = [x[0] for x in values] - self.write(shipment_ids, {'company': company_id}) + for i in range(0, len(shipment_ids), cursor.IN_MAX): + sub_ids = shipment_ids[i:i + cursor.IN_MAX] + red_sql, red_ids = reduce_ids('id', sub_ids) + cursor.execute('UPDATE "' + self._table + '" ' + 'SET company = %s WHERE ' + red_sql, + [company_id] + red_ids) table.not_null_action('company', action='add') # Add index on create_date @@ -1742,7 +1763,12 @@ class ShipmentInternal(ModelWorkflow, ModelSQL, ModelView): for company_id, values in itertools.groupby(cursor.fetchall(), operator.itemgetter(1)): shipment_ids = [x[0] for x in values] - self.write(shipment_ids, {'company': company_id}) + for i in range(0, len(shipment_ids), cursor.IN_MAX): + sub_ids = shipment_ids[i:i + cursor.IN_MAX] + red_sql, red_ids = reduce_ids('id', sub_ids) + cursor.execute('UPDATE "' + self._table + '" ' + 'SET company = %s WHERE ' + red_sql, + [company_id] + red_ids) table.not_null_action('company', action='add') # Add index on create_date