changeset 6675d0caa210 in modules/account_invoice:default
details: 
https://hg.tryton.org/modules/account_invoice?cmd=changeset&node=6675d0caa210
description:
        Allow column sql types to be tested from the table handler

        issue9645
        review312421002
diffstat:

 payment_term.py |  17 ++++-------------
 1 files changed, 4 insertions(+), 13 deletions(-)

diffs (35 lines):

diff -r b33b6e913b27 -r 6675d0caa210 payment_term.py
--- a/payment_term.py   Sun Apr 11 20:52:21 2021 +0200
+++ b/payment_term.py   Mon Apr 12 20:56:08 2021 +0200
@@ -267,6 +267,7 @@
         line = Line.__table__()
         month = Month.__table__()
         day = Day.__table__()
+        table_h = cls.__table_handler__(module_name)
 
         # Migration from 4.0: rename long table
         old_model_name = 'account.invoice.payment_term.line.relativedelta'
@@ -278,20 +279,10 @@
         # Migration from 5.0: use ir.calendar
         migrate_calendar = False
         if backend.TableHandler.table_exist(cls._table):
-            cursor.execute(*sql_table.select(
-                    sql_table.month, sql_table.weekday,
-                    where=(sql_table.month != Null)
-                    | (sql_table.weekday != Null),
-                    limit=1))
-            try:
-                row, = cursor.fetchall()
-                migrate_calendar = any(isinstance(v, str) for v in row)
-            except ValueError:
-                # As we cannot know the column type
-                # we migrate any way as no data need to be migrated
-                migrate_calendar = True
+            migrate_calendar = (
+                (table_h.column_is_type('month', 'VARCHAR')
+                or (table_h.column_is_type('weekday', 'VARCHAR'))
             if migrate_calendar:
-                table_h = cls.__table_handler__(module_name)
                 table_h.column_rename('month', '_temp_month')
                 table_h.column_rename('weekday', '_temp_weekday')
 

Reply via email to