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..ca097a9 --- /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'], + '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..64a96b2 --- /dev/null +++ b/bemade_documents_portal/controllers/portal.py @@ -0,0 +1,39 @@ +from odoo.addons.portal.controllers.portal import CustomerPortal +from odoo.http import request, route + + +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) + print(f"Documents: {documents_count}...") + for doc in documents: + print(doc.name) + values.update({ + 'documents_count': documents_count, + 'documents': documents.sudo(), + 'default_url': '/my/documents', + 'page_name': 'my_documents', + }) + print + 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), + ] 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..0395240 --- /dev/null +++ b/bemade_documents_portal/models/documents.py @@ -0,0 +1,12 @@ +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}' + 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..55c50ff --- /dev/null +++ b/bemade_documents_portal/views/document_portal_templates.xml @@ -0,0 +1,38 @@ + + + + + + + + \ No newline at end of file