Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
274 Lượt xem

I have a custom datetime columns on the Account Analytic Line for Start_Time and End_Time that I need with updated date and time when the start and stop button is pressed for the timesheet line while within a Helpdesk ticket and Field Service/Project. The fields are working but I cant seem to find out where to go to customize the functionality of that specific button to extend Odoo's standard functionality to update my custom fields.


This is because Odoo doesn't track the Exact Start and End time for Timesheets, Tickets and Field Service. I need to track this for my reporting.


I am Using Version 18.0

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Please refer to the code:

from odoo import models, fields

from datetime import datetime


class AccountAnalyticLine(models.Model):

    _inherit = 'account.analytic.line'


    start_time = fields.Datetime("Start Time")

    end_time = fields.Datetime("End Time")


    def action_timer_start(self):

        res = super().action_timer_start()

        for line in self:

            # Only set start_time if it’s not already set

            if not line.start_time:

                line.start_time = fields.Datetime.now()

        return res


    def action_timer_stop(self):

        res = super().action_timer_stop()

        for line in self:

            line.end_time = fields.Datetime.now()

        return res


Hope it helps.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 25
931
1
thg 7 25
621
1
thg 3 25
1559
0
thg 1 25
992
1
thg 10 25
581