Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
8659 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
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"/>

Powiązane posty Odpowiedzi Widoki Czynność
1
lut 21
9995
2
mar 24
2421
1
lip 22
2950
0
paź 21
3941
3
lip 21
6078