6-odoo-basic-tools.png
Blogger_636921856896094478.png
By: Sreejith Sasidharan

6 Odoo Basic Tools

Technical

Odoo is one of the fastest-growing ERP of the globe and is widely known for its functionality in the various business domains. The integrated management system efficiently covers every business departments and intuitively perform their departmental operations. Odoo is indeed considered as the #1 open-source ERP available in the market. This article discusses Odoo Tools and Tricks. 


Here, I am going to explain to you the built-in tools associated with Odoo system. 


All the commands below are running in Odoo shell.


1. Config

The config tool comes in connection to the odoo.conf configuration file. By using this tool we can get the values from the .conf file. Let’s see how it is done.


from odoo.tools import config
config.get('db_name')
# 'odoo'
config.filestore(config.get('db_name'))
# /var/lib/odoo/filestore/odoo
config.session_dir
# /var/lib/odoo/sessions
config.options
# {
#     'addons_paths': 'opt/odoo/core/odoo/addons',
#     'auto_reload': False,
#     'db_host': 'db'
#     ...
# }


2. Convert

The covert tool mainly focuses on the conversion of data types. If you are working with APIs and integration, the most common function built into convert is str2bool.


from odoo.tools import convert
convert.str2bool('0')  # Returns False
convert.str2bool('false')  # Returns False
convert.str2bool('False')  # Returns False
convert.str2bool('1')  # Returns True
convert.str2bool('true')  # Returns True
convert.str2bool('True')  # Returns True


3. Date_utils

Date_utils provides a powerful extension to the standard DateTime module. This is used for getting ranges and references to different time periods, computing of relative deltas (next month, next year, next Monday, last week of month) also computing relative deltas between two dates, and so forth. 


from odoo import fields
from odoo.tools import date_utils
today = fields.Datetime.now()
#  2019-11-29 03:56:01 Returns the current Date and Time
date_utils.get_month(today)
#  (datetime.datetime(2019, 11, 1, 0, 0), datetime.datetime(2019, 11, 30, 0, 0))
#  Returns the range for the first day of month to the last
date_utils.get_quarter(today)
#  (datetime.datetime(2019, 10, 1, 0, 0), datetime.datetime(2019, 12, 31, 0, 0))
#  Returns the range for the first day of the fiscal quarter to the last
date_utils.get_quarter_number(today)
#  4 Returns the number of current quarter
date_utils.get_fiscal_year(today)
#  (datetime.datetime(2019, 1, 1, 0, 0), datetime.datetime(2019, 12, 31, 0, 0))
#  Returns the range for the first day of the fiscal year to the last


4. Date_utils - range helpers

These are the range helpers in the date_utils tool. Here we are using start_of and end_of functions of hour, day, week, month, quarter and year.


from odoo import fields
from odoo.tools import date_utils
today = fields.Datetime.now()
#  2019-12-09 11:16:33 today
date_utils.start_of(today, "hour")
#  2019-12-09 11:00:00 hour
date_utils.start_of(today, "day")
#  2019-12-09 00:00:00 day
date_utils.start_of(today, "week")
#  2019-12-09 00:00:00 week
date_utils.start_of(today, "month")
#  2019-12-01 00:00:00 month
date_utils.start_of(today, "quarter")
#  2019-10-01 00:00:00 quarter
date_utils.start_of(today, "year")
#  2019-01-01 00:00:00 year
date_utils.end_of(today, "hour")
#  2019-12-09 11:59:59.999999 hour
date_utils.end_of(today, "day")
#  2019-12-09 23:59:59.999999 day
date_utils.end_of(today, "week")
#  2019-12-15 23:59:59.999999 week
date_utils.end_of(today, "month")
#  2019-12-31 23:59:59.999999 month
date_utils.end_of(today, "quarter")
#  2019-12-31 23:59:59.999999 quarter
date_utils.end_of(today, "year")
#  2019-12-31 23:59:59.999999 year


5. date_utils – calculations

These are a couple of abstractions in date_utils. Mainly addition and subtraction of days, weeks, months and years.


from odoo import fields
from odoo.tools import date_utils
today = fields.Datetime.now()
#  2019-12-09 11:39:13 today
date_utils.add(today, days=5)
#  2019-12-14 11:39:13
date_utils.add(today, weeks=2)
#  2019-12-23 11:39:13
date_utils.add(today, months=1)
#  2020-01-09 11:39:13
date_utils.add(today, years=1)
#  2020-12-09 11:39:13
date_utils.add(today, days=2, months=6, years=1)
#  2021-06-11 11:39:13
date_utils.subtract(today, days=5)
#  2019-12-04 11:39:13
date_utils.subtract(today, weeks=2)
#  2019-11-25 11:39:13
date_utils.subtract(today, months=1)
#  2019-11-09 11:39:13
date_utils.subtract(today, years=1)
#  2018-12-09 11:39:13
date_utils.subtract(today, days=2, months=6, years=1)
#  2018-06-07 11:39:13

 

6. Image

This tool is used for manipulating images.


from odoo.tools import image
image.image_resize_image(img, size=(400, 400))
image.image_resize_and_sharpen(img, size=(400, 400))
with open('/tmp/image_file.png', 'w') as f:
   image.image_save_for_web(img, f)



cybrosys youtube

Comments

0


Leave a comment

 
Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

London

Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message