From daa1783dc5ff40351ba2c97be64f59cf34b41bb2 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 28 Sep 2017 14:59:32 +0200 Subject: [PATCH] [IMP] precompute last_rec_date [ADD] index last_rec_date --- account_financial_report_webkit/__init__.py | 2 ++ .../__openerp__.py | 1 + account_financial_report_webkit/hooks.py | 35 +++++++++++++++++++ .../models/account_move_line.py | 1 + 4 files changed, 39 insertions(+) create mode 100644 account_financial_report_webkit/hooks.py diff --git a/account_financial_report_webkit/__init__.py b/account_financial_report_webkit/__init__.py index 1eeb7fc5..bf51e89d 100644 --- a/account_financial_report_webkit/__init__.py +++ b/account_financial_report_webkit/__init__.py @@ -21,3 +21,5 @@ from . import models from . import wizard from . import report +from . import hooks +from .hooks import pre_init_hook diff --git a/account_financial_report_webkit/__openerp__.py b/account_financial_report_webkit/__openerp__.py index b0776563..98c42008 100644 --- a/account_financial_report_webkit/__openerp__.py +++ b/account_financial_report_webkit/__openerp__.py @@ -60,4 +60,5 @@ 'active': False, 'installable': True, 'application': True, + 'pre_init_hook': 'pre_init_hook', } diff --git a/account_financial_report_webkit/hooks.py b/account_financial_report_webkit/hooks.py new file mode 100644 index 00000000..18081b6c --- /dev/null +++ b/account_financial_report_webkit/hooks.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from .models.account_move_line import AccountMoveLine + + +def pre_init_hook(cr): + with cr.savepoint(): + # don't break if column exists + cr.execute( + 'alter table account_move_line add column last_rec_date date', + ) + cr.execute( + 'comment on column account_move_line.last_rec_date is %s', + (AccountMoveLine.last_rec_date.string,), + ) + cr.execute( + 'create index account_move_line_last_rec_date_index ' + 'on account_move_line (last_rec_date)', + ) + # but still do the initialization + cr.execute( + """update account_move_line + set last_rec_date=ml_fr.date + from account_move_line ml + left join account_move_reconcile fr on ml.reconcile_id=fr.id + join ( + select + coalesce(reconcile_id, reconcile_partial_id) as reconcile_id, + max(date) as date + from account_move_line + group by coalesce(reconcile_id, reconcile_partial_id) + ) ml_fr on ml_fr.reconcile_id=fr.id + where ml.id=account_move_line.id""" + ) diff --git a/account_financial_report_webkit/models/account_move_line.py b/account_financial_report_webkit/models/account_move_line.py index e95618c0..9a3a6cc7 100644 --- a/account_financial_report_webkit/models/account_move_line.py +++ b/account_financial_report_webkit/models/account_move_line.py @@ -18,6 +18,7 @@ class AccountMoveLine(models.Model): last_rec_date = fields.Date( compute='_compute_last_rec_date', store=True, + index=True, string='Last reconciliation date', help="The date of the last reconciliation (full or partial) " "account move line."