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.

46 lines
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Savoir-faire Linux
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import logging
  5. _logger = logging.getLogger(__name__)
  6. def migrate(cr, version):
  7. if not version:
  8. return
  9. _logger.info('Updating column last_rec_date on account_move_line')
  10. cr.execute(
  11. """
  12. UPDATE account_move_line SET last_rec_date = rec_data.aml_date
  13. FROM (
  14. SELECT rec.id, max(greatest(aml.date,ap.date_start)) as aml_date
  15. FROM account_move_line aml
  16. JOIN account_period ap ON aml.period_id=ap.id
  17. JOIN account_move_reconcile rec
  18. ON rec.id = aml.reconcile_id
  19. GROUP BY rec.id
  20. ) as rec_data
  21. WHERE rec_data.id = account_move_line.reconcile_id
  22. AND account_move_line.reconcile_id IS NOT NULL
  23. """
  24. )
  25. cr.execute(
  26. """
  27. UPDATE account_move_line SET last_rec_date = rec_data.aml_date
  28. FROM (
  29. SELECT rec.id, max(greatest(aml.date,ap.date_start)) as aml_date
  30. FROM account_move_line aml
  31. JOIN account_period ap ON aml.period_id=ap.id
  32. JOIN account_move_reconcile rec
  33. ON rec.id = aml.reconcile_partial_id
  34. GROUP BY rec.id
  35. ) as rec_data
  36. WHERE rec_data.id = account_move_line.reconcile_partial_id
  37. AND account_move_line.reconcile_partial_id IS NOT NULL
  38. """
  39. )