From 08fbe8113712110a89deb56ce3a7eb37c8012fdf Mon Sep 17 00:00:00 2001 From: Vincent Van Rossem Date: Tue, 16 Jun 2020 10:40:28 +0200 Subject: [PATCH 1/5] [MIG] emc_website_taxshelter: adaptation to 12.0 --- .../models/tax_shelter_declaration.py | 6 + .../__manifest__.py | 8 +- .../controllers/main.py | 140 ++++-------- ...y_my_coop_website_taxshelter_templates.xml | 211 ++++++++++-------- 4 files changed, 176 insertions(+), 189 deletions(-) diff --git a/easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py b/easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py index de1e921..20d9e2d 100644 --- a/easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py +++ b/easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py @@ -187,6 +187,7 @@ class TaxShelterDeclaration(models.Model): class TaxShelterCertificate(models.Model): _name = "tax.shelter.certificate" + _inherit = ['portal.mixin'] _description = "Tax Shelter Certificate" _order = "cooperator_number asc" @@ -277,6 +278,11 @@ class TaxShelterCertificate(models.Model): related="declaration_id.company_id", string="Company" ) + def _compute_access_url(self): + super()._compute_access_url() + for certificate in self: + certificate.access_url = '/my/tax_shelter_certificates/%s' % (certificate.id) + def generate_pdf_report(self, report_type): report, name = REPORT_DIC[report_type] report = self.env.ref(report).render_qweb_pdf(self.id)[0] diff --git a/easy_my_coop_website_taxshelter/__manifest__.py b/easy_my_coop_website_taxshelter/__manifest__.py index 4b4dfca..194ab55 100644 --- a/easy_my_coop_website_taxshelter/__manifest__.py +++ b/easy_my_coop_website_taxshelter/__manifest__.py @@ -7,16 +7,14 @@ "version": "12.0.1.0.0", "depends": [ "website", - "website_portal_v10", + "portal", "easy_my_coop_taxshelter_report", - "report", ], "summary": "Give access to Tax Shelter Report in the website portal.", "author": "Coop IT Easy SCRLfs", "license": "AGPL-3", "category": "Cooperative Management", - "website": "https://www.coopiteasy.be", + "website": "https://coopiteasy.be", "data": ["views/easy_my_coop_website_taxshelter_templates.xml"], - "installable": False, - "application": False, + "installable": True, } diff --git a/easy_my_coop_website_taxshelter/controllers/main.py b/easy_my_coop_website_taxshelter/controllers/main.py index 3cf47d8..a2a4813 100644 --- a/easy_my_coop_website_taxshelter/controllers/main.py +++ b/easy_my_coop_website_taxshelter/controllers/main.py @@ -2,38 +2,41 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import http -from openerp.addons.website_portal_v10.controllers.main import WebsiteAccount -from openerp.exceptions import AccessError, MissingError -from openerp.http import request +from odoo import http +from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager +from odoo.exceptions import AccessError, MissingError +from odoo.http import request from werkzeug.exceptions import Forbidden, NotFound -class TaxShelterWebsiteAccount(WebsiteAccount): - @http.route() - def account(self): - """ Add Tax Shelter Certificate to main account page """ - response = super(TaxShelterWebsiteAccount, self).account() - partner = request.env.user.partner_id +class PortalTaxShelter(CustomerPortal): - tax_shelter_mgr = request.env["tax.shelter.certificate"] - tax_shelter_count = tax_shelter_mgr.sudo().search_count( + def _prepare_portal_layout_values(self): + values = super()._prepare_portal_layout_values() + partner = request.env.user.partner_id + tax_shelter_count = request.env["tax.shelter.certificate"].sudo().search_count( [("partner_id", "in", [partner.commercial_partner_id.id])] ) + values['tax_shelter_count'] = tax_shelter_count + return values - response.qcontext.update({"tax_shelter_count": tax_shelter_count}) - return response + def _taxshelter_certificate_get_page_view_values(self, taxshelter_certificate, access_token, **kwargs): + values = { + 'page_name': 'taxshelter', + 'taxshelter': taxshelter_certificate, + } + return self._get_page_view_values(taxshelter_certificate, access_token, values, 'my_taxshelter_certificates_history', False, **kwargs) @http.route( [ - "/my/tax_shelter_certificate", - "/my/tax_shelter_certificate/page/", + "/my/tax_shelter_certificates", + "/my/tax_shelter_certificates/page/", ], type="http", auth="user", website=True, ) - def portal_my_tax_shelter_certificate( + def portal_my_tax_shelter_certificates( self, page=1, date_begin=None, date_end=None, **kw ): """Render a page that lits the tax shelter report: @@ -41,9 +44,8 @@ class TaxShelterWebsiteAccount(WebsiteAccount): * Shares Certifcates """ values = self._prepare_portal_layout_values() + TaxShelterCertificate = request.env["tax.shelter.certificate"] partner = request.env.user.partner_id - tax_shelter_mgr = request.env["tax.shelter.certificate"] - domain = [("partner_id", "in", [partner.commercial_partner_id.id])] if date_begin and date_end: @@ -53,106 +55,54 @@ class TaxShelterWebsiteAccount(WebsiteAccount): ] # count for pager - tax_shelter_count = tax_shelter_mgr.sudo().search_count(domain) + tax_shelter_count = TaxShelterCertificate.sudo().search_count(domain) # pager - pager = request.website.pager( - url="/my/tax_shelter_certificate", + pager = portal_pager( + url="/my/tax_shelter_certificates", url_args={"date_begin": date_begin, "date_end": date_end}, total=tax_shelter_count, page=page, step=self._items_per_page, ) # content according to pager and archive selected - tax_shelters = tax_shelter_mgr.sudo().search( + tax_shelters = TaxShelterCertificate.sudo().search( domain, limit=self._items_per_page, offset=pager["offset"] ) tax_shelters = tax_shelters.sorted( key=lambda r: r.declaration_id.fiscal_year, reverse=True ) + request.session['my_taxshelter_certificates_history'] = tax_shelters.ids[:100] + values.update( { "date": date_begin, "tax_shelters": tax_shelters, - "page_name": "invoice", + "page_name": "taxshelter", "pager": pager, - "default_url": "/my/tax_shelter_certificate", + "default_url": "/my/tax_shelter_certificates", } ) - return request.website.render( + return request.render( "easy_my_coop_website_taxshelter.portal_my_tax_shelter", values ) - @http.route( - ["/my/taxshelter_certificate/pdf/"], - type="http", - auth="user", - website=True, - ) - def get_taxshelter_certificate_pdf(self, oid=-1): - """Render the Tax Shelter Certificate pdf of the given Tax - Shelter Report - """ - # Get the subscription certificate and raise an error if the user - # is not allowed to access to it or if the object is not found. + @http.route(['/my/tax_shelter_certificates/'], type='http', auth="public", website=True) + def portal_taxshelter_certificate(self, certificate_id, access_token=None, report_type=None, download=False, query_string=None, **kw): partner = request.env.user.partner_id - tax_shelter_mgr = request.env["tax.shelter.certificate"] - tax_shelter = tax_shelter_mgr.sudo().browse(oid) try: - if tax_shelter.partner_id != partner: + taxshelter_certificate_sudo = self._document_check_access('tax.shelter.certificate', certificate_id, access_token) + if taxshelter_certificate_sudo.partner_id != partner: raise Forbidden() - except AccessError: - raise Forbidden() - except MissingError: - raise NotFound() - # Get the pdf - report_mgr = request.env["report"] - pdf = report_mgr.sudo().get_pdf( - tax_shelter, - "easy_my_coop_taxshelter_report.tax_shelter_subscription_report", - ) - filename = "Tax Shelter Certificate - {} - {}".format( - partner.name, tax_shelter.declaration_id.fiscal_year - ) - return self._render_pdf(pdf, filename) + except (AccessError, MissingError): + return request.redirect('/my') - @http.route( - ["/my/share_certificate/pdf/"], - type="http", - auth="user", - website=True, - ) - def get_share_certificate_pdf(self, oid=-1): - """Render the Share Certificate pdf of the given Tax Shelter - Report - """ - # Get the share certificate and raise an error if the user - # is not allowed to access to it or if the object is not found. - partner = request.env.user.partner_id - tax_shelter_mgr = request.env["tax.shelter.certificate"] - tax_shelter = tax_shelter_mgr.sudo().browse(oid) - try: - if tax_shelter.partner_id != partner: - raise Forbidden() - except AccessError: - raise Forbidden() - except MissingError: - raise NotFound() - # Get the pdf - report_mgr = request.env["report"] - pdf = report_mgr.sudo().get_pdf( - tax_shelter, - "easy_my_coop_taxshelter_report.tax_shelter_shares_report", - ) - filename = "Share Certificate - {} - {}".format( - partner.name, tax_shelter.declaration_id.fiscal_year - ) - return self._render_pdf(pdf, filename) + if report_type in ('html', 'pdf', 'text') and query_string in ('subscription', 'shares'): + report_ref = "easy_my_coop_taxshelter_report.action_tax_shelter_%s_report" % (query_string) + return self._show_report( + model=taxshelter_certificate_sudo, + report_type=report_type, + report_ref=report_ref, + download=download) - def _render_pdf(self, pdf, filename): - """Render a http response for a pdf""" - pdfhttpheaders = [ - ("Content-Disposition", 'inline; filename="%s.pdf"' % filename), - ("Content-Type", "application/pdf"), - ("Content-Length", len(pdf)), - ] - return request.make_response(pdf, headers=pdfhttpheaders) + values = self._taxshelter_certificate_get_page_view_values(taxshelter_certificate_sudo, access_token, **kw) + return request.render("easy_my_coop_website_taxshelter.portal_taxshelter_page", values) diff --git a/easy_my_coop_website_taxshelter/views/easy_my_coop_website_taxshelter_templates.xml b/easy_my_coop_website_taxshelter/views/easy_my_coop_website_taxshelter_templates.xml index e79d262..538adbd 100644 --- a/easy_my_coop_website_taxshelter/views/easy_my_coop_website_taxshelter_templates.xml +++ b/easy_my_coop_website_taxshelter/views/easy_my_coop_website_taxshelter_templates.xml @@ -1,108 +1,141 @@ - - + -