diff --git a/README.md b/README.md index fea6c87..10389a3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# bemade-addons Branch 16.0 +# bemade-addons Odoo Addons made by Bemade diff --git a/bemade_documents_portal/__init__.py b/bemade_documents_portal/__init__.py new file mode 100644 index 0000000..91c5580 --- /dev/null +++ b/bemade_documents_portal/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/bemade_documents_portal/__manifest__.py b/bemade_documents_portal/__manifest__.py new file mode 100644 index 0000000..b5e503b --- /dev/null +++ b/bemade_documents_portal/__manifest__.py @@ -0,0 +1,32 @@ +# +# Bemade Inc. +# +# Copyright (C) September 2023 Bemade Inc. (). +# Author: Marc Durepos (Contact : marc@bemade.org) +# +# This program is under the terms of the Odoo Proprietary License v1.0 (OPL-1) +# It is forbidden to publish, distribute, sublicense, or sell copies of the Software +# or modified copies of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +{ + 'name': 'Documents Portal Base', + 'version': '15.0.1.0.0', + 'summary': 'Adds documents to the front-end portal.', + 'category': 'Document Management', + 'author': 'Bemade Inc.', + 'website': 'https://www.bemade.org', + 'license': 'OPL-1', + 'depends': ['documents', 'portal', 'mail_enterprise', 'im_livechat'], + 'data': ['views/document_portal_templates.xml'], + 'demo': [], + 'installable': True, + 'auto_install': False, +} diff --git a/bemade_documents_portal/controllers/__init__.py b/bemade_documents_portal/controllers/__init__.py new file mode 100644 index 0000000..8c3feb6 --- /dev/null +++ b/bemade_documents_portal/controllers/__init__.py @@ -0,0 +1 @@ +from . import portal diff --git a/bemade_documents_portal/controllers/portal.py b/bemade_documents_portal/controllers/portal.py new file mode 100644 index 0000000..b33fe63 --- /dev/null +++ b/bemade_documents_portal/controllers/portal.py @@ -0,0 +1,65 @@ +from odoo.addons.portal.controllers.portal import CustomerPortal +from odoo.http import request, route +from odoo.exceptions import AccessError, MissingError +from odoo import _ + + +class DocumentCustomerPortal(CustomerPortal): + + def _prepare_home_portal_values(self, counters): + rtn = super()._prepare_home_portal_values(counters) + domain = self._prepare_documents_domain() + rtn['documents_count'] = request.env['documents.document'].search_count(domain) + return rtn + + @route('/my/documents', type='http', auth='user', website=True) + def portal_my_documents(self, **kwargs): + values = self._prepare_portal_layout_values() + Documents = request.env['documents.document'] + domain = self._prepare_documents_domain() + documents_count = Documents.search_count(domain) + documents = Documents.search(domain) + values.update({ + 'documents_count': documents_count, + 'documents': documents.sudo(), + 'default_url': '/my/documents', + 'page_name': 'my_documents', + }) + return request.render("bemade_documents_portal.portal_my_documents", values) + + def _prepare_documents_domain(self): + partner = request.env.user.partner_id + user = request.env.user + """Helper method intended to be overridden for future modules.""" + return ['|', + ('partner_id', '=', partner.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/', 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), + ('content-disposition', f'attachment; filename="{document.name}"') + ] + return request.make_response(attachment.raw, headers) diff --git a/bemade_documents_portal/models/__init__.py b/bemade_documents_portal/models/__init__.py new file mode 100644 index 0000000..203b44a --- /dev/null +++ b/bemade_documents_portal/models/__init__.py @@ -0,0 +1 @@ +from . import documents diff --git a/bemade_documents_portal/models/documents.py b/bemade_documents_portal/models/documents.py new file mode 100644 index 0000000..adcef6a --- /dev/null +++ b/bemade_documents_portal/models/documents.py @@ -0,0 +1,17 @@ +from odoo import models, fields + + +class Document(models.Model): + _name = 'documents.document' + _inherit = ['documents.document', 'portal.mixin'] + + def _compute_access_url(self): + super()._compute_access_url() + for document in self: + 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') \ No newline at end of file diff --git a/bemade_documents_portal/views/document_portal_templates.xml b/bemade_documents_portal/views/document_portal_templates.xml new file mode 100644 index 0000000..64fc142 --- /dev/null +++ b/bemade_documents_portal/views/document_portal_templates.xml @@ -0,0 +1,112 @@ + + + + + +