From a90ccb386ac63bd04f23d3e26c181c6f53da2b8a Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Fri, 2 Jun 2023 18:59:32 +0200 Subject: [PATCH] Migrate supply_on_sale in history table if activated Closes #12255 --- modules/sale_supply/product.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/sale_supply/product.py b/modules/sale_supply/product.py index db493b8aa2..b1362ac2b2 100644 --- a/modules/sale_supply/product.py +++ b/modules/sale_supply/product.py @@ -33,6 +33,15 @@ class Template(metaclass=PoolMeta): 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') + 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) @@ -43,6 +52,12 @@ class Template(metaclass=PoolMeta): ['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):