Browse Source

[MIG] finalize migration. fix last glitches

pull/52/head
houssine 5 years ago
parent
commit
d652412e42
  1. 4
      easy_my_coop_website_portal/__manifest__.py
  2. 133
      easy_my_coop_website_portal/controllers/main.py
  3. 73
      easy_my_coop_website_portal/views/easy_my_coop_website_portal_templates.xml

4
easy_my_coop_website_portal/__manifest__.py

@ -1,5 +1,6 @@
# Copyright 2018-Coop IT Easy SCRLfs (<http://www.coopiteasy.be>)
# Copyright 2018 Coop IT Easy SCRLfs (<http://www.coopiteasy.be>)
# - Rémy Taymans <remy@coopiteasy.be> # - Rémy Taymans <remy@coopiteasy.be>
# - Houssine Bakkali <houssine@coopiteasy.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Easy My Coop Website Portal', 'name': 'Easy My Coop Website Portal',
@ -7,6 +8,7 @@
'depends': [ 'depends': [
'easy_my_coop', 'easy_my_coop',
'website', 'website',
'account',
'portal', 'portal',
], ],
'description': """ 'description': """

133
easy_my_coop_website_portal/controllers/main.py

@ -1,19 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 Odoo S.A.
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com> # Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# Copyright 2017-2018 Rémy Taymans <remytaymans@gmail.com>
# Copyright 2017-2018 Rémy Taymans <remy@coopiteasy.be>
# Copyright 2019 Houssine Bakkali <houssine@coopiteasy.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from werkzeug.exceptions import Forbidden, NotFound
from odoo import http from odoo import http
from odoo.exceptions import AccessError, MissingError from odoo.exceptions import AccessError, MissingError
from odoo.fields import Date from odoo.fields import Date
from odoo.http import request from odoo.http import request
from odoo.addons.portal.controllers.portal import CustomerPortal from odoo.addons.portal.controllers.portal import CustomerPortal
from odoo.addons.portal.controllers.portal import pager as portal_pager
from odoo.addons.payment.controllers.portal import PaymentProcessing
class CooperatorPortalAccount(CustomerPortal): class CooperatorPortalAccount(CustomerPortal):
@ -31,26 +29,47 @@ class CooperatorPortalAccount(CustomerPortal):
limit=1 limit=1
) )
invoice_mgr = request.env['account.invoice'] invoice_mgr = request.env['account.invoice']
capital_request_count = invoice_mgr.sudo().search_count([
('partner_id', 'in',
[partner.commercial_partner_id.id]),
capital_request_count = invoice_mgr.search_count([
# ('partner_id', 'in', [partner.commercial_partner_id.id]),
('state', 'in', ['open', 'paid', 'cancelled']), ('state', 'in', ['open', 'paid', 'cancelled']),
# Get only the release capital request # Get only the release capital request
('release_capital_request', '=', True), ('release_capital_request', '=', True),
]) ])
invoice_count = invoice_mgr.search_count([
# ('partner_id', 'in', [partner.commercial_partner_id.id]),
('release_capital_request', '=', False)
])
values.update({ values.update({
'coop': coop, 'coop': coop,
'coop_bank': coop_bank, 'coop_bank': coop_bank,
'capital_request_count': capital_request_count
'capital_request_count': capital_request_count,
'invoice_count': invoice_count
}) })
return values return values
@http.route(['/my/invoices', '/my/invoices/page/<int:page>'], type='http',
auth="user", website=True)
def portal_my_invoices(self, page=1, date_begin=None, date_end=None,
sortby=None, **kw):
res = super(CooperatorPortalAccount, self).portal_my_invoices(
page, date_begin, date_end, sortby, **kw)
invoice_obj = request.env['account.invoice']
qcontext = res.qcontext
if qcontext:
invoices = invoice_obj.search([('release_capital_request', '=', False)])
invoice_count = len(invoices)
qcontext['invoices'] = invoices
qcontext['pager']['invoice_count'] = invoice_count
return res
@http.route( @http.route(
['/my/release_capital_request', ['/my/release_capital_request',
'/my/release_capital_request/page/<int:page>'], '/my/release_capital_request/page/<int:page>'],
type='http', auth="user", website=True) type='http', auth="user", website=True)
def portal_my_release_capital_request(self, page=1, date_begin=None, def portal_my_release_capital_request(self, page=1, date_begin=None,
date_end=None, **kw):
date_end=None, sortby=None, **kw):
"""Render a page with the list of release capital request. """Render a page with the list of release capital request.
A release capital request is an invoice with a flag that tell A release capital request is an invoice with a flag that tell
if it's a capital request or not. if it's a capital request or not.
@ -75,9 +94,10 @@ class CooperatorPortalAccount(CustomerPortal):
# count for pager # count for pager
capital_request_count = invoice_mgr.sudo().search_count(domain) capital_request_count = invoice_mgr.sudo().search_count(domain)
# pager # pager
pager = request.website.pager(
pager = portal_pager(
url="/my/release_capital_request", url="/my/release_capital_request",
url_args={'date_begin': date_begin, 'date_end': date_end},
url_args={'date_begin': date_begin, 'date_end': date_end,
'sortby': sortby},
total=capital_request_count, total=capital_request_count,
page=page, page=page,
step=self._items_per_page step=self._items_per_page
@ -88,7 +108,7 @@ class CooperatorPortalAccount(CustomerPortal):
values.update({ values.update({
'date': date_begin, 'date': date_begin,
'capital_requests': invoices, 'capital_requests': invoices,
'page_name': 'invoice',
'page_name': 'Release request',
'pager': pager, 'pager': pager,
'archive_groups': archive_groups, 'archive_groups': archive_groups,
'default_url': '/my/release_capital_request', 'default_url': '/my/release_capital_request',
@ -98,66 +118,43 @@ class CooperatorPortalAccount(CustomerPortal):
values values
) )
@http.route(['/my/release_capital_request/pdf/<int:oid>'],
type='http', auth="user", website=True)
def get_release_capital_request(self, oid=-1, **kw):
"""Render the pdf of the given release capital request"""
# Get the release capital request 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
invoice_mgr = request.env['account.invoice']
capital_request = invoice_mgr.sudo().browse(oid)
try:
if capital_request.partner_id != partner:
raise Forbidden()
except AccessError:
raise Forbidden()
except MissingError:
raise NotFound()
# Get the pdf
report_mgr = request.env.ref
pdf = report_mgr.sudo().get_pdf(
capital_request,
'easy_my_coop.theme_invoice_G002'
)
filename = "Release Capital Request - %d" % capital_request.id
return self._render_pdf(pdf, filename)
@http.route(['/my/release_capital_request/<int:oid_id>'],
type='http',
auth="public",
website=True)
def get_release_capital_request(self, oid=-1,
access_token=None,
report_type=None,
download=False,
**kw):
@http.route(['/my/invoices/<int:invoice_id>'],
type='http', auth="public", website=True)
def portal_my_invoice_detail(self, invoice_id, access_token=None,
report_type=None, download=False, **kw):
try: try:
invoice_sudo = self._document_check_access('account.invoice', invoice_sudo = self._document_check_access('account.invoice',
oid,
invoice_id,
access_token) access_token)
except (AccessError, MissingError): except (AccessError, MissingError):
return request.redirect('/my') return request.redirect('/my')
if invoice_sudo.release_capital_request:
report_ref = 'easy_my_coop.action_cooperator_invoices'
else:
report_ref = 'account.account_invoices'
if report_type in ('html', 'pdf', 'text'): if report_type in ('html', 'pdf', 'text'):
return self._show_report(
model=invoice_sudo,
report_type=report_type,
report_ref='easy_my_coop.theme_invoice_G002',
download=download)
# @http.route(['/my/cooperator_certificate/pdf'],
# type='http', auth="user", website=True)
# def get_cooperator_certificat(self, **kw):
# """Render the cooperator certificate pdf of the current user"""
# partner = request.env.user.partner_id
# report_mgr = request.env['report']
# pdf = report_mgr.sudo().get_pdf(
# partner,
# 'easy_my_coop.cooperator_certificat_G001'
# )
# filename = "Cooperator Certificate - %s" % partner.name
# return self._render_pdf(pdf, filename)
return self._show_report(model=invoice_sudo,
report_type=report_type,
report_ref=report_ref,
download=download)
values = self._invoice_get_page_view_values(invoice_sudo, access_token,
**kw)
PaymentProcessing.remove_payment_transaction(invoice_sudo.transaction_ids)
return request.render("account.portal_invoice_page", values)
@http.route(['/my/cooperator_certificate/pdf'],
type='http', auth="user", website=True)
def get_cooperator_certificat(self, **kw):
"""Render the cooperator certificate pdf of the current user"""
partner = request.env.user.partner_id
report_mgr = request.env['report']
pdf = report_mgr.sudo().get_pdf(
partner,
'easy_my_coop.cooperator_certificat_G001'
)
filename = "Cooperator Certificate - %s" % partner.name
return self._render_pdf(pdf, filename)
def _render_pdf(self, pdf, filename): def _render_pdf(self, pdf, filename):
"""Render a http response for a pdf""" """Render a http response for a pdf"""

73
easy_my_coop_website_portal/views/easy_my_coop_website_portal_templates.xml

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
Copyright 2015-2016 Odoo S.A.
Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com> Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
Copyright 2018 Rémy Taymans <remytaymans@gmail.com>
Copyright 2018 Rémy Taymans <remy@cooptieasy.be>
Copyright 2019 Houssine Bakkali <houssine@cooptieasy.be>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
--> -->
<odoo> <odoo>
@ -90,61 +90,21 @@
</xpath> </xpath>
</template> </template>
<!-- Release Capital Requests in the menu -->
<!--<template
id="portal_my_home_menu_capital_release"
name="Portal Menu: Easy My Coop Capital Release"
inherit_id="portal.portal_layout"
priority="20">
<xpath expr="//ul[contains(@class,'o_portal_submenu')]"
position="inside">
<li>
<a href="/my/release_capital_request">Capital Releases</a>
</li>
</xpath>
</template>
<template id="portal_my_home_menu_capital_request" name="Portal layout : capital request menu entries" inherit_id="portal.portal_breadcrumbs" priority="30"> <template id="portal_my_home_menu_capital_request" name="Portal layout : capital request menu entries" inherit_id="portal.portal_breadcrumbs" priority="30">
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
<li t-if="page_name == 'capital request'" t-attf-class="breadcrumb-item #{'active ' if not capital_requests else ''}">
<a t-if="capital_request" t-attf-href="/my/release_capital_request?{{ keep_query() }}">Capital Request</a>
<t t-else="">Capital Request</t>
</li>
<li t-if="capital_request" class="breadcrumb-item active">
<t t-esc="capital_request.number" t-if="capital_request.number"/>
<t t-else=""><em>Draft Request</em></t>
</li>
</xpath>
</template>-->
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
<li t-if="page_name == 'capital request'" t-attf-class="breadcrumb-item #{'active ' if not capital_requests else ''}">
<a t-if="capital_request" t-attf-href="/my/release_capital_request?{{ keep_query() }}">Capital Request</a>
<t t-else="">Capital Request</t>
</li>
<li t-if="capital_request" class="breadcrumb-item active">
<t t-esc="capital_request.number" t-if="capital_request.number"/>
<t t-else=""><em>Draft Request</em></t>
</li>
</xpath>
</template>
<!-- Release Capital Requests on the main page -->
<!--<template
id="portal_my_home_capital_release"
name="Portal My Home : Easy My Coop Capital Release Requests"
inherit_id="portal.portal_my_home"
priority="20">
<xpath expr="//div[contains(@class,'o_my_home_content')]"
position="inside">
<h3 class="page-header">
<a href="/my/release_capital_request">
Your Release Capital Requests
<small class="ml8">
<t t-if="capital_request_count">
<span class='badge'>
<t t-esc="capital_request_count"/>
</span>
</t>
<t t-if="not capital_request_count">
There are currently no release capital request for your
account.
</t>
</small>
</a>
</h3>
</xpath>
</template>-->
<template id="portal_my_home_capital_release"
<template id="portal_my_home_capital_release"
name="Portal My Home : Easy My Coop Capital Release Requests" name="Portal My Home : Easy My Coop Capital Release Requests"
inherit_id="portal.portal_my_home" priority="30"> inherit_id="portal.portal_my_home" priority="30">
<xpath expr="//div[hasclass('o_portal_docs')]" position="inside"> <xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
@ -182,13 +142,10 @@
<t t-foreach="capital_requests" t-as="capital_request"> <t t-foreach="capital_requests" t-as="capital_request">
<tr> <tr>
<td> <td>
<a t-att-href="capital_request.get_portal_url(report_type='easy_my_coop.theme_invoice_G002')" t-att-title="capital_request.number">
<a t-att-href="capital_request.get_portal_url()" t-att-title="capital_request.number">
<t t-esc="capital_request.number" t-if="capital_request.number"/> <t t-esc="capital_request.number" t-if="capital_request.number"/>
<em t-else="">Draft Request</em> <em t-else="">Draft Request</em>
</a> </a>
<!--<a t-att-href="'/my/release_capital_request/pdf/%s' % capital_request.id">
<t t-esc="capital_request.number"/>
</a>-->
</td> </td>
<td><span t-field="capital_request.date_invoice"/></td> <td><span t-field="capital_request.date_invoice"/></td>
<td class='d-none d-md-table-cell'><span t-field="capital_request.date_due"/></td> <td class='d-none d-md-table-cell'><span t-field="capital_request.date_due"/></td>

Loading…
Cancel
Save