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.

32 lines
1.1 KiB

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