-
-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by hbrunn
- Loading branch information
Showing
69 changed files
with
6,515 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
================================= | ||
Contact Manager In Website Portal | ||
================================= | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github | ||
:target: https://github.com/OCA/website/tree/12.0/website_portal_contact | ||
:alt: OCA/website | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/website-12-0/website-12-0-website_portal_contact | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/186/12.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module extends the functionality of the website portal to allow your | ||
users to manage their contacts. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
#. Log in as a portal user. | ||
#. Go to `your portal home </my/home>`_. | ||
#. Go to `your contacts manager </my/contacts>`_. | ||
#. Read, create, edit or delete (disable) any contacts you want! | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/website/issues/new?body=module:%20website_portal_contact%0Aversion:%2012.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 | ||
~~~~~~~ | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Jairo Llopis <[email protected]> | ||
* Laurence Lars Labusch <[email protected]> | ||
* `TAKOBI <https://takobi.online>`_: | ||
|
||
* Simone Rubino <[email protected]> | ||
|
||
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. | ||
|
||
This module is part of the `OCA/website <https://github.com/OCA/website/tree/12.0/website_portal_contact>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2016 Jairo Llopis <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import controllers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2016 Jairo Llopis <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
{ | ||
"name": "Contact Manager In Website Portal", | ||
"summary": "Allows logged in portal users to manage their contacts", | ||
"version": "12.0.1.0.0", | ||
"category": "Portal", | ||
"website": "https://tecnativa.com/", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"license": "LGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": [ | ||
"portal", | ||
"product", | ||
"website" | ||
], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"security/ir.rule.csv", | ||
"views/assets.xml", | ||
"views/contact_form.xml", | ||
"views/contact_tree.xml", | ||
"views/layout.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2016 Jairo Llopis <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
# Copyright 2016 Jairo Llopis <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
import logging | ||
|
||
from odoo import _ | ||
from odoo.addons.portal.controllers.portal import CustomerPortal | ||
from odoo.exceptions import ValidationError | ||
from odoo.http import local_redirect, request, route | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class WebsiteAccount(CustomerPortal): | ||
def _contacts_domain(self, search=""): | ||
"""Get user's contacts domain.""" | ||
partner = request.env.user.partner_id | ||
domain = [ | ||
('id', 'child_of', partner.id) | ||
] | ||
|
||
# To edit yourself you have /my/account | ||
domain += [("id", "!=", partner.id)] | ||
|
||
# Add search query | ||
for term in search.split(): | ||
domain += [ | ||
"|", | ||
"|", | ||
("name", "ilike", term), | ||
("mobile", "ilike", term), | ||
("email", "ilike", term), | ||
] | ||
|
||
return domain | ||
|
||
def _prepare_portal_layout_values(self, contact=None): | ||
values = super(WebsiteAccount, self)._prepare_portal_layout_values() | ||
partner_counts = request.env["res.partner"].search_count( | ||
self._contacts_domain() | ||
) | ||
values['contact_count'] = partner_counts | ||
return values | ||
|
||
def _prepare_contacts_values( | ||
self, page=1, date_begin=None, date_end=None, search="", sortby=None | ||
): | ||
"""Prepare the rendering context for the contacts list.""" | ||
values = self._prepare_portal_layout_values() | ||
Partner = request.env["res.partner"] | ||
base_url = "/my/contacts" | ||
|
||
searchbar_sortings = { | ||
'date': {'label': _('Newest'), 'order': 'create_date desc'}, | ||
'name': {'label': _('Name'), 'order': 'name'}, | ||
} | ||
if not sortby: | ||
sortby = 'date' | ||
order = searchbar_sortings[sortby]['order'] | ||
|
||
# Get the required domains | ||
domain = self._contacts_domain(search) | ||
archive_groups = self._get_archive_groups("res.partner", domain) | ||
|
||
if date_begin and date_end: | ||
domain += [ | ||
("create_date", ">=", date_begin), | ||
("create_date", "<", date_end), | ||
] | ||
|
||
# Make pager | ||
pager = request.website.pager( | ||
url=base_url, | ||
url_args={"date_begin": date_begin, "date_end": date_end, "sortby": sortby}, | ||
total=Partner.search_count(domain), | ||
page=page, | ||
step=self._items_per_page, | ||
) | ||
|
||
# Current records to display | ||
contacts = Partner.search( | ||
domain, order=order, limit=self._items_per_page, offset=pager["offset"] | ||
) | ||
request.session['my_contacts_history'] = contacts.ids[:100] | ||
|
||
values.update( | ||
{ | ||
"date": date_begin, | ||
"date_end": date_end, | ||
"contacts": contacts, | ||
"page_name": 'contact', | ||
"pager": pager, | ||
"archive_groups": archive_groups, | ||
"default_url": base_url, | ||
"search": search, | ||
'searchbar_sortings': searchbar_sortings, | ||
'sortby': sortby | ||
} | ||
) | ||
|
||
return values | ||
|
||
def _contacts_fields(self): | ||
"""Fields to display in the form.""" | ||
return [ | ||
"name", | ||
"phone", | ||
"mobile", | ||
"email", | ||
] | ||
|
||
def _contacts_fields_check(self, received): | ||
"""Check received fields match those available.""" | ||
disallowed = set(received) - set(self._contacts_fields()) | ||
if disallowed: | ||
raise ValidationError( | ||
_("Fields not available: %s") % ", ".join(disallowed) | ||
) | ||
|
||
def _contacts_clean_values(self, values, contact=False): | ||
"""Set values to a write-compatible format""" | ||
result = {k: v or False for k, v in values.items()} | ||
result.setdefault("type", "contact") | ||
user_partner = request.env.user.partner_id | ||
if not contact: | ||
# Contact creation | ||
result.setdefault( | ||
"parent_id", user_partner.id | ||
) | ||
return result | ||
|
||
@route( | ||
["/my/contacts", "/my/contacts/page/<int:page>"], | ||
type="http", | ||
auth="user", | ||
website=True, | ||
) | ||
def portal_my_contacts( | ||
self, page=1, date_begin=None, date_end=None, sortby=None, search="", **kw | ||
): | ||
"""List all of your contacts.""" | ||
values = self._prepare_contacts_values(page, date_begin, date_end, search, | ||
sortby) | ||
return request.render("website_portal_contact.portal_my_contacts", values) | ||
|
||
@route("/my/contacts/new", auth="user", website=True) | ||
def portal_my_contacts_new(self): | ||
"""Form to create a contact.""" | ||
return self.portal_my_contacts_read(request.env["res.partner"].new()) | ||
|
||
@route("/my/contacts/create", auth="user", website=True) | ||
def portal_my_contacts_create(self, redirect="/my/contacts", **kwargs): | ||
"""Create a contact.""" | ||
self._contacts_fields_check(kwargs.keys()) | ||
values = self._contacts_clean_values(kwargs) | ||
_logger.debug("Creating contact with: %s", values) | ||
request.env["res.partner"].create(values) | ||
return local_redirect(redirect) | ||
|
||
def _contact_get_page_view_values(self, contact, access_token, **kwargs): | ||
values = { | ||
"contact": contact, | ||
"fields": self._contacts_fields(), | ||
'page_name': 'contact', | ||
'user': request.env.user | ||
} | ||
|
||
return self._get_page_view_values(contact, access_token, values, | ||
'my_contact_history', False, **kwargs) | ||
|
||
@route( | ||
["/my/contacts/<model('res.partner'):contact>"], | ||
type="http", | ||
auth="user", | ||
website=True, | ||
) | ||
def portal_my_contacts_read(self, contact, access_token=None, **kw): | ||
"""Read a contact form.""" | ||
values = self._contact_get_page_view_values(contact, access_token, **kw) | ||
return request.render( | ||
"website_portal_contact.form", values | ||
) | ||
|
||
@route( | ||
"/my/contacts/<model('res.partner'):contact>/update", | ||
auth="user", | ||
website=True, | ||
) | ||
def portal_my_contacts_update( | ||
self, contact, redirect="/my/contacts", **kwargs | ||
): | ||
"""Update a contact.""" | ||
self._contacts_fields_check(kwargs.keys()) | ||
values = self._contacts_clean_values(kwargs, contact=contact) | ||
_logger.debug("Updating %r with: %s", contact, values) | ||
contact.write(values) | ||
return local_redirect(redirect) | ||
|
||
@route( | ||
"/my/contacts/<model('res.partner'):contact>/disable", | ||
auth="user", | ||
website=True, | ||
) | ||
def portal_my_contacts_disable(self, contact, redirect="/my/contacts"): | ||
"""Disable a contact.""" | ||
_logger.debug("Disabling %r", contact) | ||
contact.sudo().active = False | ||
return local_redirect(redirect) |
Oops, something went wrong.