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.

71 lines
3.0 KiB

9 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2015 Therp BV (<http://therp.nl>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (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 Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import models, api
  22. class AccountFinancialReport(models.Model):
  23. _inherit = 'account.financial.report'
  24. @api.multi
  25. def _has_exclusively_report_types(self, report_types):
  26. self.ensure_one()
  27. if self.type == 'accounts':
  28. for account in self.account_ids:
  29. if account.user_type.report_type not in report_types:
  30. return False
  31. elif self.type == 'account_type':
  32. for account_type in self.account_type_ids:
  33. if account_type.report_type not in report_types:
  34. return False
  35. elif self.type == 'account_report':
  36. # this will have mixed types usually, we rely upon this being
  37. # filtered out by siblings of this report
  38. return True
  39. return all(
  40. r._has_exclusively_report_types(report_types)
  41. for r in self.children_ids)
  42. @api.multi
  43. def _get_children_by_order(self):
  44. reports = super(AccountFinancialReport, self)._get_children_by_order()
  45. if self.env.context.get('account_financial_report_horizontal_side'):
  46. side = self.env.context['account_financial_report_horizontal_side']
  47. report_types = {
  48. 'left': ['income', 'asset', 'none'],
  49. 'right': ['expense', 'liability', 'none']
  50. }[side]
  51. last_good_report = None
  52. last_bad_report = None
  53. for report in self.browse(reports):
  54. if not report.parent_id:
  55. yield report.id
  56. # don't check children if we already checked the parent
  57. elif report.parent_id == last_bad_report:
  58. continue
  59. elif report.parent_id == last_good_report\
  60. or report._has_exclusively_report_types(report_types):
  61. last_good_report = report
  62. yield report.id
  63. else:
  64. last_bad_report = report
  65. else:
  66. for report_id in reports:
  67. yield report_id