Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. # -*- encoding: utf-8 -*-
  2. import odoorpc
  3. import argparse
  4. import csv
  5.  
  6. PARSER = argparse.ArgumentParser()
  7. PARSER.add_argument("-d", "--db", help="DataBase Name", required=True)
  8. PARSER.add_argument("-r", "--user", help="OpenERP User", required=True)
  9. PARSER.add_argument("-w", "--passwd", help="OpenERP Password", required=True)
  10. PARSER.add_argument("-f", "--filePath", help="csv file path", required=True)
  11. PARSER.add_argument("-p", "--port",
  12. type=int,
  13. help="Port, 8069 for default", default="8069")
  14. PARSER.add_argument("-s", "--server",
  15. help="Server IP, 127.0.0.1 for default",
  16. default="127.0.0.1")
  17. ARGS = PARSER.parse_args()
  18.  
  19. if ARGS.db is None or ARGS.user is None or ARGS.passwd is None:
  20. print "Must be specified DataBase, User and Password" # noqua
  21. quit()
  22.  
  23. DB_NAME = ARGS.db
  24. USER = ARGS.user
  25. PASSW = ARGS.passwd
  26. SERVER = ARGS.server
  27. PORT = ARGS.port
  28. FILE = ARGS.filePath
  29.  
  30. odoo = odoorpc.ODOO(SERVER,
  31. port=PORT)
  32.  
  33. UID_CONF = odoo.login(DB_NAME, USER, PASSW)
  34.  
  35. Product = odoo.env['product.template']
  36. products_ids = Product.search([])
  37. with open('products.csv', 'wb') as csvfile:
  38. writer = csv.writer(csvfile, delimiter=',',
  39. quotechar='"', quoting=csv.QUOTE_MINIMAL)
  40. for pid in products_ids:
  41. product = Product.browse(pid)
  42. code = product.default_code if product.default_code else ""
  43. barcode = product.barcode if product.barcode else ""
  44. writer.writerow([
  45. product.name.encode('utf-8'),
  46. product.type ,
  47. code ,
  48. barcode ,
  49. str(product.list_price) ,
  50. product.categ_id.name ,
  51. product.pos_categ_id.name ,
  52. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement