Files
odoo_source/addons/project/report/project_cumulative.py
T
Pierre Masereel 78f4cf0e3c [FIX] project: history cumulative bad compute inherit
When we were trying to delete a stage in project where there were
some tasks, an error was raised because of the 'project.task.history.cumulative'
records that inherit 'project.task.history' which have a compute method on
on end_date.
To fix this, we set the 'compute' attribute to 'None' and the readonly
'attribute' to 'True'.
2016-08-31 10:19:52 +02:00

43 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, tools
class ProjectTaskHistoryCumulative(models.Model):
_name = 'project.task.history.cumulative'
_inherit = 'project.task.history'
_auto = False
end_date = fields.Date(string='End Date', compute=None, readonly=True)
nbr_tasks = fields.Integer(string='# of Tasks', readonly=True)
project_id = fields.Many2one('project.project', string='Project')
def init(self):
tools.drop_view_if_exists(self._cr, self._table)
self._cr.execute(""" CREATE VIEW %s AS (
SELECT
history.date::varchar||'-'||history.history_id::varchar AS id,
history.date AS end_date,
*
FROM (
SELECT
h.id AS history_id,
h.date+generate_series(0, CAST((coalesce(h.end_date, DATE 'tomorrow')::date - h.date) AS integer)-1) AS date,
h.task_id, h.type_id, h.user_id, h.kanban_state,
count(h.task_id) as nbr_tasks,
greatest(h.remaining_hours, 1) AS remaining_hours, greatest(h.planned_hours, 1) AS planned_hours,
t.project_id
FROM
project_task_history AS h
JOIN project_task AS t ON (h.task_id = t.id)
GROUP BY
h.id,
h.task_id,
t.project_id
) AS history
)
""" % (self._table,))