You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  3. # Copyright 2017 Vicent Cubells <vicent.cubells@tecnativa.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp import api, models
  6. class ResPartner(models.Model):
  7. _inherit = 'res.partner'
  8. @api.multi
  9. def write(self, vals):
  10. """Propagate a language change in the partner to the child contacts."""
  11. res = super(ResPartner, self).write(vals)
  12. if vals.get('lang'):
  13. childs = self.search([
  14. ('id', 'child_of', self.ids),
  15. ('lang', '=', False),
  16. ])
  17. if childs:
  18. childs.write({'lang': vals['lang']})
  19. return res
  20. @api.onchange('parent_id')
  21. def onchange_parent_id(self):
  22. """Change language if the parent company changes and there's no
  23. language defined yet"""
  24. res = super(ResPartner, self).onchange_parent_id()
  25. if self.parent_id and self.parent_id != self and not self.lang:
  26. val = res.setdefault('value', {})
  27. val['lang'] = self.parent_id.lang
  28. return res