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.

40 lines
1.3 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, 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. res = super(ResPartner, self).onchange_parent_id()
  27. if (
  28. self.parent_id
  29. and self.parent_id != self
  30. and not self.lang
  31. and self.parent_id.lang
  32. ):
  33. self.lang = self.parent_id.lang
  34. return res