Skip to content

[MOD][18.0] hr_employee_language: languages selection#1517

Open
mymage wants to merge 1 commit intoOCA:18.0from
mymage:18.0-mod-hr_employee_language
Open

[MOD][18.0] hr_employee_language: languages selection#1517
mymage wants to merge 1 commit intoOCA:18.0from
mymage:18.0-mod-hr_employee_language

Conversation

@mymage
Copy link
Copy Markdown
Member

@mymage mymage commented Oct 16, 2025

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

@mymage mymage changed the title [MOD][17.0] hr_employee_language: languages selection [MOD][18.0] hr_employee_language: languages selection Oct 16, 2025
@mymage mymage force-pushed the 18.0-mod-hr_employee_language branch 17 times, most recently from 2d3668b to 75eca3b Compare October 16, 2025 17:57
@mymage mymage marked this pull request as ready for review October 16, 2025 17:59
@mymage
Copy link
Copy Markdown
Member Author

mymage commented Oct 16, 2025

@dreispt @primes2h @TheMule71 plase review.
Little differences from #1512

Comment thread hr_employee_language/models/hr_employee_language.py Outdated
Comment thread hr_employee_language/models/hr_employee_language.py
Comment thread hr_employee_language/models/hr_employee_language.py Outdated
@mymage
Copy link
Copy Markdown
Member Author

mymage commented Nov 10, 2025

@dreispt Thanks for your notes; I'm not so skilled on coding so your suggestion is very appreciated. I'll give a look asap.

@mymage mymage force-pushed the 18.0-mod-hr_employee_language branch 6 times, most recently from 72cb747 to 356ce99 Compare November 15, 2025 10:16
@mymage mymage force-pushed the 18.0-mod-hr_employee_language branch 6 times, most recently from bfff99a to ab2bd18 Compare November 16, 2025 20:56
@mymage
Copy link
Copy Markdown
Member Author

mymage commented Nov 16, 2025

@dreispt Thanks to your comments I refactored the code. The only "strange" thing that I made is this:
self_data = self.env["hr.employee.language"].search([]) for record in self_data:
to have CodeCov at 100%: this because despite I create an element in hr.employee.language for test, here self is empty.

@mymage mymage force-pushed the 18.0-mod-hr_employee_language branch from ab2bd18 to 87e51ec Compare November 19, 2025 21:19
@mymage
Copy link
Copy Markdown
Member Author

mymage commented Jan 19, 2026

@dreispt @primes2h @TheMule71 ping. Thanks

1 similar comment
@mymage
Copy link
Copy Markdown
Member Author

mymage commented Feb 16, 2026

@dreispt @primes2h @TheMule71 ping. Thanks

Copy link
Copy Markdown
Contributor

@alexey-pelykh alexey-pelykh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving the language selection to use res.lang records. A couple of things to address:

  1. _compute_display_name() searches ALL hr.employee.language records (self.env["hr.employee.language"].search([])) instead of iterating over self. This is both a performance issue and semantically incorrect — compute methods should only set values on self records.

  2. 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).

  3. 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.

Comment thread hr_employee_language/models/hr_employee_language.py Outdated
Comment thread hr_employee_language/models/hr_employee_language.py
@mymage mymage force-pushed the 18.0-mod-hr_employee_language branch 5 times, most recently from c27e05b to a3f5258 Compare March 4, 2026 21:02
@mymage
Copy link
Copy Markdown
Member Author

mymage commented Mar 4, 2026

Thanks @alexey-pelykh for your suggestions. I updated the code, I hope in the right way.
If this is ok I will fix the other two.

@mymage mymage requested a review from alexey-pelykh March 4, 2026 21:07
Copy link
Copy Markdown
Contributor

@alexey-pelykh alexey-pelykh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update — the model code now correctly addresses all three issues from my previous review:

  • _compute_display_name iterates self instead 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 recordset

Since 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

@mymage mymage force-pushed the 18.0-mod-hr_employee_language branch 3 times, most recently from e2a5cd1 to b98d728 Compare March 25, 2026 10:56
@mymage mymage force-pushed the 18.0-mod-hr_employee_language branch from b98d728 to 38ee1ed Compare March 25, 2026 12:23
@mymage
Copy link
Copy Markdown
Member Author

mymage commented Mar 25, 2026

Ok @alexey-pelykh another thanks for your suggestions. Now I think it is ok but I don't understand the last red codecov

Copy link
Copy Markdown
Contributor

@alexey-pelykh alexey-pelykh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mymage mymage requested a review from dreispt April 3, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants