-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Exclude missing-return checks for computed methods
Fixes #450. Compute methods are not supposed to return any value, even if there is a super() in it, since super() shouldn't return anything either. The only reliable way to ensure a field is computed is if has been declared in the same python module (file), so this exclusion only applies to a limited set of cases.
- Loading branch information
Showing
2 changed files
with
43 additions
and
11 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
16 changes: 16 additions & 0 deletions
16
testing/resources/test_repo/test_module/missing-return-compute.py
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 'missing-return' not necessary inside compute methods, even if super is called | ||
# we can only make sure the method is used to compute fields if said fields/methods | ||
# are declared in the same python module (file) | ||
from odoo import api, fields, models | ||
|
||
|
||
class MissingReturnCompute(models.Model): | ||
|
||
discount = fields.Float(compute="_compute_discount", store=True) | ||
|
||
@api.depends("order_id", "order_id.general_discount") | ||
def _compute_discount(self): | ||
if hasattr(super(), "_compute_discount"): | ||
super()._compute_discount() | ||
for line in self: | ||
line.discount = line.order_id.general_discount |