Guest User

Untitled

a guest
Dec 16th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import odoorpc
  2. import logging
  3. import sys
  4. logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s')
  5. logger = logging.getLogger('transfertest')
  6.  
  7. """
  8. INFO:
  9. -Script for testing the speed of transferring product templates from one Odoo installation to another
  10.  
  11. USAGE:
  12. 1) Install odoorpc with "pip install odoorpc"
  13.  
  14. 2) Set in this file for both source and target installations:
  15. -Address
  16. -Port
  17. -DB name
  18. -Username
  19. -Password
  20.  
  21. 3) Set also in this file the timeout and number of products to transfer
  22.  
  23. 4) Run from command line with "python product_transfer.py"
  24.  
  25. """
  26.  
  27. source_address = 'x'
  28. source_port = x
  29. source_dbname = 'x'
  30. source_username = 'x'
  31. source_password = 'x'
  32.  
  33. target_address = 'y'
  34. target_port = y
  35. target_dbname = 'y'
  36. target_username = 'y'
  37. target_password = 'y'
  38.  
  39. timeout=10800
  40. product_limit = 3000
  41.  
  42. logger.debug('Connecting to source {}:{}, database {}'.format(source_address, source_port, source_dbname))
  43. source_odoo = odoorpc.ODOO(source_address, port=source_port, timeout=timeout)
  44.  
  45. logger.debug('Logging in...')
  46. source_odoo.login(source_dbname, source_username, source_password)
  47.  
  48. logger.debug('Starting to browse {} products'.format(product_limit))
  49. source_product_model = source_odoo.env['product.template']
  50. source_product_ids = source_product_model.search([], limit=product_limit)
  51. source_products = source_product_model.browse(source_product_ids)
  52. logger.debug('Browsing done')
  53.  
  54.  
  55. logger.debug('Connecting to target {}:{}, database {}'.format(target_address, target_port, target_dbname))
  56. target_odoo = odoorpc.ODOO(target_address, port=target_port, timeout=timeout)
  57.  
  58. logger.debug('Logging in...')
  59. target_odoo.login(target_dbname, target_username, target_password)
  60.  
  61. logger.debug('Starting to create products...')
  62. target_product_model = target_odoo.env['product.template']
  63.  
  64. counter = 0
  65.  
  66. for source_product in source_products:
  67. target_product_model.create({
  68. 'name': source_product.name,
  69. 'default_code': source_product.default_code
  70. })
  71. counter += 1
  72. if counter % 500 == 0:
  73. logger.debug('{} products created'.format(counter))
  74.  
  75.  
  76. logger.debug('All done.')
Add Comment
Please, Sign In to add comment