From 94430f3fecf8d2daf705666c39e6d4f56a2d85d7 Mon Sep 17 00:00:00 2001 From: "Danny W. Adair" Date: Thu, 23 Feb 2023 12:45:16 +1300 Subject: [PATCH] Add pre_init_hook to add computed columns Add columns to avoid Memory error on an existing Odoo instance with lots of data. The payment_mode_id fields are introduced by this module and computed only from each other or the also newly introduced supplier_payment_mode_id and customer_payment_mode_id on res.partner, so they can stay NULL, nothing to compute. --- account_payment_partner/__init__.py | 1 + account_payment_partner/__manifest__.py | 1 + account_payment_partner/hooks.py | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 account_payment_partner/hooks.py diff --git a/account_payment_partner/__init__.py b/account_payment_partner/__init__.py index 58da23772..570623a1e 100644 --- a/account_payment_partner/__init__.py +++ b/account_payment_partner/__init__.py @@ -1,4 +1,5 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from .hooks import pre_init_hook from . import models from . import reports diff --git a/account_payment_partner/__manifest__.py b/account_payment_partner/__manifest__.py index 37e20d0ad..a0b383fbb 100644 --- a/account_payment_partner/__manifest__.py +++ b/account_payment_partner/__manifest__.py @@ -24,4 +24,5 @@ ], "demo": ["demo/partner_demo.xml"], "installable": True, + "pre_init_hook": "pre_init_hook", } diff --git a/account_payment_partner/hooks.py b/account_payment_partner/hooks.py new file mode 100644 index 000000000..95b5712e7 --- /dev/null +++ b/account_payment_partner/hooks.py @@ -0,0 +1,20 @@ +import logging + +from odoo.tools import sql + +logger = logging.getLogger(__name__) + + +def pre_init_hook(cr): + """Prepare new payment_mode fields. + Add columns to avoid Memory error on an existing Odoo instance + with lots of data. + The payment_mode_id fields are introduced by this module and computed only + from each other or the also newly introduced supplier_payment_mode_id and + customer_payment_mode_id on res.partner, so they can stay NULL, nothing + to compute. + """ + if not sql.column_exists(cr, "account_move", "payment_mode_id"): + sql.create_column(cr, "account_move", "payment_mode_id", "int4") + if not sql.column_exists(cr, "account_move_line", "payment_mode_id"): + sql.create_column(cr, "account_move_line", "payment_mode_id", "int4")