forked from OCA/website
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New module displaying the address book of your employees in the website
- Loading branch information
1 parent
3c97a15
commit 0a03114
Showing
10 changed files
with
477 additions
and
1 deletion.
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,52 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
=============== | ||
HR Address Book | ||
=============== | ||
|
||
This module add a new page into your website displaying the address book of your employees. | ||
The informations related to your employees are publicly available if your employee is | ||
published. The same rule applies to the address informations. | ||
|
||
Usage | ||
===== | ||
|
||
.. 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/8.0 | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
* todo: add the department's address book | ||
|
||
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 | ||
`here <https://github.com/OCA/website/issues/new?body=module:%20website_hr_employee_addressbook%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Laurent Mignon <[email protected]> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: http://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: http://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 http://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,2 @@ | ||
# -*- coding: utf-8 -*- | ||
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,45 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This file is part of website_hr_contact, | ||
# an Odoo module. | ||
# | ||
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>) | ||
# | ||
# website_hr_contact is free software: | ||
# you can redistribute it and/or modify it under the terms of the GNU | ||
# Affero General Public License as published by the Free Software | ||
# Foundation,either version 3 of the License, or (at your option) any | ||
# later version. | ||
# | ||
# website_hr_contact is distributed | ||
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
# PURPOSE. See the GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with website_hr_contact. | ||
# If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
{ | ||
'name': "hR Address Book", | ||
|
||
'summary': """ | ||
Display your hr address book in your website""", | ||
|
||
'author': 'ACSONE SA/NV,' | ||
'Odoo Community Association (OCA)', | ||
'website': "http://acsone.eu", | ||
'category': 'Website', | ||
'version': '8.0.1.0.0', | ||
'license': 'AGPL-3', | ||
'depends': [ | ||
'website_hr', | ||
], | ||
|
||
'data': [ | ||
'views/website_hr_contact_templates.xml', | ||
'data/website_hr_contact_data.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,2 @@ | ||
# -*- coding: utf-8 -*- | ||
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,155 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This file is part of website_hr_contact, an Odoo module. | ||
# | ||
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>) | ||
# | ||
# website_hr_contact is free software: you can redistribute it and/or | ||
# modify it under the terms of the GNU Affero General Public License | ||
# as published by the Free Software Foundation, either version 3 of | ||
# the License, or (at your option) any later version. | ||
# | ||
# website_hr_contact is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the | ||
# GNU Affero General Public License | ||
# along with website_hr_contact. | ||
# If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
import werkzeug | ||
|
||
from openerp import http | ||
from openerp.addons.website.models.website import slug | ||
from openerp.osv.orm import browse_record | ||
|
||
|
||
class QueryURL(object): | ||
def __init__(self, path='', path_args=None, **args): | ||
self.path = path | ||
self.args = args | ||
self.path_args = set(path_args or []) | ||
|
||
def __call__(self, path=None, path_args=None, **kw): | ||
path = path or self.path | ||
for k, v in self.args.items(): | ||
kw.setdefault(k, v) | ||
path_args = set(path_args or []).union(self.path_args) | ||
paths, fragments = [], [] | ||
for key, value in kw.items(): | ||
if value and key in path_args: | ||
if isinstance(value, browse_record): | ||
paths.append((key, slug(value))) | ||
else: | ||
paths.append((key, value)) | ||
elif value: | ||
if isinstance(value, list) or isinstance(value, set): | ||
fragments.append( | ||
werkzeug.url_encode([(key, item) for item in value])) | ||
else: | ||
fragments.append(werkzeug.url_encode([(key, value)])) | ||
for key, value in paths: | ||
path += '/' + key + '/%s' % value | ||
if fragments: | ||
path += '?' + '&'.join(fragments) | ||
return path | ||
|
||
|
||
class WebsiteHrAddressbook(http.Controller): | ||
_items_per_page = 20 | ||
|
||
def _get_children_department_recursive(self, root, visible_departments): | ||
tree = [] | ||
for department in root.child_ids: | ||
children = self._get_children_department_recursive( | ||
department, visible_departments) | ||
if department in visible_departments: | ||
tree.append({ | ||
'department': visible_departments.filtered( | ||
lambda rec: rec.id == department.id), | ||
'children': children | ||
}) | ||
else: | ||
tree.extend(children) | ||
return tree | ||
|
||
def _get_departments_tree(self, department=None, search=None, **post): | ||
""" Build a department tree with only published departments | ||
The tree only contains published department even if the parent | ||
department is not published. | ||
""" | ||
tree = [] | ||
request = http.request | ||
hr_department = request.env['hr.department'] | ||
sudo_hr_department = hr_department.sudo() | ||
visible_departments = hr_department.search([(1, '=', 1)]) | ||
departments = sudo_hr_department.search([('parent_id', '=', False)]) | ||
for department in departments: | ||
children = self._get_children_department_recursive( | ||
department, visible_departments) | ||
if department in visible_departments: | ||
tree.append({ | ||
'department': visible_departments.filtered( | ||
lambda rec: rec.id == department.id), | ||
'children': children | ||
}) | ||
else: | ||
tree.extend(children) | ||
return tree | ||
|
||
def _get_employees_domain(self, department=None, search=None, **post): | ||
domain = [] | ||
if department: | ||
domain.append(('department_id', '=', department.id)) | ||
if search: | ||
domain.append(('name', 'ilike', search)) | ||
return domain | ||
|
||
@http.route(['/page/hr_contact/employees', | ||
'/page/hr_contact/employees/page/<int:page>', | ||
'/page/hr_contact/employees/department/' | ||
'<model("hr.department"):department>', | ||
'/page/hr_contact/employees/department/' | ||
'<model("hr.department"):department>/page/<int:page>' | ||
], type='http', auth="public", website=True) | ||
def employees(self, department=None, search='', page=1, **post): | ||
request = http.request | ||
hr_employee = request.env['hr.employee'] | ||
departments_tree = self._get_departments_tree( | ||
department, search, **post) | ||
|
||
domain = self._get_employees_domain(department, search, **post) | ||
employees = hr_employee.search(domain) | ||
|
||
url_builder = QueryURL( | ||
'/page/hr_contact/employees', ['department', 'page'], | ||
department=department) | ||
|
||
count = len(employees) | ||
pager = request.website.pager( | ||
url=url_builder(), | ||
total=count, | ||
page=page, | ||
step=self._items_per_page, | ||
url_args={'search': search}, | ||
) | ||
pager_begin = (page - 1) * self._items_per_page | ||
pager_end = page * self._items_per_page | ||
employees = employees[pager_begin:pager_end] | ||
|
||
values = { | ||
'employees': employees, | ||
'departments_tree': departments_tree, | ||
'department': department, | ||
'pager': pager, | ||
'url_builder': url_builder, | ||
'search': search, | ||
'count': count, | ||
} | ||
return request.website.render( | ||
'website_hr_contact.employees', values) |
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data noupdate="1"> | ||
|
||
<record id="menu_contact_employees" model="website.menu"> | ||
<field name="name">Employees</field> | ||
<field name="url">/page/hr_contact/employees</field> | ||
<field name="parent_id" ref="website.main_menu"/> | ||
<field name="sequence" type="int">50</field> | ||
</record> | ||
|
||
</data> | ||
</openerp> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,20 @@ | ||
.employees_contact #middle_column>section+section { | ||
margin-top: 2em; | ||
padding-top: 2em; | ||
border-top: 1px solid #ddd; | ||
} | ||
.employees_contact dl { | ||
} | ||
|
||
.employees_contact dt { | ||
float: left; | ||
clear: left; | ||
text-align: right; | ||
font-weight: bold; | ||
} | ||
.employees_contact dt:after { | ||
content: ":\00a0"; | ||
} | ||
.employees_contact dd { | ||
padding: 0 0 0.5em 0; | ||
} |
Oops, something went wrong.