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.

153 lines
4.8 KiB

6 years ago
  1. # Copyright 2017-2018 Coop IT Easy SCRLfs <remy@gcoopiteasy.be>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from werkzeug.exceptions import Forbidden
  4. from odoo import http
  5. from odoo.exceptions import AccessError, MissingError
  6. from odoo.http import request
  7. from odoo.addons.portal.controllers.portal import (
  8. CustomerPortal,
  9. pager as portal_pager,
  10. )
  11. class PortalTaxShelter(CustomerPortal):
  12. def _prepare_portal_layout_values(self):
  13. values = super()._prepare_portal_layout_values()
  14. partner = request.env.user.partner_id
  15. tax_shelter_count = (
  16. request.env["tax.shelter.certificate"]
  17. .sudo()
  18. .search_count(
  19. [("partner_id", "in", [partner.commercial_partner_id.id])]
  20. )
  21. )
  22. values["tax_shelter_count"] = tax_shelter_count
  23. return values
  24. def _taxshelter_certificate_get_page_view_values(
  25. self, taxshelter_certificate, access_token, **kwargs
  26. ):
  27. values = {
  28. "page_name": "taxshelter",
  29. "taxshelter": taxshelter_certificate,
  30. }
  31. return self._get_page_view_values(
  32. taxshelter_certificate,
  33. access_token,
  34. values,
  35. "my_taxshelter_certificates_history",
  36. False,
  37. **kwargs,
  38. )
  39. @http.route(
  40. [
  41. "/my/tax_shelter_certificates",
  42. "/my/tax_shelter_certificates/page/<int:page>",
  43. ],
  44. type="http",
  45. auth="user",
  46. website=True,
  47. )
  48. def portal_my_tax_shelter_certificates(
  49. self, page=1, date_begin=None, date_end=None, **kw
  50. ):
  51. """Render a page that lits the tax shelter report:
  52. * Tax Shelter Certificates
  53. * Shares Certifcates
  54. """
  55. values = self._prepare_portal_layout_values()
  56. TaxShelterCertificate = request.env["tax.shelter.certificate"]
  57. partner = request.env.user.partner_id
  58. domain = [("partner_id", "in", [partner.commercial_partner_id.id])]
  59. if date_begin and date_end:
  60. domain += [
  61. ("create_date", ">=", date_begin),
  62. ("create_date", "<", date_end),
  63. ]
  64. # count for pager
  65. tax_shelter_count = TaxShelterCertificate.sudo().search_count(domain)
  66. # pager
  67. pager = portal_pager(
  68. url="/my/tax_shelter_certificates",
  69. url_args={"date_begin": date_begin, "date_end": date_end},
  70. total=tax_shelter_count,
  71. page=page,
  72. step=self._items_per_page,
  73. )
  74. # content according to pager and archive selected
  75. tax_shelters = TaxShelterCertificate.sudo().search(
  76. domain, limit=self._items_per_page, offset=pager["offset"]
  77. )
  78. tax_shelters = tax_shelters.sorted(
  79. key=lambda r: r.declaration_id.fiscal_year, reverse=True
  80. )
  81. request.session[
  82. "my_taxshelter_certificates_history"
  83. ] = tax_shelters.ids[:100]
  84. values.update(
  85. {
  86. "date": date_begin,
  87. "tax_shelters": tax_shelters,
  88. "page_name": "taxshelter",
  89. "pager": pager,
  90. "default_url": "/my/tax_shelter_certificates",
  91. }
  92. )
  93. return request.render(
  94. "easy_my_coop_website_taxshelter.portal_my_tax_shelter", values
  95. )
  96. @http.route(
  97. ["/my/tax_shelter_certificates/<int:certificate_id>"],
  98. type="http",
  99. auth="public",
  100. website=True,
  101. )
  102. def portal_taxshelter_certificate(
  103. self,
  104. certificate_id,
  105. access_token=None,
  106. report_type=None,
  107. download=False,
  108. query_string=None,
  109. **kw
  110. ):
  111. partner = request.env.user.partner_id
  112. try:
  113. taxshelter_certificate_sudo = self._document_check_access(
  114. "tax.shelter.certificate", certificate_id, access_token
  115. )
  116. if taxshelter_certificate_sudo.partner_id != partner:
  117. raise Forbidden()
  118. except (AccessError, MissingError):
  119. return request.redirect("/my")
  120. if report_type in ("html", "pdf", "text") and query_string in (
  121. "subscription",
  122. "shares",
  123. ):
  124. report_ref = (
  125. "easy_my_coop_taxshelter_report.action_tax_shelter_%s_report"
  126. % (query_string)
  127. )
  128. return self._show_report(
  129. model=taxshelter_certificate_sudo,
  130. report_type=report_type,
  131. report_ref=report_ref,
  132. download=download,
  133. )
  134. values = self._taxshelter_certificate_get_page_view_values(
  135. taxshelter_certificate_sudo, access_token, **kw
  136. )
  137. return request.render(
  138. "easy_my_coop_website_taxshelter.portal_taxshelter_page", values
  139. )