Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Export float_time widget data into time format?..

Subscribe

Get notified when there's activity on this post

This question has been flagged
exporttimefloat_time
3 Replies
35525 Views
Avatar
Prakash

In openerp 7,  Start Time columns created using float_time widget.

in py file,

start_time: fields.float('Start Time')

in xml file,

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

Using "Export" options  Start Time output values generated it shows in float format.

Coversion float to float_time code:-

case 'float_time': var pattern = '%02d:%02d'; if (value < 0) { value = Math.abs(value); pattern = '-' + pattern; } var hour = Math.floor(value); var min = Math.round((value % 1) * 60); if (min == 60){ min = 0; hour = hour + 1; } return _.str.sprintf(pattern, hour, min);

In Export options export_data method how to override and apply the above float to float_time conversion formula for all widget="float_time" Field.?,,,,

 

0
Avatar
Discard
Avatar
Prakash
Author Best Answer

In the model override export_data ORM method and float value convert into time.

Example

import math

def float_time_convert(float_val):
factor = float_val < 0 and -1 or 1
val = abs(float_val)
return (factor * int(math.floor(val)), int(round((val % 1) * 60)))

def export_data(self, cr, uid, ids, fields, context=None):
index = range(len(fields))
fields_name = dict(zip(fields,index))
res = super(class_name, self).export_data(cr, uid, ids, fields, context=context)
try:
for index, val in enumerate(res['datas']):
if fields_name.get('float_fieldname1'):
field1index = fields_name.get('float_fieldname1')
float_field1 = float(res['datas'][index][field1index])
hour, minute = self.float_time_convert(float_field1)
res['datas'][index][field1index] = '{0:02d}:{1:02d}'.format(hour, minute)
if fields_name.get('float_fieldname2'):
field2index = fields_name.get('float_fieldname2')
float_field2 = float(res['datas'][index][field2index])
hour, minute = self.float_time_convert(float_field2)
res['datas'][index][field2index] = '{0:02d}:{1:02d}'.format(hour, minute)
except Exception, e:
#print "Export Exception", e
pass
return res

1
Avatar
Discard
Avatar
Lucas Huber
Best Answer

I did follow the method of Prakash but got an error first. Then I did realise that the float_time_convert call has to be an @api.multi and not an api.one:

File "/opt/odoo/custom/addons9/project_scrum/models/scrum_base.py", line 180, in onchange_duration_hrs
hour, minute = self.float_time_convert(self.duration)
ValueError: need more than 1 value to unpack


my correct code:

@api.multi
def float_time_convert(self, float_val):
    factor = float_val < 0 and -1 or 1 val = abs(float_val)
    return (factor * int(math.floor(val)), int(round((val % 1) * 60)))
...
hour, minute = self.float_time_convert(self.duration)

But then I get a problem with adding Datetime and timedelta

start_datetime = fields.Datetime()
....

end_time = self.start_datetime + datetime.timedelta(hours=hour, minute=minute)

Python does interpret start_datetime not as datetime!

0
Avatar
Discard
Faris Fathurrahman

i have tried this and it worked. I used datetime.combine with initial date and time.min as the start_datetime

Avatar
Arsalan
Best Answer

I require the same thing.... did you get a way to handle such situation ??

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Convert Hours and Minute into Float value Solved
time float_time V13
Avatar
Avatar
1
Apr 20
17215
How to subtract two 'float_time' field values?
time float float_time odoo10
Avatar
Avatar
4
Jan 20
7031
Exporting large amount of data
error export time long
Avatar
0
Jul 15
5017
exporteren
export
Avatar
Avatar
1
Jul 25
2498
How can I list/export more than 80 items? Solved
export
Avatar
Avatar
Avatar
3
Feb 25
16057
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now