mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[MIG] project_task_line: to 15.0
Re-implement the subtasks smartbutton and action.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
'name': 'Project Task Lines',
|
||||
'version': '14.0.1.0.0',
|
||||
'version': '15.0.1.0.0',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'website': 'https://hibou.io/',
|
||||
'license': 'AGPL-3',
|
||||
|
||||
@@ -7,14 +7,30 @@ class ProjectTask(models.Model):
|
||||
line_ids = fields.One2many('project.task.line', 'task_id', string='Todo List')
|
||||
subtask_count_done = fields.Integer(compute='_compute_subtask_count', string="Sub-task Done count")
|
||||
|
||||
@api.depends('child_ids')
|
||||
def _compute_subtask_count(self):
|
||||
for task in self:
|
||||
task.subtask_count = self.search_count([('id', 'child_of', task.id), ('id', '!=', task.id)])
|
||||
if task.subtask_count:
|
||||
task.subtask_count_done = self.search_count([('id', 'child_of', task.id), ('id', '!=', task.id),
|
||||
('stage_id.fold', '=', True)])
|
||||
else:
|
||||
task.subtask_count_done = 0
|
||||
subtasks = task._get_all_subtasks()
|
||||
task.subtask_count = len(subtasks)
|
||||
task.subtask_count_done = len(subtasks.filtered(lambda t: t.stage_id.is_closed))
|
||||
|
||||
def action_subtask(self):
|
||||
action = self.env.ref('project.action_view_all_task').read()[0]
|
||||
|
||||
# display all subtasks of current task
|
||||
action['domain'] = [('id', 'child_of', self.id), ('id', '!=', self.id)]
|
||||
|
||||
ctx = dict(self.env.context)
|
||||
ctx = {k: v for k, v in ctx.items() if not k.startswith('search_default_')}
|
||||
ctx.update({
|
||||
'default_name': self.env.context.get('name', self.name) + ':',
|
||||
'default_parent_id': self.id, # will give default subtask field in `default_get`
|
||||
'default_company_id': self.env.company.id,
|
||||
})
|
||||
|
||||
action['context'] = ctx
|
||||
|
||||
return action
|
||||
|
||||
|
||||
class ProjectTaskLine(models.Model):
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
<field name="model">project.task</field>
|
||||
<field name="inherit_id" ref="project.view_task_form2" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='subtask_count']" position="replace">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<button name="action_subtask" type="object" class="oe_stat_button" icon="fa-tasks" attrs="{'invisible' : ['|', ('allow_subtasks', '=', False), ('id', '=', False)]}" context="{'default_user_ids': user_ids, 'default_parent_id': id, 'default_project_id': project_id}">
|
||||
<span class="o_stat_value"><field name="subtask_count_done" widget="statinfo" nolabel="1"/> / <field name="subtask_count" widget="statinfo" nolabel="1"/></span>
|
||||
<span class="o_stat_text">Sub-Tasks</span>
|
||||
</div>
|
||||
</button>
|
||||
</xpath>
|
||||
<xpath expr="//page[@name='description_page']" position="after">
|
||||
<page name="task_lines" string="Todo List">
|
||||
|
||||
Reference in New Issue
Block a user