diff --git a/addons/mrp/__init__.py b/addons/mrp/__init__.py index 07f99e38042..01c44c4b198 100644 --- a/addons/mrp/__init__.py +++ b/addons/mrp/__init__.py @@ -8,6 +8,16 @@ from . import controller from odoo import api, SUPERUSER_ID + +def _pre_init_mrp(cr): + """ Allow installing MRP in databases with large stock.move table (>1M records) + - Creating the computed+stored field stock_move.is_done is terribly slow with the ORM and + leads to "Out of Memory" crashes + """ + cr.execute("""ALTER TABLE "stock_move" ADD COLUMN "is_done" bool;""") + cr.execute("""UPDATE stock_move + SET is_done=COALESCE(state in ('done', 'cancel'), FALSE);""") + def _create_warehouse_data(cr, registry): """ This hook is used to add a default manufacture_pull_id, manufacture picking_type on every warehouse. It is necessary if the mrp module is diff --git a/addons/mrp/__manifest__.py b/addons/mrp/__manifest__.py index fc38329c1be..2be559a112e 100644 --- a/addons/mrp/__manifest__.py +++ b/addons/mrp/__manifest__.py @@ -52,6 +52,7 @@ ], 'test': [], 'application': True, + 'pre_init_hook': '_pre_init_mrp', 'post_init_hook': '_create_warehouse_data', 'uninstall_hook': 'uninstall_hook', }