Browse Source

Merge pull request #106 from coopiteasy/12.0-mig-emc_website_taxshelter

[12.0][MIG] easy_my_coop_website_taxshelter
pull/122/head
Rémy Taymans 4 years ago
committed by GitHub
parent
commit
cd6ab005dd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      easy_my_coop_taxshelter_report/models/tax_shelter_declaration.py
  2. 4
      easy_my_coop_website_taxshelter/README.rst
  3. 12
      easy_my_coop_website_taxshelter/__manifest__.py
  4. 179
      easy_my_coop_website_taxshelter/controllers/main.py
  5. 5
      easy_my_coop_website_taxshelter/readme/CONTRIBUTORS.rst
  6. 6
      easy_my_coop_website_taxshelter/static/description/index.html
  7. 211
      easy_my_coop_website_taxshelter/views/easy_my_coop_website_taxshelter_templates.xml

8
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,13 @@ 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]

4
easy_my_coop_website_taxshelter/README.rst

@ -47,8 +47,10 @@ Authors
Contributors
~~~~~~~~~~~~
* Coop IT Easy SCRLfs
* `Coop IT Easy SCRLfs <https://coopiteasy.be>`_:
* Rémy TAYMANS <remy@coopiteasy.be>
* Vincent VAN ROSSEM <vincent@coopiteasy.be>
Maintainers
~~~~~~~~~~~

12
easy_my_coop_website_taxshelter/__manifest__.py

@ -5,18 +5,12 @@
{
"name": "Easy My Coop Tax Shelter Website",
"version": "12.0.1.0.0",
"depends": [
"website",
"website_portal_v10",
"easy_my_coop_taxshelter_report",
"report",
],
"depends": ["website", "portal", "easy_my_coop_taxshelter_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,
}

179
easy_my_coop_website_taxshelter/controllers/main.py

@ -2,38 +2,58 @@
# 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 werkzeug.exceptions import Forbidden, NotFound
from werkzeug.exceptions import Forbidden
from odoo import http
from odoo.exceptions import AccessError, MissingError
from odoo.http import request
from odoo.addons.portal.controllers.portal import (
CustomerPortal,
pager as portal_pager,
)
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
tax_shelter_mgr = request.env["tax.shelter.certificate"]
tax_shelter_count = tax_shelter_mgr.sudo().search_count(
[("partner_id", "in", [partner.commercial_partner_id.id])]
class PortalTaxShelter(CustomerPortal):
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/<int:page>",
"/my/tax_shelter_certificates",
"/my/tax_shelter_certificates/page/<int: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 +61,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 +72,82 @@ 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/<int:oid>"],
["/my/tax_shelter_certificates/<int:certificate_id>"],
type="http",
auth="user",
auth="public",
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.
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/<int:oid>"],
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",
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,
)
values = self._taxshelter_certificate_get_page_view_values(
taxshelter_certificate_sudo, access_token, **kw
)
filename = "Share Certificate - {} - {}".format(
partner.name, tax_shelter.declaration_id.fiscal_year
return request.render(
"easy_my_coop_website_taxshelter.portal_taxshelter_page", values
)
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)

5
easy_my_coop_website_taxshelter/readme/CONTRIBUTORS.rst

@ -1 +1,4 @@
* Coop IT Easy SCRLfs
* `Coop IT Easy SCRLfs <https://coopiteasy.be>`_:
* Rémy TAYMANS <remy@coopiteasy.be>
* Vincent VAN ROSSEM <vincent@coopiteasy.be>

6
easy_my_coop_website_taxshelter/static/description/index.html

@ -400,7 +400,11 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<ul class="simple">
<li>Coop IT Easy SCRLfs</li>
<li><a class="reference external" href="https://coopiteasy.be">Coop IT Easy SCRLfs</a>:<ul>
<li>Rémy TAYMANS &lt;<a class="reference external" href="mailto:remy&#64;coopiteasy.be">remy&#64;coopiteasy.be</a>&gt;</li>
<li>Vincent VAN ROSSEM &lt;<a class="reference external" href="mailto:vincent&#64;coopiteasy.be">vincent&#64;coopiteasy.be</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">

211
easy_my_coop_website_taxshelter/views/easy_my_coop_website_taxshelter_templates.xml

