From 60a7abac56bf738747cb738648aea55e5343fea6 Mon Sep 17 00:00:00 2001 From: "Danny W. Adair" Date: Thu, 23 Feb 2023 12:51:39 +1300 Subject: [PATCH] Add pre_init_hook to add computed column Add partner_bank_id column to avoid MemoryError on an existing Odoo instance with lots of data. partner_bank_id on account.move.line requires payment_order_ok to be True which it won't be as it's newly introduced - again nothing to compute. (see AccountMoveLine._compute_partner_bank_id() in models/account_move_line.py) --- account_payment_order/__init__.py | 1 + account_payment_order/__manifest__.py | 3 ++- account_payment_order/hooks.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 account_payment_order/hooks.py diff --git a/account_payment_order/__init__.py b/account_payment_order/__init__.py index 7660e7bf6..cb033efa6 100644 --- a/account_payment_order/__init__.py +++ b/account_payment_order/__init__.py @@ -1,3 +1,4 @@ +from .hooks import pre_init_hook from . import models from . import report from . import wizard diff --git a/account_payment_order/__manifest__.py b/account_payment_order/__manifest__.py index c1a6756dc..50655c409 100644 --- a/account_payment_order/__manifest__.py +++ b/account_payment_order/__manifest__.py @@ -9,7 +9,7 @@ { "name": "Account Payment Order", - "version": "15.0.1.1.1", + "version": "15.0.1.1.2", "license": "AGPL-3", "author": "ACSONE SA/NV, " "Therp BV, " @@ -40,4 +40,5 @@ ], "demo": ["demo/payment_demo.xml"], "installable": True, + "pre_init_hook": "pre_init_hook", } diff --git a/account_payment_order/hooks.py b/account_payment_order/hooks.py new file mode 100644 index 000000000..9db88f54f --- /dev/null +++ b/account_payment_order/hooks.py @@ -0,0 +1,16 @@ +from odoo.tools import sql + + +def pre_init_hook(cr): + """Prepare new partner_bank_id computed field. + + Add column to avoid MemoryError on an existing Odoo instance + with lots of data. + + partner_bank_id on account.move.line requires payment_order_ok to be True + which it won't be as it's newly introduced - nothing to compute. + (see AccountMoveLine._compute_partner_bank_id() in models/account_move_line.py + and AccountMove._compute_payment_order_ok() in models/account_move.py) + """ + if not sql.column_exists(cr, "account_move_line", "partner_bank_id"): + sql.create_column(cr, "account_move_line", "partner_bank_id", "int4")