Update project_task.py
This commit is contained in:
parent
54ce329636
commit
011cf7e25f
|
|
@ -4,15 +4,14 @@ from dateutil import relativedelta
|
|||
from odoo.addons.resource.models.resource import float_to_time, HOURS_PER_DAY
|
||||
from odoo.osv import expression
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError, ValidationError ,Warning
|
||||
from odoo.exceptions import UserError, ValidationError, Warning
|
||||
|
||||
|
||||
class ProjectTask(models.Model):
|
||||
_inherit = "project.task"
|
||||
|
||||
|
||||
phase_id = fields.Many2one('project.phase', string='Project Phase', domain="[('project_id','=',project_id)]")
|
||||
phase_hours = fields.Float("phase total hours",related="phase_id.estimated_hours")
|
||||
phase_hours = fields.Float("phase total hours", related="phase_id.estimated_hours")
|
||||
user_ids = fields.Many2many('res.users', 'project_task_users',
|
||||
'task_id', 'users_id', string="Employees")
|
||||
weight = fields.Float(string='Weight', )
|
||||
|
|
@ -20,11 +19,13 @@ class ProjectTask(models.Model):
|
|||
maximum_rate = fields.Float(string='Maximum Rate', default=1)
|
||||
|
||||
allowed_internal_user_ids = fields.Many2many('res.users', 'project_task_allowed_internal_users_rel',
|
||||
string="Allowed Internal Users", default=lambda self: self.env.user, domain=[('share', '=', False)])
|
||||
allowed_portal_user_ids = fields.Many2many('res.users', 'project_task_allowed_portal_users_rel', string="Allowed Portal Users", domain=[('share', '=', True)])
|
||||
isdone= fields.Boolean(string='')
|
||||
string="Allowed Internal Users", default=lambda self: self.env.user,
|
||||
domain=[('share', '=', False)])
|
||||
allowed_portal_user_ids = fields.Many2many('res.users', 'project_task_allowed_portal_users_rel',
|
||||
string="Allowed Portal Users", domain=[('share', '=', True)])
|
||||
isdone = fields.Boolean(string='')
|
||||
|
||||
@api.constrains('task_progress' , 'weight')
|
||||
@api.constrains('task_progress', 'weight')
|
||||
def _check_task_weight_progress(self):
|
||||
for record in self:
|
||||
if record.task_progress < 0 or record.task_progress > 100:
|
||||
|
|
@ -33,7 +34,7 @@ class ProjectTask(models.Model):
|
|||
raise ValidationError(_("The weight must be between 0 and 100."))
|
||||
|
||||
def write(self, vals):
|
||||
res = super(project, self).write(vals)
|
||||
res = super(ProjectTask, self).write(vals)
|
||||
if 'stage_id' in vals and vals.get('stage_id'):
|
||||
manager_users = self.env.ref('project.group_project_manager').users
|
||||
department_manager_users = self.env.ref('project_base.group_project_department_manager').users
|
||||
|
|
@ -47,25 +48,24 @@ class ProjectTask(models.Model):
|
|||
task.name, task.project_id.name or ""),
|
||||
'subject': _("Done Task"),
|
||||
'partner_ids': [(6, 0, user_ids.mapped('partner_id').ids)],
|
||||
'notification_ids': [(0, 0, {'res_partner_id': user.partner_id.id, 'notification_type': 'inbox'})
|
||||
'notification_ids': [
|
||||
(0, 0, {'res_partner_id': user.partner_id.id, 'notification_type': 'inbox'})
|
||||
for user in user_ids if user_ids],
|
||||
'model': task._name,
|
||||
'res_id': task.id,
|
||||
'author_id': self.env.user.partner_id and self.env.user.partner_id.id
|
||||
})
|
||||
|
||||
# self._send_state_change_notification()
|
||||
return res
|
||||
|
||||
@api.onchange('weight')
|
||||
def _onchange_weight(self):
|
||||
done_task = self.env['project.task'].search([('phase_id', '=', self.phase_id.id),('id','!=',self._origin.id)])
|
||||
done_task = self.env['project.task'].search(
|
||||
[('phase_id', '=', self.phase_id.id), ('id', '!=', self._origin.id)])
|
||||
weight_done = done_task.mapped('weight')
|
||||
sum_weight = sum(weight_done) + self.weight
|
||||
if sum_weight > 100:
|
||||
raise ValidationError(_("The total weights of the tasks for the stage must not exceed 100"))
|
||||
|
||||
|
||||
|
||||
@api.onchange('project_id')
|
||||
def _onchange_project_id(self):
|
||||
for task in self:
|
||||
|
|
|
|||
Loading…
Reference in New Issue