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