跳至內容
選單
此問題已被標幟
2 回覆
2272 瀏覽次數

How can I prevent time entry on a finished project or task?


頭像
捨棄

@Odoo - any news?

作者

But there seems to be no answer.

In most other time registration software this is a standard feature !

最佳答案

Hi,

Please refer to the code:


from odoo import models, api

from odoo.exceptions import ValidationError


class AnalyticLine(models.Model):

    _inherit = "account.analytic.line"


    @api.model

    def create(self, vals):

        task_id = vals.get("task_id")

        if task_id:

            task = self.env["project.task"].browse(task_id)

            if task.is_closed:

                raise ValidationError("You cannot log time on a closed task.")

        return super().create(vals)


    def write(self, vals):

        if "task_id" in vals:

            task = self.env["project.task"].browse(vals["task_id"])

            if task.is_closed:

                raise ValidationError("You cannot reassign timesheet to a closed task.")

        return super().write(vals)


Hope it helps.

頭像
捨棄
最佳答案

On the Settings tab of the Project, uncheck "Timesheets - Log time on tasks" to prevent further timesheeting:


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
5月 23
4296
1
10月 22
3251
0
11月 21
2176
1
5月 21
2839
1
9月 20
8265