forked from OCA/partner-contact
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
partner_contact_lang: Manage language in contacts (OCA#302)
=========================== 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.
- Loading branch information
Showing
9 changed files
with
874 additions
and
157 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 |
---|---|---|
@@ -1,102 +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 | ||
=========================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:547d4bcfd0afc33a40f2083409a4dd7c9b5fe47447745b33d151eec7fef57026 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github | ||
:target: https://github.com/OCA/partner-contact/tree/16.0/partner_contact_lang | ||
:alt: OCA/partner-contact | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_contact_lang | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
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. | ||
#. Show the language in the inner narrowed Contact form and | ||
set the new conctact with a different language if needed. | ||
#. Search and also group contacts by their language. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
* 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 company partner has contacts. | ||
#. Click on any contact and you will be able to edit the language. | ||
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 to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_contact_lang%0Aversion:%2016.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. | ||
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 | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`__: | ||
------------ | ||
|
||
* Javier Iniesta | ||
* Vicent Cubells | ||
* David Vidal | ||
* Cristina Martín | ||
* Pedro Evaristo Gonzalez Sanchez <pedro.gonzalez@pesol.es> | ||
* Pedro M. Baeza <pedro.baeza@tecnativa.com> | ||
|
||
* Tharathip Chaweewongphan <tharathipc@ecosoft.co.th> | ||
Icon | ||
---- | ||
* Original Odoo icons. | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
: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. | ||
|
||
This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/16.0/partner_contact_lang>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. | ||
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import models |
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 @@ | ||
# -*- 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 | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import res_partner |
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 |
---|---|---|
@@ -1,38 +1,42 @@ | ||
# Copyright 2016-2020 Tecnativa - Pedro M. Baeza | ||
# Copyright 2017 Tecnativa - Vicent Cubells | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
# -*- 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 odoo import api, models | ||
from openerp import api, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
_inherit = 'res.partner' | ||
|
||
@api.multi | ||
def write(self, vals): | ||
"""Propagate a language change in the partner to the child contacts.""" | ||
res = super(ResPartner, self).write(vals) | ||
if vals.get("lang"): | ||
childs = self.search([("id", "child_of", self.ids), ("lang", "=", False)]) | ||
if vals.get('lang'): | ||
childs = self.search([ | ||
('id', 'child_of', self.ids), | ||
('lang', '=', False), | ||
]) | ||
if childs: | ||
childs.write({"lang": vals["lang"]}) | ||
childs.write({'lang': vals['lang']}) | ||
return res | ||
|
||
@api.onchange("parent_id") | ||
def onchange_parent_id(self): | ||
@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. | ||
A special case is made for virtual records, where default lang value | ||
is assigned at startup, so we always overwrite language in that case. | ||
""" | ||
res = super(ResPartner, self).onchange_parent_id() | ||
if ( | ||
self.parent_id.lang | ||
and ( | ||
not self.lang | ||
or (isinstance(self.id, models.NewId) and not self._origin) | ||
) | ||
and self.parent_id.lang != self.lang | ||
): | ||
self.lang = self.parent_id.lang | ||
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 |
Oops, something went wrong.