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.

44 lines
1.5 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, fields, models
  5. class ResPartner(models.Model):
  6. _inherit = "res.partner"
  7. # HACK https://github.com/odoo/odoo/issues/53738
  8. # TODO Remove when fixed
  9. partner_lang = fields.Selection(
  10. string="Partner lang",
  11. related="lang",
  12. readonly=True,
  13. )
  14. def write(self, vals):
  15. """Propagate a language change in the partner to the child contacts."""
  16. res = super(ResPartner, self).write(vals)
  17. if vals.get("lang"):
  18. childs = self.search([("id", "child_of", self.ids), ("lang", "=", False)])
  19. if childs:
  20. childs.write({"lang": vals["lang"]})
  21. return res
  22. @api.onchange("parent_id")
  23. def onchange_parent_id(self):
  24. """Change language if the parent company changes and there's no
  25. language defined yet.
  26. A special case is made for virtual records, where default lang value
  27. is assigned at startup, so we always overwrite language in that case.
  28. """
  29. res = super(ResPartner, self).onchange_parent_id()
  30. if (
  31. self.parent_id.lang and (
  32. not self.lang or
  33. (isinstance(self.id, models.NewId) and not self._origin)
  34. ) and self.parent_id.lang != self.lang
  35. ):
  36. self.lang = self.parent_id.lang
  37. return res