Skip to content

Commit 921aff6

Browse files
sbejaouimoylop260
authored andcommitted
[ADD] deprecated-name-get: name_get deprecated since v17
'name_get' is deprecated since v17. More info at odoo/odoo#122085.
1 parent 58443c4 commit 921aff6

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ bad-builtin-groupby | Used builtin function `itertools.groupby`. Prefer `odoo.to
2626
category-allowed | Category "%s" not allowed in manifest file. | C8114
2727
consider-merging-classes-inherited | Consider merging classes inherited to "%s" from %s. | R8180
2828
context-overridden | Context overridden using dict. Better using kwargs `with_context(**%s)` or `with_context(key=value)` | W8121
29+
deprecated-name-get | 'name_get' is deprecated. Use '_compute_display_name' instead. More info at https://github.com/odoo/odoo/pull/122085. | E8146
2930
deprecated-odoo-model-method | %s has been deprecated by Odoo. Please look for alternatives. | W8160
3031
development-status-allowed | Manifest key development_status "%s" not allowed. Use one of: %s. | C8111
3132
except-pass | pass into block except. If you really need to use the pass consider logging that exception | W8138
@@ -176,6 +177,10 @@ Checks valid only for odoo <= 13.0
176177
- https://github.com/OCA/pylint-odoo/blob/v9.3.2/testing/resources/test_repo/broken_module/models/broken_model.py#L197 Context overridden using dict. Better using kwargs `with_context(**ctx)` or `with_context(key=value)`
177178
- https://github.com/OCA/pylint-odoo/blob/v9.3.2/testing/resources/test_repo/broken_module/models/broken_model.py#L199 Context overridden using dict. Better using kwargs `with_context(**ctx2)` or `with_context(key=value)`
178179

180+
* deprecated-name-get
181+
182+
- https://github.com/OCA/pylint-odoo/blob/v9.3.2/testing/resources/test_repo/twelve_module/models.py#L7 'name_get' is deprecated. Use '_compute_display_name' instead. More info at https://github.com/odoo/odoo/pull/122085.
183+
179184
* deprecated-odoo-model-method
180185

181186
- https://github.com/OCA/pylint-odoo/blob/v9.3.2/testing/resources/test_repo/broken_module/models/broken_model.py#L94 fields_view_get has been deprecated by Odoo. Please look for alternatives.

src/pylint_odoo/checkers/odoo_addons.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@
190190
"manifest-behind-migrations",
191191
"Update your manifest version, otherwise the migration script won't run",
192192
),
193+
"E8146": (
194+
"'name_get' is deprecated. Use '_compute_display_name' instead. More info at https://github.com/odoo/odoo/pull/122085.",
195+
"deprecated-name-get",
196+
CHECK_DESCRIPTION,
197+
),
193198
"F8101": ('File "%s": "%s" not found.', "resource-not-exist", CHECK_DESCRIPTION),
194199
"R8101": (
195200
"`odoo.exceptions.Warning` is a deprecated alias to `odoo.exceptions.UserError` "
@@ -580,6 +585,7 @@ class OdooAddons(OdooBaseChecker, BaseChecker):
580585
},
581586
"no-raise-unlink": {"odoo_minversion": "15.0"},
582587
"prefer-env-translation": {"odoo_minversion": "18.0"},
588+
"deprecated-name-get": {"odoo_minversion": "17.0"},
583589
}
584590

585591
def __init__(self, linter: PyLinter):
@@ -1244,7 +1250,11 @@ def check_deprecated_odoo_method(self, node: NodeNG) -> bool:
12441250
return node.name in self._deprecated_odoo_methods
12451251

12461252
@utils.only_required_for_messages(
1247-
"method-required-super", "prohibited-method-override", "missing-return", "deprecated-odoo-model-method"
1253+
"method-required-super",
1254+
"prohibited-method-override",
1255+
"missing-return",
1256+
"deprecated-odoo-model-method",
1257+
"deprecated-name-get",
12481258
)
12491259
def visit_functiondef(self, node):
12501260
"""Check that `api.one` and `api.multi` decorators not exists together
@@ -1256,7 +1266,8 @@ def visit_functiondef(self, node):
12561266

12571267
if self.is_odoo_message_enabled("deprecated-odoo-model-method") and self.check_deprecated_odoo_method(node):
12581268
self.add_message("deprecated-odoo-model-method", node=node, args=(node.name,))
1259-
1269+
if self.is_odoo_message_enabled("deprecated-name-get") and node.name == "name_get":
1270+
self.add_message("deprecated-name-get", node=node)
12601271
if node.name in self.linter.config.method_required_super:
12611272
calls = [
12621273
call_func.func.name

testing/resources/test_repo/twelve_module/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33

44
class TwelveModel(models.Model):
5-
_name = 'twelve.model'
5+
_name = "twelve.model"
6+
7+
def name_get(self):
8+
# do staff
9+
return super().name_get()

tests/test_main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"bad-builtin-groupby": 2,
2525
"consider-merging-classes-inherited": 2,
2626
"context-overridden": 3,
27+
"deprecated-name-get": 1,
2728
"development-status-allowed": 1,
2829
"except-pass": 3,
2930
"external-request-timeout": 51,
@@ -159,6 +160,7 @@ def test_25_checks_excluding_by_odoo_version(self):
159160
"translation-too-few-args",
160161
"translation-too-many-args",
161162
"translation-unsupported-format",
163+
"deprecated-name-get",
162164
}
163165
self.default_extra_params += ["--valid-odoo-versions=13.0"]
164166
pylint_res = self.run_pylint(self.paths_modules)
@@ -177,6 +179,7 @@ def test_35_checks_emiting_by_odoo_version(self):
177179
expected_errors = self.expected_errors.copy()
178180
expected_errors.update({"manifest-version-format": 6})
179181
excluded_msgs = {
182+
"deprecated-name-get",
180183
"deprecated-odoo-model-method",
181184
"no-raise-unlink",
182185
"prefer-env-translation",

0 commit comments

Comments
 (0)