From 4bfa5f61d4904eec2a80a5dd76e401119a6e7709 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Thu, 24 Nov 2016 23:52:04 +0100 Subject: [PATCH] partner_contact_lang: Manage language in contacts (#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. --- partner_contact_lang/README.rst | 97 +-- partner_contact_lang/__init__.py | 3 +- partner_contact_lang/__openerp__.py | 20 + partner_contact_lang/models/__init__.py | 3 +- partner_contact_lang/models/res_partner.py | 54 +- .../static/description/icon.svg | 760 ++++++++++++++++++ partner_contact_lang/tests/__init__.py | 3 +- .../tests/test_partner_contact_lang.py | 46 +- .../views/res_partner_view.xml | 45 +- 9 files changed, 874 insertions(+), 157 deletions(-) create mode 100644 partner_contact_lang/__openerp__.py create mode 100644 partner_contact_lang/static/description/icon.svg diff --git a/partner_contact_lang/README.rst b/partner_contact_lang/README.rst index ba0095fbed2e..ecab7d3d5b54 100644 --- a/partner_contact_lang/README.rst +++ b/partner_contact_lang/README.rst @@ -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 `_. -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 `_. - -Do not contact contributors directly about support or help with technical issues. +Bugs are tracked on `GitHub 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 `__: +------------ - * Javier Iniesta - * Vicent Cubells - * David Vidal - * Cristina Martín - * Pedro Evaristo Gonzalez Sanchez +* Pedro M. Baeza -* Tharathip Chaweewongphan +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 `_ 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. diff --git a/partner_contact_lang/__init__.py b/partner_contact_lang/__init__.py index 4b76c7b2d5c9..a77a6fcbc5d3 100644 --- a/partner_contact_lang/__init__.py +++ b/partner_contact_lang/__init__.py @@ -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 diff --git a/partner_contact_lang/__openerp__.py b/partner_contact_lang/__openerp__.py new file mode 100644 index 000000000000..6d154ab4dd1a --- /dev/null +++ b/partner_contact_lang/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2016 Pedro M. Baeza +# 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 +} diff --git a/partner_contact_lang/models/__init__.py b/partner_contact_lang/models/__init__.py index 284a83ff1c2b..e0345afe794b 100644 --- a/partner_contact_lang/models/__init__.py +++ b/partner_contact_lang/models/__init__.py @@ -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 diff --git a/partner_contact_lang/models/res_partner.py b/partner_contact_lang/models/res_partner.py index 4ca32c17557c..23d6e02f9873 100644 --- a/partner_contact_lang/models/res_partner.py +++ b/partner_contact_lang/models/res_partner.py @@ -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 +# 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 diff --git a/partner_contact_lang/static/description/icon.svg b/partner_contact_lang/static/description/icon.svg new file mode 100644 index 000000000000..95b972591fa8 --- /dev/null +++ b/partner_contact_lang/static/description/icon.svg @@ -0,0 +1,760 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/partner_contact_lang/tests/__init__.py b/partner_contact_lang/tests/__init__.py index 6493df257d56..410aa95b391b 100644 --- a/partner_contact_lang/tests/__init__.py +++ b/partner_contact_lang/tests/__init__.py @@ -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 test_partner_contact_lang diff --git a/partner_contact_lang/tests/test_partner_contact_lang.py b/partner_contact_lang/tests/test_partner_contact_lang.py index 29e677bf53cf..273958854976 100644 --- a/partner_contact_lang/tests/test_partner_contact_lang.py +++ b/partner_contact_lang/tests/test_partner_contact_lang.py @@ -1,35 +1,29 @@ -# Copyright 2016 Tecnativa - Pedro M. Baeza -# Copyright 2017 Tecnativa - Vicent Cubells -# Copyright 2018 Tecnativa - Cristina Martín -# Copyright 2021 Pesol - Pedro Evaristo Gonzalez Sanchez -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +# -*- coding: utf-8 -*- +# © 2016 Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests import common +from openerp.tests import common class TestPartnerContactLang(common.TransactionCase): - @classmethod - def setUpClass(cls): - super(TestPartnerContactLang, cls).setUpClass() - cls.ResPartner = cls.env["res.partner"] - cls.partner = cls.ResPartner.create({"name": "Partner test", "lang": "en_US"}) - cls.contact = cls.ResPartner.create( - {"name": "Contact test", "lang": False, "parent_id": cls.partner.id} - ) + def setUp(self): + super(TestPartnerContactLang, self).setUp() + self.ResPartner = self.env['res.partner'] + self.partner = self.ResPartner.create({ + 'name': 'Partner test', + 'lang': 'en_US', + }) + self.contact = self.ResPartner.create({ + 'name': 'Contact test', + 'lang': False, + 'parent_id': self.partner.id, + }) def test_onchange_parent_id(self): self.contact.parent_id = False - res = self.contact.onchange_parent_id() - self.assertIsNone(res) - self.contact.parent_id = self.partner - res = self.contact.onchange_parent_id() - self.assertEqual(self.contact.lang, "en_US") + res = self.contact.onchange_address(False, self.partner.id) + self.assertEqual(res.get('value', {}).get('lang'), 'en_US') def test_write_parent_lang(self): - """First empty the field for filling it again afterwards to see if - the contact gets the same value. - """ - self.contact.lang = False - self.partner.lang = False - self.partner.lang = "en_US" - self.assertEqual(self.contact.lang, "en_US") + self.partner.lang = 'en_US' + self.assertEqual(self.contact.lang, 'en_US') diff --git a/partner_contact_lang/views/res_partner_view.xml b/partner_contact_lang/views/res_partner_view.xml index cecd9269e5d9..1213a38b9543 100644 --- a/partner_contact_lang/views/res_partner_view.xml +++ b/partner_contact_lang/views/res_partner_view.xml @@ -1,41 +1,16 @@ - - - + + + + - view.partner.address.form.extension res.partner - 100 - + - - - - - - - + + - - res.partner.filter.extension - res.partner - - - - - - - - - - - + + +