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.

38 lines
1.3 KiB

  1. # Copyright 2016-2020 Tecnativa - Pedro M. Baeza
  2. # Copyright 2017 Tecnativa - Vicent Cubells
  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. A special case is made for virtual records, where default lang value
  20. is assigned at startup, so we always overwrite language in that case.
  21. """
  22. res = super(ResPartner, self).onchange_parent_id()
  23. if (
  24. self.parent_id.lang
  25. and (
  26. not self.lang
  27. or (isinstance(self.id, models.NewId) and not self._origin)
  28. )
  29. and self.parent_id.lang != self.lang
  30. ):
  31. self.lang = self.parent_id.lang
  32. return res