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.

29 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 (http://www.gnu.org/licenses/agpl.html).
  4. from odoo 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([("id", "child_of", self.ids), ("lang", "=", False),])
  13. if childs:
  14. childs.write({"lang": vals["lang"]})
  15. return res
  16. @api.onchange("parent_id")
  17. def onchange_parent_id(self):
  18. """Change language if the parent company changes and there's no
  19. language defined yet"""
  20. res = super(ResPartner, self).onchange_parent_id()
  21. if self.parent_id and self.parent_id != self and not self.lang:
  22. val = res.setdefault("value", {})
  23. val["lang"] = self.parent_id.lang
  24. return res