Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import odoorpc
- import logging
- import sys
- logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s')
- logger = logging.getLogger('transfertest')
- """
- INFO:
- -Script for testing the speed of transferring product templates from one Odoo installation to another
- USAGE:
- 1) Install odoorpc with "pip install odoorpc"
- 2) Set in this file for both source and target installations:
- -Address
- -Port
- -DB name
- -Username
- -Password
- 3) Set also in this file the timeout and number of products to transfer
- 4) Run from command line with "python product_transfer.py"
- """
- source_address = 'x'
- source_port = x
- source_dbname = 'x'
- source_username = 'x'
- source_password = 'x'
- target_address = 'y'
- target_port = y
- target_dbname = 'y'
- target_username = 'y'
- target_password = 'y'
- timeout=10800
- product_limit = 3000
- logger.debug('Connecting to source {}:{}, database {}'.format(source_address, source_port, source_dbname))
- source_odoo = odoorpc.ODOO(source_address, port=source_port, timeout=timeout)
- logger.debug('Logging in...')
- source_odoo.login(source_dbname, source_username, source_password)
- logger.debug('Starting to browse {} products'.format(product_limit))
- source_product_model = source_odoo.env['product.template']
- source_product_ids = source_product_model.search([], limit=product_limit)
- source_products = source_product_model.browse(source_product_ids)
- logger.debug('Browsing done')
- logger.debug('Connecting to target {}:{}, database {}'.format(target_address, target_port, target_dbname))
- target_odoo = odoorpc.ODOO(target_address, port=target_port, timeout=timeout)
- logger.debug('Logging in...')
- target_odoo.login(target_dbname, target_username, target_password)
- logger.debug('Starting to create products...')
- target_product_model = target_odoo.env['product.template']
- counter = 0
- for source_product in source_products:
- target_product_model.create({
- 'name': source_product.name,
- 'default_code': source_product.default_code
- })
- counter += 1
- if counter % 500 == 0:
- logger.debug('{} products created'.format(counter))
- logger.debug('All done.')
Add Comment
Please, Sign In to add comment