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.

41 lines
1.3 KiB

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