Skip to content
Snippets Groups Projects
Commit f83944aa authored by rmu-odoo's avatar rmu-odoo Committed by Yannick Tivisse
Browse files

[IMP] hr_timesheet: Prevent wrong `parent_id` configuration

And hide the parent_id field.
parent df01742f
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, api
from odoo import models, fields, api, _
from odoo.exceptions import UserError
class Project(models.Model):
......@@ -59,3 +60,9 @@ class Task(models.Model):
subtask_count = fields.Integer(compute='_get_subtask_count', type='integer', string="Sub-task count")
_constraints = [(models.BaseModel._check_recursion, 'Circular references are not permitted between tasks and sub-tasks', ['parent_id'])]
@api.constrains('parent_id')
def _check_subtask_project(self):
for task in self:
if task.parent_id and task.parent_id.project_id and task.project_id and task.project_id != task.parent_id.project_id.subtask_project_id:
raise UserError(_("You can't define a parent task if its project is not correctly configured. The sub-task's project of the parent task's project should be this task's project"))
......@@ -93,7 +93,7 @@
<field name="planned_hours" widget="float_time"/>
</field>
<field name="partner_id" position="after">
<field name="parent_id" attrs="{'invisible' : [('parent_id', '=', False)]}" />
<field name="parent_id" groups="base.group_no_one"/>
<field name="child_ids" invisible="1" />
<field name="subtask_project_id" invisible="1" />
</field>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment