diff --git a/partner_contact_lang/README.rst b/partner_contact_lang/README.rst new file mode 100644 index 000000000..0522bafff --- /dev/null +++ b/partner_contact_lang/README.rst @@ -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/9.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 smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Pedro M. Baeza + +Icon +---- +* Original Odoo icons. + +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. diff --git a/partner_contact_lang/__init__.py b/partner_contact_lang/__init__.py new file mode 100644 index 000000000..a77a6fcbc --- /dev/null +++ b/partner_contact_lang/__init__.py @@ -0,0 +1,4 @@ +# -*- 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 000000000..6567618a4 --- /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': '9.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/i18n/sl.po b/partner_contact_lang/i18n/sl.po new file mode 100644 index 000000000..f922deb67 --- /dev/null +++ b/partner_contact_lang/i18n/sl.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_contact_lang +# +# Translators: +# Matjaž Mozetič , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-11-25 03:42+0000\n" +"PO-Revision-Date: 2016-11-25 03:42+0000\n" +"Last-Translator: Matjaž Mozetič , 2016\n" +"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: sl\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" + +#. module: partner_contact_lang +#: model:ir.model,name:partner_contact_lang.model_res_partner +msgid "Partner" +msgstr "Partner" diff --git a/partner_contact_lang/models/__init__.py b/partner_contact_lang/models/__init__.py new file mode 100644 index 000000000..e0345afe7 --- /dev/null +++ b/partner_contact_lang/models/__init__.py @@ -0,0 +1,4 @@ +# -*- 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 new file mode 100644 index 000000000..0b6b612c1 --- /dev/null +++ b/partner_contact_lang/models/res_partner.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# © 2016 Pedro M. Baeza +# 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): + """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 childs: + childs.write({'lang': vals['lang']}) + return res + + @api.multi + def onchange_parent_id(self, parent_id): + """Change language if the parent company changes and there's no + language defined yet""" + res = super(ResPartner, self).onchange_parent_id(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.png b/partner_contact_lang/static/description/icon.png new file mode 100644 index 000000000..90980f184 Binary files /dev/null and b/partner_contact_lang/static/description/icon.png differ diff --git a/partner_contact_lang/static/description/icon.svg b/partner_contact_lang/static/description/icon.svg new file mode 100644 index 000000000..95b972591 --- /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 new file mode 100644 index 000000000..410aa95b3 --- /dev/null +++ b/partner_contact_lang/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- 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 new file mode 100644 index 000000000..945245198 --- /dev/null +++ b/partner_contact_lang/tests/test_partner_contact_lang.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# © 2016 Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests import common + + +class TestPartnerContactLang(common.TransactionCase): + 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.partner.id) + self.assertEqual(res.get('value', {}).get('lang'), 'en_US') + + def test_write_parent_lang(self): + 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 new file mode 100644 index 000000000..4412c82af --- /dev/null +++ b/partner_contact_lang/views/res_partner_view.xml @@ -0,0 +1,17 @@ + + + + + res.partner + + 9999 + + + + + + + + + +