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.

63 lines
2.6 KiB

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