Skip to content

Commit

Permalink
[add] hr_employee_address_improved
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Aug 7, 2017
1 parent 5ddb8df commit bcfba2f
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 0 deletions.
84 changes: 84 additions & 0 deletions hr_employee_address_improved/README.rst
@@ -0,0 +1,84 @@
.. 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 Employee Address Improved
============================

When the HR modules are enabled and we have 1 employee for each users,
some parts of the UI become confusing because
we have several partners for the same person:

1. res.user inherits from res.partner,
and fields such as the email are stored in there

2. hr.employee has address_id and address_home_id.
The first one refers to the work address
(presumably the partner related to the company of the address
of an office of the company, so not a problem)
but the other one is the home address
and if used it will probably be linked to a partner
with the same name as the employee.

Assumption: we would like to exclude home addresses
from the list of available partners in m2o and m2m fields.

.. note::

when this module is installed a post init hook
**will set all partners related via `address_home_id` as inactive**.

Installation
============

To install this module, you need to:

* clone the branch 10.0 of the repository https://github.com/OCA/hr
* add the path to this repository in your configuration (addons-path)
* update the module list
* search for "HR Employee Address Improved" in your addons
* install the module

Configuration
=============

No extra configuration needed.


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

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/hr/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
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

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

* Simone Orsi <simone.orsi@camptocamp.com>
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>

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.
1 change: 1 addition & 0 deletions hr_employee_address_improved/__init__.py
@@ -0,0 +1 @@
from .hooks import post_init_hook
18 changes: 18 additions & 0 deletions hr_employee_address_improved/__manifest__.py
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Author: Simone Orsi
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'HR Employee Address Improved',
'version': '10.0.1.0.0',
'category': 'Human Resources',
'author': 'Camptocamp,Odoo Community Association (OCA)',
'license': 'AGPL-3',
'depends': ['hr'],
'website': 'http://www.camptocamp.com',
'data': [
'views/hr.xml',
],
'installable': True,
'post_init_hook': 'post_init_hook',
}
23 changes: 23 additions & 0 deletions hr_employee_address_improved/hooks.py
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Author: Simone Orsi
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import SUPERUSER_ID, api
import logging

logger = logging.getLogger('[hr_employee_address_improved.post_init_hook]')


def post_init_hook(cr, pool):
env = api.Environment(cr, SUPERUSER_ID, {})
partners_count = env['res.partner'].search_count([])
empls = env['hr.employee'].with_context(
active_test=False).search([('address_home_id', '!=', False)])
empls.mapped('address_home_id').with_context(
tracking_disable=True).write({'active': False})
logger.info(
'Set all partners assigned to `employee.address_home_id` '
'as not active. Partners matching: %d out of %d',
len(empls), partners_count
)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions hr_employee_address_improved/views/hr.xml
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_employee_form" model="ir.ui.view">
<field name="name">hr_employee_address_improved hr.employee.form </field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<field name="bank_account_id" position="attributes">
<attribute name="domain">['|', ('active', '=', True), ('active', '=', False)]</attribute>
<attribute name="context">{
'default_supplier': True,
'default_customer': False,
'default_active': False,
'default_partner_id': address_home_id}</attribute>
</field>
<field name="address_home_id" position="attributes">
<attribute name="context">{
'show_address': True,
'default_supplier': True,
'default_customer': False,
'default_active': False}</attribute>
</field>
</field>
</record>
</odoo>

0 comments on commit bcfba2f

Please sign in to comment.