-
-
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.
[MIG] website_portal_contact from Odoo 9
- Replace website_portal_v10 by portal - Fix menu, breadcumb and contact_count - Adapt test with tour - Translate fr_CA.po, fr.po and pot - Fix parent_id with the same partner_id
- Loading branch information
Showing
82 changed files
with
7,950 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,63 @@ | ||
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
|
||
================================= | ||
Contact Manager In Website Portal | ||
================================= | ||
|
||
This module extends the functionality of the website portal to allow your | ||
users to manage their contacts. | ||
|
||
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! | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/186/9.0 | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
* This uses the backported version of the website portal from v10. When | ||
migrating to v10, we should adapt to any changes there. | ||
* Remove workarounds for https://github.com/odoo/odoo/issues/12961 in JS tour | ||
when fixed. | ||
|
||
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. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Jairo Llopis <[email protected]> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
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. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
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,25 @@ | ||
# 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", | ||
"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,207 @@ | ||
# 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.""" | ||
# domain = request.env.ref( | ||
# "website_portal_contact.rule_edit_own_contacts" | ||
# ).domain_force | ||
# TODO manage permission, permit to show own contacts | ||
domain = [] | ||
|
||
# To edit yourself you have /my/account | ||
domain += [("id", "!=", request.env.user.partner_id.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") | ||
if not contact or contact.id != request.env.user.commercial_partner_id.id: | ||
result.setdefault( | ||
"parent_id", request.env.user.commercial_partner_id.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) | ||
contact = request.env["res.partner"].create(values) | ||
return local_redirect(redirect.format(contact.id)) | ||
|
||
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.contacts_followup", 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.format(contact.id)) | ||
|
||
@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.