got portal working to at least give a download button and chatter on documents. No preview yet.
This commit is contained in:
parent
ee7882ea69
commit
679e29f4da
4 changed files with 105 additions and 7 deletions
|
|
@ -24,7 +24,7 @@
|
||||||
'author': 'Bemade Inc.',
|
'author': 'Bemade Inc.',
|
||||||
'website': 'https://www.bemade.org',
|
'website': 'https://www.bemade.org',
|
||||||
'license': 'OPL-1',
|
'license': 'OPL-1',
|
||||||
'depends': ['documents', 'portal'],
|
'depends': ['documents', 'portal', 'mail_enterprise', 'im_livechat'],
|
||||||
'data': ['views/document_portal_templates.xml'],
|
'data': ['views/document_portal_templates.xml'],
|
||||||
'demo': [],
|
'demo': [],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
from odoo.addons.portal.controllers.portal import CustomerPortal
|
from odoo.addons.portal.controllers.portal import CustomerPortal
|
||||||
from odoo.http import request, route
|
from odoo.http import request, route
|
||||||
|
from odoo.exceptions import AccessError, MissingError
|
||||||
|
from odoo import _
|
||||||
|
|
||||||
|
|
||||||
class DocumentCustomerPortal(CustomerPortal):
|
class DocumentCustomerPortal(CustomerPortal):
|
||||||
|
|
@ -17,16 +19,12 @@ class DocumentCustomerPortal(CustomerPortal):
|
||||||
domain = self._prepare_documents_domain()
|
domain = self._prepare_documents_domain()
|
||||||
documents_count = Documents.search_count(domain)
|
documents_count = Documents.search_count(domain)
|
||||||
documents = Documents.search(domain)
|
documents = Documents.search(domain)
|
||||||
print(f"Documents: {documents_count}...")
|
|
||||||
for doc in documents:
|
|
||||||
print(doc.name)
|
|
||||||
values.update({
|
values.update({
|
||||||
'documents_count': documents_count,
|
'documents_count': documents_count,
|
||||||
'documents': documents.sudo(),
|
'documents': documents.sudo(),
|
||||||
'default_url': '/my/documents',
|
'default_url': '/my/documents',
|
||||||
'page_name': 'my_documents',
|
'page_name': 'my_documents',
|
||||||
})
|
})
|
||||||
print
|
|
||||||
return request.render("bemade_documents_portal.portal_my_documents", values)
|
return request.render("bemade_documents_portal.portal_my_documents", values)
|
||||||
|
|
||||||
def _prepare_documents_domain(self):
|
def _prepare_documents_domain(self):
|
||||||
|
|
@ -37,3 +35,30 @@ class DocumentCustomerPortal(CustomerPortal):
|
||||||
('partner_id', '=', partner.id),
|
('partner_id', '=', partner.id),
|
||||||
('owner_id', '=', user.id),
|
('owner_id', '=', user.id),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def _render_record_template(self, values):
|
||||||
|
""" Override this method to apply a different template for a single document
|
||||||
|
record on the portal. """
|
||||||
|
return request.render("bemade_documents_portal.document_portal_template", values)
|
||||||
|
|
||||||
|
@route('/my/documents/<int:document_id>', type='http', auth='user', website=True)
|
||||||
|
def portal_document_page(self, document_id, download=False, **kwargs):
|
||||||
|
document = request.env['documents.document'].browse(document_id)
|
||||||
|
if not document:
|
||||||
|
raise MissingError(_('This document does not exist.'))
|
||||||
|
if download:
|
||||||
|
return self._download_attachment(document)
|
||||||
|
values={
|
||||||
|
'document': document,
|
||||||
|
'page_name': 'my_documents',
|
||||||
|
'action': document._get_portal_return_action(),
|
||||||
|
}
|
||||||
|
return self._render_record_template(values)
|
||||||
|
|
||||||
|
def _download_attachment(self, document):
|
||||||
|
attachment = document.attachment_id
|
||||||
|
headers = [
|
||||||
|
('content-type', attachment.mimetype),
|
||||||
|
('content-length', attachment.file_size),
|
||||||
|
]
|
||||||
|
return request.make_response(attachment.raw, headers)
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,8 @@ class Document(models.Model):
|
||||||
for document in self:
|
for document in self:
|
||||||
document.access_url = f'/my/documents/{document.id}'
|
document.access_url = f'/my/documents/{document.id}'
|
||||||
|
|
||||||
|
def _get_portal_return_action(self):
|
||||||
|
""" Return the action used to display documents when returning from customer
|
||||||
|
portal."""
|
||||||
|
self.ensure_one()
|
||||||
|
return self.env.ref('documents.document_action')
|
||||||
|
|
@ -21,17 +21,85 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<t t-foreach="documents" t-as="document">
|
<t t-foreach="documents" t-as="document">
|
||||||
<tr>
|
<tr>
|
||||||
<td><a t-att-href="document.get_portal_url()"><t t-esc="document.name"/></a></td>
|
<td>
|
||||||
|
<a t-att-href="document.get_portal_url()">
|
||||||
|
<t t-esc="document.name"/>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</t>
|
</t>
|
||||||
</tbody>
|
</tbody>
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
</template>
|
</template>
|
||||||
|
<template id="document_portal_template" name="Document Portal Template"
|
||||||
|
inherit_id="portal.portal_sidebar" primary="True">
|
||||||
|
<xpath expr="//div[hasclass('o_portal_sidebar')]" position="inside">
|
||||||
|
<t t-set="o_portal_fullwidth_alert"
|
||||||
|
groups="documents.group_documents_user">
|
||||||
|
<t t-call="portal.portal_back_in_edit_mode">
|
||||||
|
<t t-set="backend_url"
|
||||||
|
t-value="'/web#model=%s&id=%s&action=%s&view_type=form' % (document._name, document.id, action.id)"/>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
<div class="row mt16">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<t t-call="portal.portal_record_sidebar">
|
||||||
|
<t t-set="classes">col-lg-auto d-print-none</t>
|
||||||
|
<t t-set="title">
|
||||||
|
<h2 class="mb-0">
|
||||||
|
<b>Document Info</b>
|
||||||
|
</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 b-0">
|
||||||
|
File name: <t t-esc="document.name"/>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li class="list-group-item flex-grow-1 b-0">
|
||||||
|
<strong class="text-muted">File Type:
|
||||||
|
<t t-esc="document.mimetype"/>
|
||||||
|
</strong>
|
||||||
|
</li>
|
||||||
|
<li class="list-group-item flex-grow-1 b-0">
|
||||||
|
<strong class="text-muted">File Size:
|
||||||
|
<t t-call="documents.format_file_size"/>
|
||||||
|
</strong>
|
||||||
|
</li>
|
||||||
|
<li class="list-group-item flex-grow-1 b-0">
|
||||||
|
<a class="btn btn-secondary btn-block o_download_btn"
|
||||||
|
t-att-href="document.get_portal_url(download=True)">
|
||||||
|
Download</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
<!-- Main Document Contents -->
|
||||||
|
<div id="document_content" class="col-12 col-lg justify-content-end">
|
||||||
|
<div class="card">
|
||||||
|
<!-- Chatter -->
|
||||||
|
<div id="document_communication" class="card-body">
|
||||||
|
<h2>History</h2>
|
||||||
|
<t t-call="portal.message_thread">
|
||||||
|
<t t-set="object" t-value="document"/>
|
||||||
|
</t>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
<template id="portal_breadcrumbs" inherit_id="portal.portal_breadcrumbs">
|
<template id="portal_breadcrumbs" inherit_id="portal.portal_breadcrumbs">
|
||||||
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
|
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
|
||||||
<li t-if="page_name == 'my_documents'"
|
<li t-if="page_name == 'my_documents'"
|
||||||
class="breadcrumb-item">Documents</li>
|
t-attf-class="breadcrumb-item #{'active ' if not document else ''}">
|
||||||
|
<a t-if="document"
|
||||||
|
t-attf-href="/my/documents?{{ keep_query() }}">Documents</a>
|
||||||
|
<t t-else="">Documents</t>
|
||||||
|
</li>
|
||||||
|
<li t-if="document" class="breadcrumb-item active" t-esc="document.name">
|
||||||
|
</li>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
</data>
|
</data>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue