khadher
khadher

Reputation: 91

OpenERP field to hold time values such as `08:04`

i'm working in a module openeRP

i'm looking for a solution to declare a field in which i can add a time like this: 08:04.

i found this type datetime but it's not what i need.

fields.datetime

it doesn't work

because i don't need a date i need only the time.

can you help me?

Upvotes: 1

Views: 4062

Answers (2)

odony
odony

Reputation: 4117

Use the float_time widget

I'm not sure whether you actually need to store a time or a duration. If you want to store a duration, the easiest is probably to use a fields.float in combination with float_time widget. This is what OpenERP uses by default for storing task durations.

This will store the value in hours as a float in the database, but lets the users see and enter values using the familiar HH:MM format. So if the user enters 8:30 the value stored in the database will be 8.5. Having float values for durations makes it very easy to compute sums or average durations across many records.

For example your OpenERP model could have the following:

_columns: {
    'duration': fields.float('Duration (in hours)'),
}

and the corresponding view would contain:

<field name="duration" widget="float_time"/>

You can see a similar example in the official project module, at model and view levels.

Upvotes: 2

OmaL
OmaL

Reputation: 5044

Can you try fields.time. I dont know openerp still have this field.

Upvotes: 0

Related Questions