From ce4281d316e9c7ae58b24a09ccc964c432f86b88 Mon Sep 17 00:00:00 2001 From: "Danny W. Adair" Date: Fri, 20 Jan 2023 14:45:31 +1300 Subject: [PATCH 1/2] Add pre_init_hook to add computed columns Add columns to avoid MemoryError on an existing Odoo instance with lots of data. payment_order_ok on account.move is computed from payment_order_ok on account.payment.mode which are both introduced by this module, so nothing to compute. (see AccountMove._compute_payment_order_ok() in models/account_move.py) 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 | 1 + account_payment_order/hooks.py | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+) 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 242153019..36b0f5216 100644 --- a/account_payment_order/__manifest__.py +++ b/account_payment_order/__manifest__.py @@ -38,4 +38,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..6800a2975 --- /dev/null +++ b/account_payment_order/hooks.py @@ -0,0 +1,23 @@ +from odoo.tools import sql + + +def pre_init_hook(cr): + """Prepare new computed fields. + + Add columns to avoid MemoryError on an existing Odoo instance + with lots of data. + + payment_order_ok on account.move is computed from payment_order_ok + on account.payment.mode which are both introduced by this module, + so nothing to compute. + (see AccountMove._compute_payment_order_ok() in models/account_move.py) + + 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) + """ + if not sql.column_exists(cr, "account_move", "payment_order_ok"): + sql.create_column(cr, "account_move", "payment_order_ok", "bool") + + if not sql.column_exists(cr, "account_move_line", "partner_bank_id"): + sql.create_column(cr, "account_move_line", "partner_bank_id", "int4") From a6a6231a340446f1416803d9df6e1ce86ab62e59 Mon Sep 17 00:00:00 2001 From: Danny Adair Date: Mon, 23 Jan 2023 16:25:43 +1300 Subject: [PATCH 2/2] Don't create payment_order_ok column (not stored) --- account_payment_order/hooks.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/account_payment_order/hooks.py b/account_payment_order/hooks.py index 6800a2975..9db88f54f 100644 --- a/account_payment_order/hooks.py +++ b/account_payment_order/hooks.py @@ -2,22 +2,15 @@ from odoo.tools import sql def pre_init_hook(cr): - """Prepare new computed fields. + """Prepare new partner_bank_id computed field. - Add columns to avoid MemoryError on an existing Odoo instance + Add column to avoid MemoryError on an existing Odoo instance with lots of data. - payment_order_ok on account.move is computed from payment_order_ok - on account.payment.mode which are both introduced by this module, - so nothing to compute. - (see AccountMove._compute_payment_order_ok() in models/account_move.py) - 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) + 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", "payment_order_ok"): - sql.create_column(cr, "account_move", "payment_order_ok", "bool") - if not sql.column_exists(cr, "account_move_line", "partner_bank_id"): sql.create_column(cr, "account_move_line", "partner_bank_id", "int4")