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.

74 lines
3.0 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. cursor.execute('SELECT date from account_move_line'
  46. ' WHERE reconcile_id = %s'
  47. ' OR reconcile_partial_id = %s'
  48. ' ORDER BY date DESC LIMIT 1 ',
  49. (rec.id, rec.id))
  50. res_set = cursor.fetchone()
  51. if res_set:
  52. res[line.id] = {'last_rec_date': res_set[0]}
  53. return res
  54. _columns = {
  55. 'last_rec_date': fields.function(
  56. _get_last_rec_date,
  57. method=True,
  58. string='Last reconciliation date',
  59. store={'account.move.line': (lambda self, cr, uid, ids, c={}: ids,
  60. ['date'], 20),
  61. 'account.move.reconcile': (_get_move_line_from_line_rec,
  62. None, 20)},
  63. type='date',
  64. multi='all',
  65. help="the date of the last reconciliation (full or partial) \
  66. account move line"),
  67. }