Skip to content
Snippets Groups Projects
Commit 1ca5968d authored by Ivan Yelizariev's avatar Ivan Yelizariev
Browse files

[FIX] l10n_pe: create related field directly to speed it up

Odoo ORM has special optimization for installing module with a stored related
fields, but it requires the final field be not computed [1] (I'm not sure why),
which is not the case for the `group_id` field. Since `account.move.line` table
may have millions of records, we have to optimize the installation and fill
`l10n_pe_group_id` via a single sql query.

[1]: https://github.com/odoo/odoo/blob/0aff8bb9484a23c0d875d3b12259dd4e0d51e716/odoo/fields.py#L818



opw-2762510

closes odoo/odoo#107154

X-original-commit: 63341b58
Signed-off-by: default avatarRaphael Collet <rco@odoo.com>
Signed-off-by: default avatarIvan Elizaryev (iel) <iel@odoo.com>
parent b7b8809e
No related branches found
No related tags found
No related merge requests found
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields
from odoo.tools.sql import column_exists, create_column
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
l10n_pe_group_id = fields.Many2one("account.group", related="account_id.group_id", store=True)
def _auto_init(self):
"""
Create column to stop ORM from computing it himself (too slow)
"""
if not column_exists(self.env.cr, self._table, 'l10n_pe_group_id'):
create_column(self.env.cr, self._table, 'l10n_pe_group_id', 'int4')
self.env.cr.execute("""
UPDATE account_move_line line
SET l10n_pe_group_id = account.group_id
FROM account_account account
WHERE account.id = line.account_id
""")
return super()._auto_init()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment