-
-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] partner_country_lang: Migration to 17.0
TT54939
- Loading branch information
1 parent
cbb10dc
commit 8697a6f
Showing
3 changed files
with
11 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,15 @@ | ||
# Copyright 2022 Tecnativa - Víctor Martínez | ||
# Copyright 2022-2025 Tecnativa - Víctor Martínez | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
@api.onchange("country_id") | ||
def _onchange_country_id(self): | ||
result = super()._onchange_country_id() | ||
if self.country_id.lang: | ||
self.lang = self.country_id.lang | ||
return result | ||
lang = fields.Selection(compute="_compute_lang") | ||
|
||
def _adjust_lang_by_country(self, vals): | ||
"""Adjust vals dictionary for adding the language of the country | ||
if no one is included in it, but country is. | ||
""" | ||
if vals.get("country_id") and "lang" not in vals: | ||
country = self.env["res.country"].browse(vals["country_id"]) | ||
if country.lang: | ||
vals["lang"] = country.lang | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
"""Add lang if the partner is created with a country through code | ||
and no language is specified. | ||
""" | ||
for vals in vals_list: | ||
self._adjust_lang_by_country(vals) | ||
return super().create(vals_list) | ||
|
||
def write(self, vals): | ||
"""Change language if a country is written through code and no | ||
one is modified as well. | ||
""" | ||
self._adjust_lang_by_country(vals) | ||
return super().write(vals) | ||
@api.depends("country_id") | ||
def _compute_lang(self): | ||
for item in self: | ||
item.lang = item.country_id.lang or item.lang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters