Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project_worksheet/data/mail_template_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="name">Worksheet: Approval Request</field>
<field name="model_id" ref="project_worksheet.model_project_worksheet"/>
<field name="subject">Worksheet ${object.name} - project ${object.project_id.name} - approval required</field>
<field name="email_to">${object.partner_approver_id.email}</field>
<field name="email_to">${object.partner_approver_id.email},${object.supervisor_id.work_email}</field>
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px; font-size: 13px; color: #444444;">
<p style="margin: 0px 0px 16px 0px;">
Expand Down
34 changes: 30 additions & 4 deletions project_worksheet/models/project_worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,12 @@ def _generate_timesheets_if_empty(self):
self._generate_timesheets()

def _send_approval_email(self):
template = self.env.ref("project_worksheet.email_template_worksheet_approval")
template.send_mail(self.id, force_send=True)
template_id = self.env.ref("project_worksheet.email_template_worksheet_approval").id
self.message_post_with_template(
template_id,
composition_mode="comment",
message_type="comment",
)

def _get_remind_client_action(self):
template = self.env.ref("project_worksheet.email_template_worksheet_approval")
Expand Down Expand Up @@ -239,9 +243,31 @@ def _confirm_worksheet(self, source):
self._send_confirmation_email()

def _send_confirmation_email(self):
template = self.env.ref("project_worksheet.email_template_worksheet_confirmed")
template_id = self._get_confirmation_template_id()
for worksheet in self:
template.send_mail(worksheet.id, force_send=True)
worksheet._post_confirmation_message(template_id)

def _get_confirmation_template_id(self):
return self.env.ref("project_worksheet.email_template_worksheet_confirmed").id

def _post_confirmation_message(self, template_id):
# Post the message using the appropriate user context
record = self._get_mail_sender_record()
record.message_post_with_template(
template_id,
composition_mode="comment",
message_type="comment",
)

def _get_mail_sender_record(self):
# Use root user (OdooBot) if the client is the one confirming the worksheet
if self.approval_source == "client":
return self._get_root_user_record()
return self

def _get_root_user_record(self):
root_user = self.env.ref("base.user_root")
return self.with_user(root_user)

def _generate_timesheets(self):
timesheet_model = self.env["account.analytic.line"]
Expand Down
Loading