Skip to content

Commit

Permalink
[IMP] project_task_subtask: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Medeeet committed Oct 28, 2024
1 parent 907f46d commit 4098584
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 132 deletions.
111 changes: 13 additions & 98 deletions project_task_subtask/models/project_task_subtask.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from markupsafe import Markup, escape
from markupsafe import Markup

from odoo import api, fields, models
from odoo.exceptions import UserError
Expand All @@ -12,10 +12,6 @@
}


# def escape(s):
# return str(html_escape(s))


class ProjectTaskSubtask(models.Model):
_name = "project.task.subtask"
_description = "Subtask"
Expand Down Expand Up @@ -47,17 +43,18 @@ class ProjectTaskSubtask(models.Model):

def _compute_recolor(self):
for record in self:
if self.env.user == record.user_id and record.state == "todo":
record.recolor = True
else:
record.recolor = False
record.recolor = (
True
if self.env.user == record.user_id and record.state == "todo"
else False
)

def _compute_hide_button(self):
for record in self:
if self.env.user not in [record.reviewer_id, record.user_id]:
record.hide_button = True
else:
record.hide_button = False
record.hide_button = self.env.user not in [
record.reviewer_id,
record.user_id,
]

def _compute_reviewer_id(self):
for record in self:
Expand Down Expand Up @@ -128,7 +125,6 @@ def change_state_waiting(self):

class Task(models.Model):
_inherit = "project.task"

subtask_ids = fields.One2many("project.task.subtask", "task_id", "Subtask")
kanban_subtasks = fields.Html(compute="_compute_kanban_subtasks")
default_user = fields.Many2one("res.users", compute="_compute_default_user")
Expand Down Expand Up @@ -246,88 +242,7 @@ def send_subtask_email(
subtask_user_id,
old_name=None,
):
for r in self:
body = Markup("") # Initialize body as a Markup object
reviewer = self.env["res.users"].browse(subtask_reviewer_id)
user = self.env["res.users"].browse(subtask_user_id)
state = Markup(SUBTASK_STATES[subtask_state]) # Keep state as Markup

# Set state color based on subtask state
if subtask_state == "done":
state = Markup('<span style="color:#080">' + str(state) + "</span>")
elif subtask_state == "todo":
state = Markup('<span style="color:#A00">' + str(state) + "</span>")
elif subtask_state == "cancelled":
state = Markup('<span style="color:#777">' + str(state) + "</span>")
elif subtask_state == "waiting":
state = Markup('<span style="color:#b818ce">' + str(state) + "</span>")

partner_ids = []

if user == self.env.user and reviewer == self.env.user:
body = Markup(
"<p><strong>"
+ str(state)
+ "</strong>: "
+ escape(subtask_name)
+ "</p>"
)
elif self.env.user == reviewer:
body = Markup(
"<p>"
+ escape(user.name)
+ ", <br><strong>"
+ str(state)
+ "</strong>: "
+ escape(subtask_name)
+ "</p>"
)
partner_ids = [user.partner_id.id]
elif self.env.user == user:
body = Markup(
"<p>" + escape(reviewer.name) + ', <em style="color:#999">'
"I updated checklist item assigned to me:</em> <br><strong>"
+ str(state)
+ "</strong>: "
+ escape(subtask_name)
+ "</p>"
)
partner_ids = [reviewer.partner_id.id]
else:
body = Markup(
"<p>"
+ escape(user.name)
+ ", "
+ escape(reviewer.name)
+ ', <em style="color:#999">I updated checklist item, now its assigned to '
+ escape(user.name)
+ ": </em> <br><strong>"
+ str(state)
+ "</strong>: "
+ escape(subtask_name)
+ "</p>"
)
partner_ids = [user.partner_id.id, reviewer.partner_id.id]

if old_name:
body += Markup(
'<br><em style="color:#999">Updated from</em><br><strong>'
+ str(state)
+ "</strong>: "
+ escape(old_name)
+ "</p>"
)
else:
body += Markup("</p>")

r.message_post(
message_type="comment",
body=body,
partner_ids=partner_ids,
)
state = Markup(SUBTASK_STATES[subtask_state])

def copy(self, default=None):
task = super(Task, self).copy(default)
for subtask in self.subtask_ids:
subtask.copy({"task_id": task.id, "state": subtask.state})
return task
if subtask_state == "done":
state = Markup('<span style="color:#080')
68 changes: 34 additions & 34 deletions project_task_subtask/views/project_task_subtask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,41 @@
</field>
</record>
<record id="view_task_kanban_subtasks" model="ir.ui.view">
<field name="name">project.task.kanban.subtasks</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_kanban" />
<field name="arch" type="xml">
<xpath expr="//field[@name ='tag_ids']" position="after">
<field name="completion" invisible="1" />
<field name="subtask_ids" invisible="1" />
<field name="kanban_subtasks" invisible="1" />
<field name="completion_xml" invisible="1" />
</xpath>
<xpath expr="//div[hasclass('o_kanban_record_bottom')]" position="before">
<div>
<t t-raw="record.completion_xml.raw_value" />
<t t-raw="record.kanban_subtasks.raw_value" />
</div>
</xpath>
</field>
</record>
<field name="name">project.task.kanban.subtasks</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_kanban" />
<field name="arch" type="xml">
<xpath expr="//field[@name ='tag_ids']" position="after">
<field name="completion" invisible="1" />
<field name="subtask_ids" invisible="1" />
<field name="kanban_subtasks" invisible="1" />
<field name="completion_xml" invisible="1" />
</xpath>
<xpath expr="//div[hasclass('o_kanban_record_bottom')]" position="before">
<div>
<t t-raw="record.completion_xml.raw_value" />
<t t-raw="record.kanban_subtasks.raw_value" />
</div>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="view_id">
<field name="name">project.task.subtask</field>
<field name="model">project.task.subtask</field>
<field name="arch" type="xml">
<form string="Subtask Message">
<sheet>
<group>
<field name="name" />
<field name="user_id" />
<field name="state" />
<field name="task_id" />
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_id">
<field name="name">project.task.subtask</field>
<field name="model">project.task.subtask</field>
<field name="arch" type="xml">
<form string="Subtask Message">
<sheet>
<group>
<field name="name" />
<field name="user_id" />
<field name="state" />
<field name="task_id" />
</group>
</sheet>
</form>
</field>
</record>

<record id="project_task_subtask_view_search" model="ir.ui.view">
<field name="name">project.task.subtask.filter</field>
Expand Down

0 comments on commit 4098584

Please sign in to comment.