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)
This commit is contained in:
1 parent
502b0c3a1f
commit
43e6ae3a08
1 file changed
+31
-5
+31
-5
@@ -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
|
||||
|
||||
Reference in new issue
Block a user