تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
8655 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب

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"/>

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
فبراير 21
9994
2
مارس 24
2421
1
يوليو 22
2950
0
أكتوبر 21
3941
3
يوليو 21
6077