Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions agreement_portal/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
================
Agreement Portal
================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ace66f4efb7ad30070b685116e28cabe368de238715ffc058769ec6aea8c2e40
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fagreement-lightgray.png?logo=github
:target: https://github.com/OCA/agreement/tree/18.0/agreement_portal
:alt: OCA/agreement
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/agreement-18-0/agreement-18-0-agreement_portal
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/agreement&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module lets portal users see the agreements linked to their
commercial partner (or agreements they follow) in the "My Account" area
of the portal.

It adds:

- an **Agreements** card on the portal home page with a record counter,
- a paginated, sortable list at ``/my/agreements``,
- a detail page per agreement, shareable with a portal access token.

Only the fields of the base ``agreement`` module are shown (name,
reference, start and end dates, partner). Extensions displaying fields
from other agreement modules can inherit the ``portal_agreement_page``
template.

**Table of contents**

.. contents::
:local:

Usage
=====

1. Grant a customer contact portal access (Settings > Users, "Grant
portal access").
2. As that portal user, open **My Account**: an **Agreements** card
lists the agreements whose partner belongs to the user's company,
plus any agreement the user follows.
3. Internal users can share a direct link with a token from the
agreement form ("Share" behavior provided by ``portal.mixin``).

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/agreement/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/agreement/issues/new?body=module:%20agreement_portal%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Pop Solutions

Contributors
------------

- Rafnix Guzman <rafnixg@gmail.com>
- Víctor Martínez (portal controller patterns from Tecnativa portal
modules)
- Marcos Mendez <m@pop.coop>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-marcos-mendez| image:: https://github.com/marcos-mendez.png?size=40px
:target: https://github.com/marcos-mendez
:alt: marcos-mendez

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-marcos-mendez|

This module is part of the `OCA/agreement <https://github.com/OCA/agreement/tree/18.0/agreement_portal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions agreement_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers
from . import models
19 changes: 19 additions & 0 deletions agreement_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2022 Rafnix Guzman
# Copyright (C) 2026 Pop Solutions
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Agreement Portal",
"summary": "Let portal users see their agreements",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"website": "https://github.com/OCA/agreement",
"category": "Contract",
"author": "Pop Solutions, Odoo Community Association (OCA)",
"maintainers": ["marcos-mendez"],
"depends": ["portal", "agreement"],
"data": [
"security/ir.model.access.csv",
"security/agreement_security.xml",
"views/agreement_portal_templates.xml",
],
}
1 change: 1 addition & 0 deletions agreement_portal/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
98 changes: 98 additions & 0 deletions agreement_portal/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2020-2022 Tecnativa - Víctor Martínez
# Copyright (C) 2022 Rafnix Guzman
# Copyright (C) 2026 Pop Solutions
# 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
from odoo.addons.portal.controllers.portal import pager as portal_pager


class PortalAgreement(CustomerPortal):
def _prepare_home_portal_values(self, counters):
values = super()._prepare_home_portal_values(counters)
if "agreement_count" in counters:
agreement_model = request.env["agreement"]
agreement_count = (
agreement_model.search_count([])
if agreement_model.has_access("read")
else 0
)
values["agreement_count"] = agreement_count
return values

def _agreement_get_page_view_values(self, agreement, access_token, **kwargs):
values = {
"page_name": "Agreements",
"agreement": agreement,
}
return self._get_page_view_values(
agreement, access_token, values, "my_agreements_history", False, **kwargs
)

def _get_filter_domain(self, kw):
return []

@http.route(
["/my/agreements", "/my/agreements/page/<int:page>"],
type="http",
auth="user",
website=True,
)
def portal_my_agreements(self, page=1, sortby=None, **kw):
values = self._prepare_portal_layout_values()
agreement_model = request.env["agreement"]
if not agreement_model.has_access("read"):
return request.redirect("/my")
domain = self._get_filter_domain(kw)
searchbar_sortings = {
"name": {"label": _("Name"), "order": "name desc"},
"code": {"label": _("Reference"), "order": "code desc"},
}
if not sortby:
sortby = "name"
order = searchbar_sortings[sortby]["order"]
agreement_count = agreement_model.search_count(domain)
pager = portal_pager(
url="/my/agreements",
url_args={"sortby": sortby},
total=agreement_count,
page=page,
step=self._items_per_page,
)
agreements = agreement_model.search(
domain, order=order, limit=self._items_per_page, offset=pager["offset"]
)
request.session["my_agreements_history"] = agreements.ids[:100]
values.update(
{
"agreements": agreements,
"page_name": "Agreements",
"pager": pager,
"default_url": "/my/agreements",
"searchbar_sortings": searchbar_sortings,
"sortby": sortby,
}
)
return request.render("agreement_portal.portal_my_agreements", values)

@http.route(
["/my/agreements/<int:agreement_id>"],
type="http",
auth="public",
website=True,
)
def portal_my_agreement_detail(self, agreement_id, access_token=None, **kw):
try:
agreement_sudo = self._document_check_access(
"agreement", agreement_id, access_token
)
except (AccessError, MissingError):
return request.redirect("/my")
values = self._agreement_get_page_view_values(
agreement_sudo, access_token, **kw
)
return request.render("agreement_portal.portal_agreement_page", values)
1 change: 1 addition & 0 deletions agreement_portal/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import agreement
15 changes: 15 additions & 0 deletions agreement_portal/models/agreement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) 2022 Rafnix Guzman
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class Agreement(models.Model):
_name = "agreement"
_inherit = ["agreement", "portal.mixin"]

def _compute_access_url(self):
res = super()._compute_access_url()
for record in self:
record.access_url = f"/my/agreements/{record.id}"
return res
3 changes: 3 additions & 0 deletions agreement_portal/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions agreement_portal/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Rafnix Guzman \<rafnixg@gmail.com\>
- Víctor Martínez (portal controller patterns from Tecnativa portal modules)
- Marcos Mendez \<m@pop.coop\>
12 changes: 12 additions & 0 deletions agreement_portal/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This module lets portal users see the agreements linked to their commercial
partner (or agreements they follow) in the "My Account" area of the portal.

It adds:

- an **Agreements** card on the portal home page with a record counter,
- a paginated, sortable list at `/my/agreements`,
- a detail page per agreement, shareable with a portal access token.

Only the fields of the base `agreement` module are shown (name, reference,
start and end dates, partner). Extensions displaying fields from other
agreement modules can inherit the `portal_agreement_page` template.
7 changes: 7 additions & 0 deletions agreement_portal/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1. Grant a customer contact portal access (Settings > Users, "Grant portal
access").
2. As that portal user, open **My Account**: an **Agreements** card lists the
agreements whose partner belongs to the user's company, plus any agreement
the user follows.
3. Internal users can share a direct link with a token from the agreement form
("Share" behavior provided by `portal.mixin`).
14 changes: 14 additions & 0 deletions agreement_portal/security/agreement_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="rule_agreement_portal" model="ir.rule">
<field name="name">Agreement: portal users see their own</field>
<field name="model_id" ref="agreement.model_agreement" />
<field name="domain_force">
['|',
('partner_id', 'child_of', user.partner_id.commercial_partner_id.id),
('message_partner_ids', 'in', [user.partner_id.id]),
]
</field>
<field name="groups" eval="[(4, ref('base.group_portal'))]" />
</record>
</odoo>
2 changes: 2 additions & 0 deletions agreement_portal/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_agreement_portal,Agreement portal user,agreement.model_agreement,base.group_portal,1,0,0,0
Loading
Loading