-
Notifications
You must be signed in to change notification settings - Fork 50
[T3371] FIX: don't queue B2S letters when the language detector has no opinion #2160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NoeBerdoz
wants to merge
3
commits into
14.0
Choose a base branch
from
T3371-b2s-letters-wrongly-queued
base: 14.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
| ############################################################################## | ||
| # | ||
| # Copyright (C) 2026 Compassion CH (http://www.compassion.ch) | ||
| # Releasing children from poverty in Jesus' name | ||
| # | ||
| # The licence is in the file __manifest__.py | ||
| # | ||
| ############################################################################## | ||
|
|
||
| from langdetect import DetectorFactory | ||
|
|
||
| from odoo.tests import TransactionCase | ||
|
|
||
| SHORT_CAPTION = "Salut, C'est Martial. Juste un bonjour!" | ||
| LONG_ENGLISH = ( | ||
| "Dear sponsor, thank you very much for your letter and for the gift you " | ||
| "sent me. I am doing well at school. God bless you." | ||
| ) | ||
| LONG_SWAHILI = ( | ||
| "Habari yako mlezi wangu, asante sana kwa barua yako na zawadi " | ||
| "uliyonitumia. Mimi ni mzima wa afya. Mungu akubariki sana." | ||
| ) | ||
|
|
||
|
|
||
| class TestLetterLanguageVerdict(TransactionCase): | ||
| """Pins the verdict the B2S translation gate is built on (T3339 / T3371). | ||
|
|
||
| Covers `_letter_language_verdict` only. `_sponsor_can_read_letter` needs a | ||
| persisted letter, because `supporter_languages_ids` is related to | ||
| `partner_id.spoken_lang_ids` and comes back NewId-wrapped on an in-memory | ||
| record, and building one needs `BaseSponsorshipTest`, whose `setUpClass` is | ||
| currently broken for all 13 test classes that use it. | ||
| """ | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| # langdetect samples randomly and runs unseeded in production, so the | ||
| # same text occasionally misses the confidence threshold (~0.1% of runs | ||
| # for the English text below). Pin the seed here so these tests exercise | ||
| # verdict handling rather than detector luck. | ||
| previous_seed = DetectorFactory.seed | ||
| DetectorFactory.seed = 0 | ||
| self.addCleanup(setattr, DetectorFactory, "seed", previous_seed) | ||
|
|
||
| def _letter(self, text, field="translated_text"): | ||
| return self.env["correspondence"].new( | ||
| {"page_ids": [(0, 0, {"paragraph_ids": [(0, 0, {field: text})]})]} | ||
| ) | ||
|
|
||
| def test_short_text_gives_no_opinion(self): | ||
| """Photo captions are too short to judge: the gate must fall back.""" | ||
| language, has_opinion = self._letter(SHORT_CAPTION)._letter_language_verdict() | ||
| self.assertFalse(language) | ||
| self.assertFalse(has_opinion) | ||
|
|
||
| def test_long_text_is_detected(self): | ||
| language, has_opinion = self._letter(LONG_ENGLISH)._letter_language_verdict() | ||
| self.assertTrue(has_opinion) | ||
| self.assertEqual( | ||
| language, self.env.ref("advanced_translation.lang_compassion_english") | ||
| ) | ||
|
|
||
| def test_long_untranslatable_text_still_gives_an_opinion(self): | ||
| """A language we do not handle is an answer, not an absence of one. | ||
|
|
||
| Without this the letter falls back to the field-office stamp and can | ||
| reach the sponsor untranslated (T3339). | ||
| """ | ||
| letter = self._letter(LONG_SWAHILI, field="original_text") | ||
| language, has_opinion = letter._letter_language_verdict() | ||
| self.assertFalse(language) | ||
| self.assertTrue(has_opinion) | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.