Skip to content

Commit

Permalink
[MIG] sbc_translation: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NoeBerdoz committed Feb 23, 2024
1 parent f0523c5 commit 144615d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 22 deletions.
6 changes: 3 additions & 3 deletions sbc_translation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data noupdate="1">
<record id="increment_priority_cron" model="ir.cron">
<field name="name">Increment translation priority</field>
<data>
<record id="update_translation_priority_cron" model="ir.cron">
<field name="name">Update translation priority</field>
<field name="model_id" ref="model_correspondence"/>
<field name="type">ir.action.server</field>
<field name="state">code</field>
<field name="code">model.increment_priority_cron()</field>
<field name="code">model.update_translation_priority_cron()</field>
<field name="interval_number">1</field>
<field name="interval_type">weeks</field>
<field name="numbercall">-1</field>
Expand Down
2 changes: 1 addition & 1 deletion sbc_translation/data/website.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<data noupdate="1">
<record id="translation_website" model="website">
<field name="name">Translation Platform</field>
<field name="domain">translate-test.compassion.ch</field>
<field name="domain">translate.compassion.ch</field>
</record>
</data>
</odoo>
51 changes: 41 additions & 10 deletions sbc_translation/models/correspondence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions sbc_translation/models/translation_competence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion sbc_translation/models/translation_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion sbc_translation/views/correspondence_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<field name="translation_url"/>
<field name="translation_priority_name"/>
<field name="unread_comments"/>
<progressbar field="translation_priority_name" colors="{&quot;High&quot;: &quot;success&quot;, &quot;Very high&quot;: &quot;warning&quot;, &quot;Urgent&quot;: &quot;danger&quot;}"/>
<progressbar field="translation_priority" colors='{"2": "success", "3": "warning", "4": "danger"}'/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_card oe_kanban_global_click #{(record.unread_comments.raw_value || record.translation_issue.raw_value) ? 'oe_kanban_color_1' : ''}">
Expand Down

0 comments on commit 144615d

Please sign in to comment.