Skip to content

Commit

Permalink
Merge pull request #1936 from CompassionCH/T116-add-letter-comments-l…
Browse files Browse the repository at this point in the history
…ogs-on-chatter

T1156 add letter comments logs on chatter
  • Loading branch information
NoeBerdoz authored Sep 3, 2024
2 parents 5d5a7dc + 46ef390 commit db9c0f2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 14 deletions.
29 changes: 29 additions & 0 deletions sbc_translation/data/mail_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,35 @@
</field>
</record>

<template id="translation_issue_log">
<p>
<b>Issue type</b>:
<span t-field="record.translation_issue" />
</p>
<span t-field="record.translation_issue_comments" />
</template>

<template id="translation_comments_update">
<p>
Comments updated
</p>
<ul>
<li t-foreach="comments" t-as="comment">
Page
<t t-esc="comment['page_index']"/>
paragraph
<t t-esc="comment['paragraph_index']"/>:
<t t-esc="comment['old']" />
<span
class="o_Message_trackingValueSeparator o_Message_trackingValueItem fa fa-long-arrow-right"
title="Changed"
role="img"
/>
<t t-esc="comment['new']" />
</li>
</ul>
</template>

<template id="comments_reply">
<p>Dear <span t-field="object.new_translator_id.partner_id.name" />,</p>
<p
Expand Down
63 changes: 49 additions & 14 deletions sbc_translation/models/correspondence.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def get_translation_issue_list(self):
@api.onchange("new_translator_id")
def onchange_new_translator_id(self):
"""
When a translator is set, the letter should always be on "in progress" status to ensure that the letter can
be found under the translator's saved letters in the Translation Platform.
When a translator is set, the letter should always be on "in progress" status to ensure that the letter can
be found under the translator's saved letters in the Translation Platform.
"""
if self.new_translator_id:
self.translation_status = "in progress"
Expand Down Expand Up @@ -233,7 +233,8 @@ def calculate_translation_priority(self):

# Dynamically get the list of priority keys from the selection field definition
priorities = [
int(priority[0]) for priority in self._fields["translation_priority"].selection
int(priority[0])
for priority in self._fields["translation_priority"].selection
]

# Handle the case where scanned_date is not set
Expand All @@ -242,10 +243,15 @@ def calculate_translation_priority(self):
)

# 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)
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:
if (
self.translation_priority
and int(self.translation_priority) >= calculated_priority
):
return self.translation_priority

return str(calculated_priority)
Expand Down Expand Up @@ -308,12 +314,18 @@ def raise_translation_issue(self, issue_type, body_html):
TP API for translator to raise an issue with the letter
"""
self.ensure_one()

self.write(
{"translation_issue": issue_type, "translation_issue_comments": body_html}
)
self.assign_supervisor()
# template = self.env.ref("sbc_translation.translation_issue_notification").sudo()
# self.sudo().message_post_with_template(template.id, author_id=self.env.user.partner_id.id)

html = self.env["ir.qweb"]._render(
"sbc_translation.translation_issue_log", {"record": self}
)

self._message_log(body=html)

return True

def reply_to_comments(self, body_html):
Expand Down Expand Up @@ -344,10 +356,9 @@ def reply_to_issue(self, body_html):
"reply": body_html,
},
)
return self.write({
'translation_issue': False,
'translation_issue_comments': False
})
return self.write(
{"translation_issue": False, "translation_issue_comments": False}
)

def mark_comments_read(self):
return self.write({"unread_comments": False})
Expand Down Expand Up @@ -377,6 +388,7 @@ def save_translation(self, letter_elements, translator_id=None):
page_index = 0
paragraph_index = 0
current_page = self.page_ids[page_index]
comments_updates = []
if not translator_id:
# Don't overwrite current translator if any.
if self.new_translator_id:
Expand All @@ -389,6 +401,7 @@ def save_translation(self, letter_elements, translator_id=None):
"new_translator_id": translator_id,
"translation_status": "in progress",
}

for element in letter_elements:
if element.get("type") == "pageBreak":
page_index += 1
Expand All @@ -404,10 +417,33 @@ def save_translation(self, letter_elements, translator_id=None):
if self.translation_language_id.code_iso == "eng":
# Copy translation text into english text field
paragraph_vals["english_text"] = element.get("content")

if (
current_page.paragraph_ids[paragraph_index].comments
!= paragraph_vals["comments"]
):
comments_updates.append(
{
"page_index": page_index + 1,
"paragraph_index": paragraph_index + 1,
"old": current_page.paragraph_ids[paragraph_index].comments,
"new": paragraph_vals["comments"],
}
)

current_page.paragraph_ids[paragraph_index].write(paragraph_vals)
paragraph_index += 1
if element.get("comments"):
letter_vals["unread_comments"] = True

if len(comments_updates) > 0:
html = self.env["ir.qweb"]._render(
"sbc_translation.translation_comments_update",
{"comments": comments_updates},
)

self._message_log(body=html)

self.write(letter_vals)
return True

Expand Down Expand Up @@ -540,8 +576,8 @@ def get_translated_elements(self):
"content": paragraph.translated_text,
"comments": paragraph.comments,
"source": paragraph.english_text
or paragraph.original_text
or "",
or paragraph.original_text
or "",
}
)
if i < len(self.page_ids) - 1:
Expand All @@ -566,7 +602,6 @@ def update_translation_priority_cron(self):

# Update priority for each letters
for letter in letters_to_translate:

current_priority = letter.translation_priority
new_priority = letter.calculate_translation_priority()

Expand Down

0 comments on commit db9c0f2

Please sign in to comment.