Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- encoding: utf-8 -*-
- import odoorpc
- import argparse
- import csv
- PARSER = argparse.ArgumentParser()
- PARSER.add_argument("-d", "--db", help="DataBase Name", required=True)
- PARSER.add_argument("-r", "--user", help="OpenERP User", required=True)
- PARSER.add_argument("-w", "--passwd", help="OpenERP Password", required=True)
- PARSER.add_argument("-f", "--filePath", help="csv file path", required=True)
- PARSER.add_argument("-p", "--port",
- type=int,
- help="Port, 8069 for default", default="8069")
- PARSER.add_argument("-s", "--server",
- help="Server IP, 127.0.0.1 for default",
- default="127.0.0.1")
- ARGS = PARSER.parse_args()
- if ARGS.db is None or ARGS.user is None or ARGS.passwd is None:
- print "Must be specified DataBase, User and Password" # noqua
- quit()
- DB_NAME = ARGS.db
- USER = ARGS.user
- PASSW = ARGS.passwd
- SERVER = ARGS.server
- PORT = ARGS.port
- FILE = ARGS.filePath
- odoo = odoorpc.ODOO(SERVER,
- port=PORT)
- UID_CONF = odoo.login(DB_NAME, USER, PASSW)
- Product = odoo.env['product.template']
- products_ids = Product.search([])
- with open('products.csv', 'wb') as csvfile:
- writer = csv.writer(csvfile, delimiter=',',
- quotechar='"', quoting=csv.QUOTE_MINIMAL)
- for pid in products_ids:
- product = Product.browse(pid)
- code = product.default_code if product.default_code else ""
- barcode = product.barcode if product.barcode else ""
- writer.writerow([
- product.name.encode('utf-8'),
- product.type ,
- code ,
- barcode ,
- str(product.list_price) ,
- product.categ_id.name ,
- product.pos_categ_id.name ,
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement