[MOD][18.0] hr_employee_language: languages selection#1517
[MOD][18.0] hr_employee_language: languages selection#1517
Conversation
2d3668b to
75eca3b
Compare
|
@dreispt @primes2h @TheMule71 plase review. |
|
@dreispt Thanks for your notes; I'm not so skilled on coding so your suggestion is very appreciated. I'll give a look asap. |
72cb747 to
356ce99
Compare
bfff99a to
ab2bd18
Compare
|
@dreispt Thanks to your comments I refactored the code. The only "strange" thing that I made is this: |
ab2bd18 to
87e51ec
Compare
|
@dreispt @primes2h @TheMule71 ping. Thanks |
1 similar comment
|
@dreispt @primes2h @TheMule71 ping. Thanks |
alexey-pelykh
left a comment
There was a problem hiding this comment.
Thanks for improving the language selection to use res.lang records. A couple of things to address:
-
_compute_display_name()searches ALLhr.employee.languagerecords (self.env["hr.employee.language"].search([])) instead of iterating overself. This is both a performance issue and semantically incorrect — compute methods should only set values onselfrecords. -
The compute method returns a list of tuples, but Odoo compute methods don't use return values — they assign to
self.display_name(which you do, but the return is dead code). -
Using
_()on selection keys (_("%(code)s", code=lang.code)) translates the code itself, which shouldn't be translated — codes are stable identifiers.
Happy to re-review once updated.
c27e05b to
a3f5258
Compare
|
Thanks @alexey-pelykh for your suggestions. I updated the code, I hope in the right way. |
alexey-pelykh
left a comment
There was a problem hiding this comment.
Thanks for the update — the model code now correctly addresses all three issues from my previous review:
_compute_display_nameiteratesselfinstead of searching all records- No more dead return value
- No more
_()on language codes
However, the test for _compute_display_name doesn't actually exercise the compute method:
self.env["hr.employee.language"].create({...}) # result not stored
self.env["hr.employee.language"]._compute_display_name() # called on empty recordsetSince the create result isn't assigned, _compute_display_name() runs on an empty recordset — the loop body never executes. This is likely why codecov is failing. The fix:
record = self.env["hr.employee.language"].create({
"name": "en_GB",
"employee_id": self.env["hr.employee"].create({"name": "Test"}).id,
})
self.assertEqual(record.display_name, "English (UK)")Accessing record.display_name triggers the compute automatically — no need to call it explicitly.
Co-Reviewed-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
e2a5cd1 to
b98d728
Compare
b98d728 to
38ee1ed
Compare
|
Ok @alexey-pelykh another thanks for your suggestions. Now I think it is ok but I don't understand the last red codecov |
alexey-pelykh
left a comment
There was a problem hiding this comment.
Thanks for the update @mymage — the test now correctly exercises the compute method. All feedback from both reviews is addressed.
Regarding the codecov/project failure: this check measures overall repository coverage, not your PR's coverage. Your codecov/patch check passes, meaning your new code is adequately covered. The codecov/project failure is a pre-existing coverage gap in the repo — not something you need to fix here.
Co-Reviewed-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
As in #1486
Changes the source of language list moving it from the res.lang.csv file to res.lang model.
In this way if you add a language at runtime it will be immediately available.
Added _compute_display_name (ex name_get) to show language name instead language code on selection or m2o widget