Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] partner_contact_lang: Manage language in contacts #302

Merged
merged 3 commits into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
63 changes: 63 additions & 0 deletions partner_contact_lang/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.. 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

===========================
Manage language in contacts
===========================

Odoo by default propagate language field to the created contacts from their
form, but it doesn't allow to change it once created.

This module fills this gap, and also provides other facilities for the
contact language management:

* Put the language of the parent company when the contact doesn't have a
language and this parent company is assigned.
* When the company changes the language, it fills with the same language all
the contacts that don't have any.

Usage
=====

Go to any partner that is a company and has contacts. Click on one contact
and you will be able to edit the language.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/8.0

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

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

* Pedro M. Baeza <pedro.baeza@tecnativa.com>

Icon
----
* Original Odoo icons.

Maintainer
----------

.. image:: https://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 https://odoo-community.org.
4 changes: 4 additions & 0 deletions partner_contact_lang/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
20 changes: 20 additions & 0 deletions partner_contact_lang/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
'name': 'Manage language in contacts',
'version': '8.0.1.0.0',
'category': 'Partner Management',
'license': 'AGPL-3',
'author': 'Tecnativa,'
'Odoo Community Association (OCA)',
'website': 'https://www.tecnativa.com',
'depends': [
'base',
],
'data': [
'views/res_partner_view.xml',
],
'installable': True
}
4 changes: 4 additions & 0 deletions partner_contact_lang/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import res_partner
41 changes: 41 additions & 0 deletions partner_contact_lang/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import api, models


class ResPartner(models.Model):
_inherit = 'res.partner'

@api.multi
def write(self, vals):
if 'lang' in vals and vals['lang']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vals.get("lang") is simpler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not exactly the same. We can do anyway if vals.get('lang') is not None:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I understand what you mean. However, in this case is better vals.get("lang"), because otherwise, if you are editing a parent partner and unsetting its lang, then you would search for all children that have no lang and unset it (which is redundant).

if 'child_ids' in vals:
childs = self.browse(vals['child_ids'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line fails. STR:

  1. In runbot, enter agrolait form.
  2. Set it to English.
  3. Save.
Odoo Server Error

Traceback (most recent call last):
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/http.py", line 544, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/http.py", line 581, in dispatch
    result = self._call_function(**self.params)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/http.py", line 317, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/http.py", line 314, in checked_call
    return self.endpoint(*a, **kw)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/http.py", line 810, in __call__
    return self.method(*args, **kw)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/http.py", line 410, in response_wrap
    response = f(*args, **kw)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/addons/web/controllers/main.py", line 944, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/api.py", line 399, in old_api
    result = method(recs, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/addons/partner_firstname/models/res_partner.py", line 245, in write
    return super(ResPartner, this).write(vals)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/api.py", line 592, in new_api
    result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/addons/partner_contact_in_several_companies/models.py", line 123, in write
    res_partner, self).write(cr, user, ids, vals, context=context)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/api.py", line 399, in old_api
    result = method(recs, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/addons/partner_relations/model/res_partner.py", line 328, in write
    .write(vals)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/addons/partner_contact_lang/models/res_partner.py", line 15, in write
    childs = self.browse(vals['child_ids'])
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/models.py", line 5313, in browse
    return self._browse(self.env, ids)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3152869-302-e4435c/openerp/models.py", line 5293, in _browse
    env.prefetch[cls._name].update(ids)
TypeError: unhashable type: 'list'

else:
childs = self.mapped('child_ids')
childs = childs.filtered(lambda x: not x.lang)
if childs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if does not much, since if not childs, next call to write will iterate over a 0-length recordset and do nothing. Not a blocker, but I'd personally remove it.

childs.write({'lang': vals['lang']})
return super(ResPartner, self).write(vals)

@api.multi
def onchange_address(self, use_parent_address, parent_id):
"""Change language if the parent company changes and there's no
language defined yet"""
res = super(ResPartner, self).onchange_address(
use_parent_address, parent_id)
if parent_id and self.parent_id.id != parent_id and not self.lang:
parent = self.browse(parent_id)
val = res.setdefault('value', {})
val['lang'] = parent.lang
return res

@api.multi
@api.onchange('lang')
def onchange_lang(self):
if self.lang:
childs = self.child_ids.filtered(lambda x: not x.lang)
for child in childs:
child.lang = self.lang
Binary file added partner_contact_lang/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading