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

Hello,

I am encountering a problem entering times in the timesheet module. 

I am in French language and when I enter a duration with decimal places with the numeric keyboard, odoo inserts a value with a comma as a decimal separator. This is normal given my language.

But odoo refuses to record the time and asks me to enter the duration with a decimal point. I think this comes from a problem with the data type of the field which does not take into account the language settings.

How to correct this problem?

Thank you for your help.

Regards,

Eric

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

You need to override the method that parses the duration input to handle both commas and points as decimal separators.


from odoo import models, fields, api
from odoo.exceptions import ValidationError
import re

class TimesheetCustom(models.Model):
    _inherit = 'account.analytic.line'

    @api.constrains('unit_amount')
    def _check_unit_amount(self):
        for record in self:
            # Replace comma with dot for decimal values
            if isinstance(record.unit_amount, str):
                record.unit_amount = record.unit_amount.replace(',', '.')
           
            # Validate the converted value
            try:
                float(record.unit_amount)
            except ValueError:
                raise ValidationError("Please enter a valid duration.")

Ensure the views are updated to handle the input correctly. You have to override the  field "unit_amount" and add float_time widget to it.


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

Hello,

Nobody can help me.

Is someone from the odoo Core can answer or create a bug ticket ?

Regards 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 5 25
952
1
thg 4 25
1119
1
thg 2 24
2831
0
thg 10 24
4111
0
thg 11 22
2290