This commit adds a right panel in the project update view. This is done by extending each View and Controller by mixins handling the RightPanel functionnality. In the RightPanelControllerMixin, we use the component Adapter to launch the Owl RightPanel Component from a Legacy Controller. This solution is based on SearchPanel and ControlPanel implementation. In the RendererMixin we handle some styling just as it's done for the SearchPanel. In the ViewMixin, we add the handling of a RightSidePanel config parameter which is passed to the Controller via params. The Project RightPanel Component gets information about the active project in the context through a rpc call and render the resulting data in a owl template. This template doen't have the ambition to be generic but only specific to this view. Serverside, the data are collected in a dict through few methods in order to be easily extended. Mixins are used in kanban and list views, each time a project update view is added, the developper will have to extend the dedicated View, Renderer and Controller. PR: #68899 task-2393768
56 lines
2.1 KiB
Python
56 lines
2.1 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)
|
|
|
|
def toggle_is_reached(self, is_reached):
|
|
self.ensure_one()
|
|
self.update({'is_reached': is_reached})
|
|
return self._get_data()
|
|
|
|
@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]
|