diff --git a/sbc_translation/__manifest__.py b/sbc_translation/__manifest__.py
index 19b3efcf8..b26be875b 100644
--- a/sbc_translation/__manifest__.py
+++ b/sbc_translation/__manifest__.py
@@ -28,21 +28,21 @@
# pylint: disable=C8101
{
"name": "SBC Translation Platform",
- "version": "13.0.1.0.0",
+ "version": "14.0.1.0.0",
"category": "Other",
"summary": "SBC - Translation Platform",
"sequence": 150,
"author": "Compassion CH",
"license": "AGPL-3",
"website": "https://www.compassion.ch",
- "depends": ["sbc_compassion", "partner_contact_birthdate"],
+ "depends": ["sbc_compassion", "partner_contact_birthdate", "website"],
"data": [
"security/ir_groups.xml",
"security/ir.model.access.csv",
"security/access_rules.xml",
"wizards/reply_to_comments_view.xml",
"data/mail_template.xml",
- "data/increment_translation_priority_cron.xml",
+ "data/update_translation_priority_cron.xml",
"data/website.xml",
"data/queue_job.xml",
"views/translation_user_view.xml",
diff --git a/sbc_translation/data/increment_translation_priority_cron.xml b/sbc_translation/data/update_translation_priority_cron.xml
similarity index 67%
rename from sbc_translation/data/increment_translation_priority_cron.xml
rename to sbc_translation/data/update_translation_priority_cron.xml
index 065b5e9c3..107e9dbb6 100644
--- a/sbc_translation/data/increment_translation_priority_cron.xml
+++ b/sbc_translation/data/update_translation_priority_cron.xml
@@ -1,12 +1,12 @@
-
-
- Increment translation priority
+
+
+ Update translation priority
ir.action.server
code
- model.increment_priority_cron()
+ model.update_translation_priority_cron()
1
weeks
-1
diff --git a/sbc_translation/data/website.xml b/sbc_translation/data/website.xml
index 6345a87d3..bbaf526b1 100644
--- a/sbc_translation/data/website.xml
+++ b/sbc_translation/data/website.xml
@@ -2,7 +2,7 @@
Translation Platform
- translate-test.compassion.ch
+ translate.compassion.ch
diff --git a/sbc_translation/models/correspondence.py b/sbc_translation/models/correspondence.py
index 0b03f3b4e..8dcf606b9 100644
--- a/sbc_translation/models/correspondence.py
+++ b/sbc_translation/models/correspondence.py
@@ -216,6 +216,31 @@ def process_letter(self):
letter.send_local_translate()
return True
+ def calculate_translation_priority(self):
+ """
+ Calculate the translation priority based on the scanned date or creation date.
+ :return: string
+ """
+
+ # Dynamically get the list of priority keys from the selection field definition
+ priorities = [
+ int(priority[0]) for priority in self._fields["translation_priority"].selection
+ ]
+
+ # Handle the case where scanned_date is not set
+ letter_date = (
+ self.scanned_date if self.scanned_date else self.create_date.date()
+ )
+
+ # Calculate the difference in weeks between the current date and the scanned date.
+ calculated_priority = min((fields.Date.today() - letter_date).days // 7, len(priorities) - 1)
+
+ # If the user had manually set a higher priority, we stick to it
+ if self.translation_priority and int(self.translation_priority) >= calculated_priority:
+ return self.translation_priority
+
+ return str(calculated_priority)
+
def send_local_translate(self):
"""
Sends the letter to the local translation platform.
@@ -230,9 +255,7 @@ def send_local_translate(self):
{
"state": "Global Partner translation queue",
"src_translation_lang_id": src_lang.id,
- "translation_priority": str(
- min((fields.Date.today() - self.scanned_date).days // 7, 4)
- ),
+ "translation_priority": self.calculate_translation_priority(),
"translation_status": "to do",
"translate_date": fields.Datetime.now(),
"translate_done": False,
@@ -447,7 +470,8 @@ def get_letter_info(self):
"status": self.translate("translation_issue")
or self.translate("translation_status")
or "None",
- "priority": self.translation_priority or "0",
+ "priority": self.translation_priority
+ or self._fields["translation_priority"].selection[0][0],
"title": self.sudo().name,
"source": self.src_translation_lang_id.name,
"target": self.translation_language_id.name,
@@ -499,19 +523,26 @@ def get_translated_elements(self):
return res
@api.model
- def increment_priority_cron(self):
+ def update_translation_priority_cron(self):
"""
- Increment priority of letters to translate, maximum
- priority is 4.
+ Update the priority of letters to translate if the letter is not already at the highest priority.
+ When the letter is already at the highest priority, it moves it to another suitable pool.
+ :return: None
"""
letters_to_translate = self.search(
[("translation_status", "not in", [False, "done"])]
)
+ # Update priority for each letters
for letter in letters_to_translate:
- old_priority = int(letter.translation_priority)
- if old_priority < 4:
- letter.translation_priority = str(old_priority + 1)
+
+ current_priority = letter.translation_priority
+ new_priority = letter.calculate_translation_priority()
+
+ if current_priority != new_priority:
+ letter.translation_priority = new_priority
+
+ # If the letter is already at the highest priority and has a fallback competence, move it to another pool
elif letter.translation_competence_id.fallback_competence_id:
letter.with_delay().move_pool()
diff --git a/sbc_translation/models/translation_competence.py b/sbc_translation/models/translation_competence.py
index 533c1c98b..7df87850f 100644
--- a/sbc_translation/models/translation_competence.py
+++ b/sbc_translation/models/translation_competence.py
@@ -35,13 +35,13 @@ class TranslationCompetence(models.Model):
"correspondence", string="Current letters", compute="_compute_current_letters"
)
number_current_letters = fields.Integer(
- compute="_compute_current_letters", store=True
+ compute="_compute_current_letters", store=True, compute_sudo=False
)
skill_ids = fields.One2many(
"translation.user.skill", "competence_id", "Translator skills"
)
number_translators = fields.Integer(
- compute="_compute_number_translators", store=True
+ compute="_compute_number_translators", store=True, compute_sudo=False
)
number_active_translators = fields.Integer(compute="_compute_number_translators")
diff --git a/sbc_translation/models/translation_user.py b/sbc_translation/models/translation_user.py
index e70cf21e8..afca5bd8e 100644
--- a/sbc_translation/models/translation_user.py
+++ b/sbc_translation/models/translation_user.py
@@ -42,7 +42,7 @@ class TranslationUser(models.Model):
search_competence_id = fields.Many2one(
"translation.competence", help="Utility field only used for the search view"
)
- avatar = fields.Binary(related="partner_id.image_small")
+ avatar = fields.Binary(related="partner_id.image_128")
_sql_constraints = [
("unique_translator", "unique(user_id)", "This translator already exists.")
diff --git a/sbc_translation/views/correspondence_view.xml b/sbc_translation/views/correspondence_view.xml
index 950746815..5a23dd002 100644
--- a/sbc_translation/views/correspondence_view.xml
+++ b/sbc_translation/views/correspondence_view.xml
@@ -142,7 +142,7 @@
-
+