Browse Source

[IMP] precompute last_rec_date

[ADD] index last_rec_date
pull/352/head
Holger Brunn 7 years ago
parent
commit
daa1783dc5
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 2
      account_financial_report_webkit/__init__.py
  2. 1
      account_financial_report_webkit/__openerp__.py
  3. 35
      account_financial_report_webkit/hooks.py
  4. 1
      account_financial_report_webkit/models/account_move_line.py

2
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

1
account_financial_report_webkit/__openerp__.py

@ -60,4 +60,5 @@
'active': False,
'installable': True,
'application': True,
'pre_init_hook': 'pre_init_hook',
}

35
account_financial_report_webkit/hooks.py

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# 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"""
)

1
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."

Loading…
Cancel
Save