Sergi Almacellas Abellana pushed to branch branch/default at Tryton / Tryton


Commits:
081dcfb3 by Sergi Almacellas Abellana at 2023-05-05T09:58:39+02:00
Fix typo in sale supply register method

Closes #12255
- - - - -
5010033b by Cédric Krier at 2023-06-02T18:26:46+02:00
Do not migrate supply on sale column if it does not exist
- - - - -
7f1f0d91 by Sergi Almacellas Abellana at 2023-06-02T18:59:32+02:00
Migrate supply_on_sale in history table if activated

Closes #12255
- - - - -


1 changed file:

- modules/sale_supply/product.py


Changes:

=====================================
modules/sale_supply/product.py
=====================================
@@ -23,8 +23,8 @@
             })
 
     @classmethod
-    def __resgister__(cls, module):
+    def __register__(cls, module):
         table_h = cls.__table_handler__(module)
         table = cls.__table__()
         cursor = Transaction().connection.cursor()
 
@@ -27,8 +27,9 @@
         table_h = cls.__table_handler__(module)
         table = cls.__table__()
         cursor = Transaction().connection.cursor()
 
-        migrate_supply_on_sale = table_h.column_is_type(
-            'supply_on_sale', 'BOOL')
+        migrate_supply_on_sale = (
+            table_h.column_exist('supply_on_sale')
+            and table_h.column_is_type('supply_on_sale', 'BOOL'))
         if migrate_supply_on_sale:
             table_h.column_rename('supply_on_sale', '_temp_supply_on_sale')
@@ -33,5 +34,14 @@
         if migrate_supply_on_sale:
             table_h.column_rename('supply_on_sale', '_temp_supply_on_sale')
+        if cls._history:
+            h_table_h = cls.__table_handler__(module, history=True)
+            h_table = cls.__table__()
+            h_migrate_supply_on_sale = (
+                h_table_h.column_exist('supply_on_sale')
+                and h_table_h.column_is_type('supply_on_sale', 'BOOL'))
+            if h_migrate_supply_on_sale:
+                h_table_h.column_rename(
+                    'supply_on_sale', '_temp_supply_on_sale')
 
         super().__register__(module)
 
@@ -42,6 +52,12 @@
                     ['always'],
                     where=table._temp_supply_on_sale == Literal(True)))
             table_h.drop_column('_temp_supply_on_sale')
+        if cls._history and h_migrate_supply_on_sale:
+            cursor.execute(*h_table.update(
+                    [h_table.supply_on_sale],
+                    ['always'],
+                    where=h_table._temp_supply_on_sale == Literal(True)))
+            h_table_h.drop_column('_temp_supply_on_sale')
 
     @fields.depends(methods=['_notify_order_point'])
     def on_change_notify(self):



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/545eb9851a81e00d311e0191742919e339905452...7f1f0d918bef55c05b53d83df9edfb9cebbaf1c4

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/545eb9851a81e00d311e0191742919e339905452...7f1f0d918bef55c05b53d83df9edfb9cebbaf1c4
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to