diff --git a/easy_my_coop_website_taxshelter/controllers/main.py b/easy_my_coop_website_taxshelter/controllers/main.py index 52a02f8..5a01ded 100644 --- a/easy_my_coop_website_taxshelter/controllers/main.py +++ b/easy_my_coop_website_taxshelter/controllers/main.py @@ -6,10 +6,11 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import fields, models, http +from werkzeug.exceptions import Forbidden, NotFound + +from openerp import http +from openerp.exceptions import AccessError, MissingError from openerp.http import request -from openerp import tools -from openerp.tools.translate import _ from openerp.addons.website_portal_v10.controllers.main import WebsiteAccount @@ -78,3 +79,72 @@ class CooperatorWebsiteAccount(WebsiteAccount): "easy_my_coop_website_taxshelter.portal_my_tax_shelter", values ) + + @http.route(['/my/subscription_certificate/pdf/'], + type='http', auth="user", website=True) + def get_subscription_certificate_pdf(self, oid=-1): + """Render the Subscription 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. + partner = request.env.user.partner_id + tax_shelter_mgr = request.env['tax.shelter.certificate'].sudo() + tax_shelter = tax_shelter_mgr.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'].sudo() + pdf = report_mgr.get_pdf( + tax_shelter.ids, + 'easy_my_coop_taxshelter_report.tax_shelter_subscription_report' + ) + filename = "Subscription Certificate - {name} - {year}".format( + name=partner.name, + year=tax_shelter.declaration_id.fiscal_year + ) + return self._render_pdf(pdf, filename) + + @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'].sudo() + tax_shelter = tax_shelter_mgr.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'].sudo() + pdf = report_mgr.get_pdf( + tax_shelter.ids, + 'easy_my_coop_taxshelter_report.tax_shelter_shares_report' + ) + filename = "Share Certificate - {name} - {year}".format( + name=partner.name, + year=tax_shelter.declaration_id.fiscal_year + ) + return self._render_pdf(pdf, filename) + + 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) diff --git a/easy_my_coop_website_taxshelter/security/ir.model.access.csv b/easy_my_coop_website_taxshelter/security/ir.model.access.csv deleted file mode 100644 index 6ea5383..0000000 --- a/easy_my_coop_website_taxshelter/security/ir.model.access.csv +++ /dev/null @@ -1,4 +0,0 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_tax_shelter_declaration,tax.shelter.declaration.portal,easy_my_coop_taxshelter_report.model_tax_shelter_declaration,base.group_portal,1,0,0,0 -access_tax_shelter_certificate,tax.shelter.certificate.portal,easy_my_coop_taxshelter_report.model_tax_shelter_certificate,base.group_portal,1,0,0,0 -access_tax_shelter_certificate_lines,certificate.line.portal,easy_my_coop_taxshelter_report.model_certificate_line,base.group_portal,1,0,0,0 diff --git a/easy_my_coop_website_taxshelter/security/tax_shelter_portal_security.xml b/easy_my_coop_website_taxshelter/security/tax_shelter_portal_security.xml deleted file mode 100644 index 25f2f54..0000000 --- a/easy_my_coop_website_taxshelter/security/tax_shelter_portal_security.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - Easy My Coop Portal Tax Shelter Certificate - - - - [('partner_id', 'in', [user.commercial_partner_id.id])] - - - - - - - Easy My Coop Portal Tax Shelter Certificate line - - - - [('tax_shelter_certificate.partner_id','in', [user.commercial_partner_id.id])] - - - - - - Easy My Coop Portal Personal Contacts - - - [('id', 'in', [user.commercial_partner_id.id])] - - - - - 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 f20711e..5a069b0 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 @@ -65,6 +65,8 @@ Declaration Year + Subscription Certificate + Share Certificate Total Amount @@ -76,7 +78,25 @@ - + + + Subscription Certificate + + + + + Share Certificate + + + + +