Files
odoo_source/addons/project/models/project_milestone.py
T
Thibault Libioulle c5cac92280 [IMP] project: add project updates and milestones
This commit adds project updates in project to take in stock the current
status of the project : which task or milestone changed in the past 30
days.

The project manager is able to add a status on the project update, and
edit the description of the update. There is also a chatter in which
he/she can discuss some points with other project users.

The description is build with informations retrieved from mail tracking
values or from project.* models. Those informations are collected in a
dict and rendered in a template to ease the inheritence in further
modules needs.

Following commits will add behaviour to handle those updates and
milestones in the various views. See PR for further information.

PR : #68899

task-2393768
2021-06-01 12:01:37 +02:00

51 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class ProjectMilestone(models.Model):
_name = 'project.milestone'
_description = "Project Milestone"
_inherit = ['mail.thread']
_order = 'deadline, is_reached desc, name'
def _get_default_project_id(self):
return self.env.context.get('default_project_id') or self.env.context.get('active_id')
name = fields.Char(required=True)
project_id = fields.Many2one('project.project', required=True, default=_get_default_project_id)
deadline = fields.Date(tracking=True)
is_reached = fields.Boolean(string="Reached", default=False)
reached_date = fields.Date(compute='_compute_reached_date', store=True)
# computed non-stored fields
is_deadline_exceeded = fields.Boolean(compute="_compute_is_deadline_exceeded")
is_deadline_future = fields.Boolean(compute="_compute_is_deadline_future")
@api.depends('is_reached')
def _compute_reached_date(self):
for ms in self:
ms.reached_date = ms.is_reached and fields.Date.context_today(self)
@api.depends('is_reached', 'deadline')
def _compute_is_deadline_exceeded(self):
today = fields.Date.context_today(self)
for ms in self:
ms.is_deadline_exceeded = not ms.is_reached and ms.deadline and ms.deadline < today
@api.depends('deadline')
def _compute_is_deadline_future(self):
for ms in self:
ms.is_deadline_future = ms.deadline and ms.deadline > fields.Date.context_today(self)
@api.model
def _get_fields_to_export(self):
return ['id', 'name', 'deadline', 'is_reached', 'reached_date', 'is_deadline_exceeded', 'is_deadline_future']
def _get_data(self):
self.ensure_one()
return {field: self[field] for field in self._get_fields_to_export()}
def _get_data_list(self):
return [ms._get_data() for ms in self]