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.

77 lines
3.2 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Nicolas Bessi.
  5. # Copyright Camptocamp SA 2011
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import fields, orm
  22. class AccountMoveLine(orm.Model):
  23. """Overriding Account move line in order to add last_rec_date.
  24. Last rec date is the date of the last reconciliation (full or partial)
  25. account move line"""
  26. _inherit = 'account.move.line'
  27. def _get_move_line_from_line_rec(self, cr, uid, ids, context=None):
  28. moves = []
  29. for reconcile in self.pool['account.move.reconcile'].browse(
  30. cr, uid, ids, context=context):
  31. for move_line in reconcile.line_partial_ids:
  32. moves.append(move_line.id)
  33. for move_line in reconcile.line_id:
  34. moves.append(move_line.id)
  35. return list(set(moves))
  36. def _get_last_rec_date(self, cursor, uid, ids, name, args, context=None):
  37. if not isinstance(ids, list):
  38. ids = [ids]
  39. res = {}
  40. for line in self.browse(cursor, uid, ids, context):
  41. res[line.id] = {'last_rec_date': False}
  42. rec = line.reconcile_id or line.reconcile_partial_id or False
  43. if rec:
  44. # we use cursor in order to gain some perfs.
  45. # also, important point: LIMIT 1 is not used due to
  46. # performance issues when in conjonction with "OR"
  47. # (one backwards index scan instead of 2 scans and a sort)
  48. cursor.execute('SELECT date from account_move_line'
  49. ' WHERE reconcile_id = %s'
  50. ' OR reconcile_partial_id = %s'
  51. ' ORDER BY date DESC',
  52. (rec.id, rec.id))
  53. res_set = cursor.fetchone()
  54. if res_set:
  55. res[line.id] = {'last_rec_date': res_set[0]}
  56. return res
  57. _columns = {
  58. 'last_rec_date': fields.function(
  59. _get_last_rec_date,
  60. method=True,
  61. string='Last reconciliation date',
  62. store={'account.move.line': (lambda self, cr, uid, ids, c={}: ids,
  63. ['date'], 20),
  64. 'account.move.reconcile': (_get_move_line_from_line_rec,
  65. None, 20)},
  66. type='date',
  67. multi='all',
  68. help="the date of the last reconciliation (full or partial) \
  69. account move line"),
  70. }