diff --git a/contract/__init__.py b/contract/__init__.py index aee8895e7..ada0b87be 100644 --- a/contract/__init__.py +++ b/contract/__init__.py @@ -1,2 +1,3 @@ +from . import controllers from . import models from . import wizards diff --git a/contract/__manifest__.py b/contract/__manifest__.py index b90a9f73c..44fd7e755 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -1,10 +1,10 @@ # Copyright 2004-2010 OpenERP SA # Copyright 2014-2018 Tecnativa - Pedro M. Baeza # Copyright 2015 Domatix -# Copyright 2016-2018 Tecnativa - Carlos Dauden # Copyright 2017 Tecnativa - Vicent Cubells # Copyright 2016-2017 LasLabs Inc. # Copyright 2018-2019 ACSONE SA/NV +# Copyright 2020 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { @@ -17,7 +17,7 @@ "LasLabs, " "Odoo Community Association (OCA)", 'website': 'https://github.com/oca/contract', - 'depends': ['base', 'account', 'product'], + 'depends': ['base', 'account', 'product', 'portal'], "external_dependencies": {"python": ["dateutil"]}, 'data': [ 'security/groups.xml', @@ -45,6 +45,10 @@ 'views/res_partner_view.xml', 'views/res_config_settings.xml', 'views/contract_terminate_reason.xml', + "views/contract_portal_templates.xml", + ], + "demo": [ + "demo/assets.xml", ], 'installable': True, } diff --git a/contract/controllers/__init__.py b/contract/controllers/__init__.py new file mode 100644 index 000000000..f43232f01 --- /dev/null +++ b/contract/controllers/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import main diff --git a/contract/controllers/main.py b/contract/controllers/main.py new file mode 100644 index 000000000..996a5d6ad --- /dev/null +++ b/contract/controllers/main.py @@ -0,0 +1,91 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +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 PortalContract(CustomerPortal): + + def _prepare_portal_layout_values(self): + values = super()._prepare_portal_layout_values() + model = 'contract.contract' + values['contract_count'] = 0 + if request.env[model].check_access_rights('read', raise_exception=False): + values['contract_count'] = request.env[model].search_count([]) + return values + + def _contract_get_page_view_values(self, contract, access_token, **kwargs): + values = { + "page_name": "Contracts", + "contract": contract, + } + return self._get_page_view_values( + contract, access_token, values, 'my_contracts_history', False, **kwargs) + + def _get_filter_domain(self, kw): + return [] + + @http.route(['/my/contracts', '/my/contracts/page/'], + type='http', auth="user", website=True) + def portal_my_contracts(self, page=1, date_begin=None, date_end=None, + sortby=None, **kw): + values = self._prepare_portal_layout_values() + contract_obj = request.env['contract.contract'] + domain = self._get_filter_domain(kw) + searchbar_sortings = { + "date": {"label": _("Date"), "order": "recurring_next_date desc"}, + "name": {"label": _("Name"), "order": "name desc"}, + "code": {"label": _("Reference"), "order": "code desc"}, + } + # default sort by order + if not sortby: + sortby = 'date' + order = searchbar_sortings[sortby]['order'] + # count for pager + contract_count = contract_obj.search_count(domain) + # pager + pager = portal_pager( + url="/my/contracts", + url_args={ + "date_begin": date_begin, + "date_end": date_end, + "sortby": sortby, + }, + total=contract_count, + page=page, + step=self._items_per_page + ) + # content according to pager and archive selected + contracts = contract_obj.search( + domain, + order=order, + limit=self._items_per_page, + offset=pager['offset'] + ) + request.session['my_contracts_history'] = contracts.ids[:100] + values.update({ + "date": date_begin, + "contracts": contracts, + "page_name": "Contracts", + "pager": pager, + "default_url": "/my/contracts", + "searchbar_sortings": searchbar_sortings, + "sortby": sortby + }) + return request.render("contract.portal_my_contracts", values) + + @http.route(['/my/contracts/'], + type='http', auth="public", website=True) + def portal_my_contract_detail(self, contract_contract_id, access_token=None, **kw): + try: + contract_sudo = self._document_check_access( + 'contract.contract', contract_contract_id, access_token + ) + except (AccessError, MissingError): + return request.redirect('/my') + values = self._contract_get_page_view_values(contract_sudo, access_token, **kw) + return request.render("contract.portal_contract_page", values) diff --git a/contract/data/mail_template.xml b/contract/data/mail_template.xml index 78368c9a5..161b1279d 100644 --- a/contract/data/mail_template.xml +++ b/contract/data/mail_template.xml @@ -57,6 +57,8 @@ %endif

+

+ View contract ]]> diff --git a/contract/demo/assets.xml b/contract/demo/assets.xml new file mode 100644 index 000000000..c84c19549 --- /dev/null +++ b/contract/demo/assets.xml @@ -0,0 +1,12 @@ + + + +