@ -1,108 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2015-2016 Odoo S.A.
Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
Copyright 2018 Rémy Taymans <remytaymans@gmail.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<!-- Tax Shelter Certificate in the menu -->
<template
id="portal_my_home_menu_tax_shelter"
name="Portal Menu: Easy My Coop Tax Shelter Certificate"
inherit_id="website_portal_v10.portal_layout"
priority="25">
<xpath expr="//ul[contains(@class,'o_portal_submenu')]"
position="inside">
<li>
<a href="/my/tax_shelter_certificate">
Tax Shelter Certificate
</a>
<template id="portal_my_home_menu_tax_shelter"
name="Portal layout: Easy My Coop Tax Shelter Certificate Menu Entries"
inherit_id="portal.portal_breadcrumbs"
priority="25">
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
<li t-if="page_name == 'taxshelter' or taxshelter and taxshelter.state in ('validated', 'sent')"
t-attf-class="breadcrumb-item #{'active ' if not taxshelter else ''}">
<a t-if="taxshelter" t-attf-href="/my/tax_shelter_certificates?{{ keep_query() }}">Tax Shelter Certificates</a>
<t t-else="">Tax Shelter Certificates</t>
</li>
<li t-if="taxshelter" class="breadcrumb-item active">
<t t-esc="taxshelter.declaration_id.name" t-if="taxshelter.declaration_id.name"/>
</li>
</xpath>
</template>
<!-- Tax Shelter Certificate on the main page -->
<template
id="portal_my_home_tax_shelter"
name="Portal My Home : Easy My Coop Tax Shelter Certificate"
inherit_id="website_portal_v10.portal_my_home"
priority="25">
<xpath expr="//div[contains(@class,'o_my_home_content')]"
position="inside">
<h3 class="page-header">
<a href="/my/tax_shelter_certificate">
Your Tax Shelter Certificate
<small class="ml8">
<t t-if="tax_shelter_count">
<span class='badge'>
<t t-esc="tax_shelter_count"/>
</span>
</t>
<t t-if="not tax_shelter_count">
There are currently no tax shelter certificate for
your
account.
</t>
</small>
</a>
</h3>
<template id="portal_my_home_tax_shelter"
name="Portal My Home : Easy My Coop Tax Shelter Certificate Entries"
inherit_id="portal.portal_my_home"
priority="25">
<xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
<t t-if="tax_shelter_count" t-call="portal.portal_docs_entry">
<t t-set="title">Tax Shelter Certificates</t>
<t t-set="url" t-value="'/my/tax_shelter_certificates'"/>
<t t-set="count" t-value="tax_shelter_count"/>
</t>
</xpath>
</template>
<!-- Tax Shelter Certificate page -->
<template id="portal_my_tax_shelter" name="My Tax Shelter">
<t t-call="website_portal_v10.portal_layout">
<h3 class="page-header">Your Tax Shelter Certificate</h3>
<t t-call="portal.portal_layout">
<t t-set="breadcrumbs_searchbar" t-value="True"/>
<t t-call="portal.portal_searchbar">
<t t-set="title">Tax Shelter Certificates</t>
</t>
<t t-if="not tax_shelters">
<p>
There are currently no tax shelter certificate for your
account.
</p>
<p>There are currently no tax shelter certificates for your account.</p>
</t>
<t t-if="tax_shelters">
<table class="table table-hover o_my_status_table">
<thead>
<tr class="active">
<th>Declaration Year</th>
<th>Tax Shelter Certificate</th>
<th>Share Certificate</th>
<th>Total Amount</th>
</tr>
</thead>
<tbody>
<tr t-foreach="tax_shelters" t-as="tax_shelter">
<td>
<t t-esc="tax_shelter.declaration_id.name"/>
</td>
<td>
<a t-att-href="'/my/taxshelter_certificate/pdf/%s'
% tax_shelter.id">
Tax Shelter Certificate
</a>
</td>
<td>
<a t-att-href="'/my/share_certificate/pdf/%s'
% tax_shelter.id">
Share Certificate
</a>
</td>
<td>
<span t-field="tax_shelter.total_amount"
t-field-options='{
"widget": "monetary",
"display_currency": "tax_shelter.partner_id.company_id.currency_id"
}'/>
</td>
</tr>
</tbody>
</table>
<div t-if="pager" class="o_portal_pager text-center">
<t t-call="website.pager"/>
</div>
<t t-if="tax_shelters" t-call="portal.portal_table">
<thead>
<tr class="active">
<th>Declaration Year</th>
<th class="text-right">Total Amount</th>
</tr>
</thead>
<t t-foreach="tax_shelters" t-as="tax_shelter">
<tr>
<td>
<a t-att-href="tax_shelter.get_portal_url()" t-att-title="tax_shelter.declaration_id.name">
<t t-esc="tax_shelter.declaration_id.name" t-if="tax_shelter.declaration_id.name"/>
<em t-else="">Draft Tax Shelter Certificate</em>
</a>
</td>
<td class="text-right">
<span t-field="tax_shelter.total_amount" t-options='{"widget": "monetary", "display_currency":tax_shelter.partner_id.company_id.currency_id}'/>
</td>
</tr>
</t>
</t>
</t>
</template>
</openerp>
<!-- Tax Shelter Certificate Content -->
<template id="portal_taxshelter_page" name="Tax Shelter Portal Template" inherit_id="portal.portal_sidebar" primary="True">
<xpath expr="//div[hasclass('o_portal_sidebar')]" position="inside">
<div class="row mt16">
<!-- Sidebar -->
<t t-call="portal.portal_record_sidebar">
<t t-set="classes" t-value="'col-lg-auto d-print-none'"/>
<t t-set="title">
<h2 class="mb-0"><b t-field="taxshelter.total_amount" data-id="total_amount" t-options='{"widget": "monetary", "display_currency":taxshelter.partner_id.company_id.currency_id}'/> </h2>
</t>
<t t-set="entries">
<ul class="list-group list-group-flush flex-wrap flex-row flex-lg-column">
<li class="list-group-item flex-grow-1">
<div class="o_download_pdf btn-toolbar flex-sm-nowrap">
<div class="btn-group flex-grow-1 mb-1">
<a id="print_taxshelter_subscription" class="btn btn-secondary btn-block o_print_btn" t-att-href="taxshelter.get_portal_url(report_type='pdf', query_string='&amp;query_string=subscription')" title="Print Subscription" target="_blank"><i class="fa fa-print"/> Subscription Certificate</a>
</div>
</div>
<div class="o_download_pdf btn-toolbar flex-sm-nowrap">
<div class="btn-group flex-grow-1 mb-1">
<a id="print_taxshelter_shares" class="btn btn-secondary btn-block o_print_btn" t-att-href="taxshelter.get_portal_url(report_type='pdf', query_string='&amp;query_string=shares')" title="Print Shares" target="_blank"><i class="fa fa-print"/> Shares Certificate</a>
</div>
</div>
</li>
</ul>
</t>
</t>
<!-- Page Content -->
<!-- Room for improvement: html display
<div id="taxshelter_certificate_content" class="o_portal_page_content col-12 col-lg d-flex flex-column align-items-end">
<div class="o_portal_page_size">
<t t-if="error or warning" t-call="easy_my_coop_website_taxshelter.portal_taxshelter_error"/>
<t t-if="success and (not error and not warning)" t-call="account.portal_taxshelter_success"/>
<div class="o_portal_html_view shadow">
<div class="o_portal_html_loader text-center">
<i class="fa fa-circle-o-notch fa-spin fa-2x fa-fw text-black-50"></i>
</div>
<iframe id="taxshelter_certificate_html" class="mt8 mb8" width="100%" height="100%" frameborder="0" scrolling="no" t-att-src="taxshelter.get_portal_url(report_type='html')"/>
</div>
</div>
</div>
-->
</div>
</xpath>
</template>
<!-- Room for improvement: those templates should be called if html display is implemented -->
<!--
<template id="portal_taxshelter_error" name="Taxshelter error/warning display">
<div class="row mr16">
<div t-attf-class="'col-lg-12 mr16 ml16 alert alert-dismissable' #{'alert-danger' if error else 'alert-warning'}" role="alert">
<a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
<t t-if="error == 'generic'" name="generic">
There was an error processing this page.
</t>
</div>
</div>
</template>
<template id="portal_taxshelter_success" name="Taxshelter success display">
<div class="row mr16">
<div class="col-lg-12 mr16 ml16 alert alert-dismissable alert-success" role="status">
<a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
</div>
</div>
</template>
-->
</odoo>
Loading…
Cancel
Save