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.

54 lines
2.1 KiB

9 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2015 Therp BV <http://therp.nl>
  3. from openerp import models, api
  4. class AccountFinancialReport(models.Model):
  5. _inherit = 'account.financial.report'
  6. @api.multi
  7. def _has_exclusively_report_types(self, report_types):
  8. self.ensure_one()
  9. if self.type == 'accounts':
  10. for account in self.account_ids:
  11. if account.user_type_id.type not in report_types:
  12. return False
  13. elif self.type == 'account_type':
  14. for account_type in self.account_type_ids:
  15. if account_type.type not in report_types:
  16. return False
  17. elif self.type == 'account_report':
  18. # this will have mixed types usually, we rely upon this being
  19. # filtered out by siblings of this report
  20. return True
  21. return all(
  22. r._has_exclusively_report_types(report_types)
  23. for r in self.children_ids)
  24. @api.multi
  25. def _get_children_by_order(self):
  26. reports = super(AccountFinancialReport, self)._get_children_by_order()
  27. if self.env.context.get('account_financial_report_horizontal_side'):
  28. side = self.env.context['account_financial_report_horizontal_side']
  29. report_types = {
  30. 'left': ['receivable', 'liquidity', 'other'],
  31. 'right': ['payable', 'other']
  32. }[side]
  33. last_good_report = self.browse([])
  34. last_bad_report = self.browse([])
  35. result = self.browse([])
  36. for report in reports:
  37. if not report.parent_id:
  38. result += report
  39. # don't check children if we already checked the parent
  40. elif report.parent_id == last_bad_report:
  41. continue
  42. elif report.parent_id == last_good_report\
  43. or report._has_exclusively_report_types(report_types):
  44. last_good_report = report
  45. result += report
  46. else:
  47. last_bad_report = report
  48. return result
  49. else:
  50. return reports