changeset 84dc1a0ab574 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset&node=84dc1a0ab574
description:
        Replace cursor fetchall by iteration over cursor

        issue5817
        review335831003
diffstat:

 inventory.py              |  8 +++++---
 move.py                   |  3 +--
 stock_reporting_margin.py |  4 ++--
 3 files changed, 8 insertions(+), 7 deletions(-)

diffs (63 lines):

diff -r 01358c0c57d1 -r 84dc1a0ab574 inventory.py
--- a/inventory.py      Sun Mar 21 15:49:07 2021 +0100
+++ b/inventory.py      Sun Mar 21 16:09:13 2021 +0100
@@ -377,7 +377,9 @@
 
     @classmethod
     def __register__(cls, module_name):
-        cursor = Transaction().connection.cursor()
+        transaction = Transaction()
+        cursor = transaction.connection.cursor()
+        update = transaction.connection.cursor()
         pool = Pool()
         Move = pool.get('stock.move')
         sql_table = cls.__table__()
@@ -391,8 +393,8 @@
         if table.column_exist('move'):
             cursor.execute(*sql_table.select(sql_table.id, sql_table.move,
                     where=sql_table.move != Null))
-            for line_id, move_id in cursor.fetchall():
-                cursor.execute(*move_table.update(
+            for line_id, move_id in cursor:
+                update.execute(*move_table.update(
                         columns=[move_table.origin],
                         values=['%s,%s' % (cls.__name__, line_id)],
                         where=move_table.id == move_id))
diff -r 01358c0c57d1 -r 84dc1a0ab574 move.py
--- a/move.py   Sun Mar 21 15:49:07 2021 +0100
+++ b/move.py   Sun Mar 21 16:09:13 2021 +0100
@@ -1502,7 +1502,6 @@
 
         cursor = Transaction().connection.cursor()
         cursor.execute(*query)
-        raw_lines = cursor.fetchall()
 
         if 'product' in grouping:
             id_name = 'product'
@@ -1519,7 +1518,7 @@
         # them directly.
         if len(location_ids) == 1:
             location, = location_ids
-        for line in raw_lines:
+        for line in cursor:
             if len(location_ids) > 1:
                 location = line[0]
             key = tuple(line[1:-1])
diff -r 01358c0c57d1 -r 84dc1a0ab574 stock_reporting_margin.py
--- a/stock_reporting_margin.py Sun Mar 21 15:49:07 2021 +0100
+++ b/stock_reporting_margin.py Sun Mar 21 16:09:13 2021 +0100
@@ -574,12 +574,12 @@
             sub_ids = list(sub_ids)
             where = reduce_ids(table.id, sub_ids)
             cursor.execute(*table.select(table.id, table.parent, where=where))
-            parents.update(cursor.fetchall())
+            parents.update(cursor)
 
             where = reduce_ids(reporting_category.id, sub_ids)
             cursor.execute(
                 *reporting_category.select(reporting_category.id, where=where))
-            reporting_categories.extend(r for r, in cursor.fetchall())
+            reporting_categories.extend(r for r, in cursor)
 
         result = {}
         reporting_categories = ReportingCategory.browse(reporting_categories)

Reply via email to