Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
8654 Vizualizări

hi all, in a Model I have to define a field to get time only (get current system time with onchange or depends method) but it can be modifiable by user in case he/she wants to enter a different time, but a format mask should restrict to enter a valid time or i can check and warn and don't save the data.

OR

i have to change field type from Datetime to Char or Float etc. to calculate them?

regards

Imagine profil
Abandonează
Cel mai bun răspuns

Hi, 

Install the following module:

https://apps.odoo.com/apps/modules/11.0/web_widget_timepicker/

and follow the following code:

ofc_in_time = fields.Float(string="Office In Time", digits=(12, 2), copy=False)

<field name="ofc_in_time" widget="timepicker"/>


Thanks

Imagine profil
Abandonează
Autor

anything else without installing another module? here is my sample Model:

from odoo import models, fields, api

from datetime import datetime

class MyModel(models.Model):

_name = 'xyz.mymodel'

_description = "My Testings..."

name = fields.Char(string="Name here...")

time = fields.Datetime(string='Time', compute="_compute_time")

@api.onchange('start_date')

def _compute_time(self):

now = datetime.now()

final_time = now.strftime("%X")

self.time = final_time

in xml: <field name="time" widget="float_time"/>

also tried to have a Char type field which showing NaN:NaN instead of valid time, for Datetime type field it is showing following error while refereshing the page :

ValueError: time data '07:27:07 AM' does not match format '%Y-%m-%d '

You can also use:

ofc_in_time = fields.Float(string="Office In Time", digits=(12, 2), copy=False)

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

Related Posts Răspunsuri Vizualizări Activitate
1
feb. 21
9994
2
mar. 24
2421
1
iul. 22
2950
0
oct. 21
3941
3
iul. 21
6077