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.

33 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import sqlparse
  5. from psycopg2.extensions import AsIs
  6. from openerp import fields, models
  7. class AccountEntriesReport(models.Model):
  8. _inherit = 'account.entries.report'
  9. analytics_id = fields.Many2one('account.analytic.plan.instance',
  10. 'Analytic Distribution')
  11. def init(self, cr):
  12. """Here, we try to be less invasive than the usual blunt overwrite of
  13. the sql view"""
  14. super(AccountEntriesReport, self).init(cr)
  15. cr.execute("select pg_get_viewdef(%s::regclass)", (self._table,))
  16. for statement in sqlparse.parse(cr.fetchone()[0]):
  17. current_keyword = None
  18. for token in statement:
  19. if token.is_keyword:
  20. current_keyword = token
  21. if isinstance(token, sqlparse.sql.IdentifierList) and\
  22. current_keyword.value == 'SELECT':
  23. last = None
  24. for last in token:
  25. pass
  26. token.insert_after(last, sqlparse.sql.Token(
  27. sqlparse.tokens.Generic, ',l.analytics_id'))
  28. cr.execute("create or replace view %s as (%s)",
  29. (AsIs(self._table), AsIs(str(statement)[:-1])))