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.

42 lines
1.4 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_address(self, use_parent_address, parent_id):
  21. """Change language if the parent company changes and there's no
  22. language defined yet"""
  23. res = super(ResPartner, self).onchange_address(
  24. use_parent_address, parent_id)
  25. if parent_id and self.parent_id.id != parent_id and not self.lang:
  26. parent = self.browse(parent_id)
  27. val = res.setdefault('value', {})
  28. val['lang'] = parent.lang
  29. return res
  30. @api.multi
  31. @api.onchange('lang')
  32. def onchange_lang(self):
  33. if self.lang:
  34. childs = self.child_ids.filtered(lambda x: not x.lang)
  35. for child in childs:
  36. child.lang = self.lang