You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2017 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from .models.account_move_line import AccountMoveLine
  5. def pre_init_hook(cr):
  6. with cr.savepoint():
  7. # don't break if column exists
  8. cr.execute(
  9. 'alter table account_move_line add column last_rec_date date',
  10. )
  11. cr.execute(
  12. 'comment on column account_move_line.last_rec_date is %s',
  13. (AccountMoveLine.last_rec_date.string,),
  14. )
  15. cr.execute(
  16. 'create index account_move_line_last_rec_date_index '
  17. 'on account_move_line (last_rec_date)',
  18. )
  19. # but still do the initialization
  20. cr.execute(
  21. """update account_move_line
  22. set last_rec_date=ml_fr.date
  23. from account_move_line ml
  24. left join account_move_reconcile fr on ml.reconcile_id=fr.id
  25. join (
  26. select
  27. coalesce(reconcile_id, reconcile_partial_id) as reconcile_id,
  28. max(date) as date
  29. from account_move_line
  30. group by coalesce(reconcile_id, reconcile_partial_id)
  31. ) ml_fr on ml_fr.reconcile_id=fr.id
  32. where ml.id=account_move_line.id"""
  33. )