Browse Source

[IMP] partner_contact_lang: black, isort

12.0
Pedro 5 years ago
committed by Pedro M. Baeza
parent
commit
06b1e7527d
  1. 19
      partner_contact_lang/__manifest__.py
  2. 17
      partner_contact_lang/models/res_partner.py
  3. 21
      partner_contact_lang/tests/test_partner_contact_lang.py

19
partner_contact_lang/__manifest__.py

@ -3,15 +3,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Manage language in contacts',
'version': '11.0.1.0.0',
'category': 'Sales',
'license': 'AGPL-3',
'author': 'Tecnativa,'
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/partner-contact/',
'depends': [
'base',
],
'installable': True,
"name": "Manage language in contacts",
"version": "11.0.1.0.0",
"category": "Sales",
"license": "AGPL-3",
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/partner-contact/",
"depends": ["base",],
"installable": True,
}

17
partner_contact_lang/models/res_partner.py

@ -6,27 +6,24 @@ from odoo 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')
@api.onchange("parent_id")
def onchange_parent_id(self):
"""Change language if the parent company changes and there's no
language defined yet"""
res = super(ResPartner, self).onchange_parent_id()
if self.parent_id and self.parent_id != self and not self.lang:
val = res.setdefault('value', {})
val['lang'] = self.parent_id.lang
val = res.setdefault("value", {})
val["lang"] = self.parent_id.lang
return res

21
partner_contact_lang/tests/test_partner_contact_lang.py

@ -10,16 +10,11 @@ class TestPartnerContactLang(common.SavepointCase):
@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,
})
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 test_onchange_parent_id(self):
self.contact.parent_id = False
@ -27,12 +22,12 @@ class TestPartnerContactLang(common.SavepointCase):
self.assertIsNone(res)
self.contact.parent_id = self.partner
res = self.contact.onchange_parent_id()
self.assertEqual(res.get('value', {}).get('lang'), 'en_US')
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.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")
Loading…
Cancel
Save