forked from tfrancoi/odoo_csv_import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
odoo_export_thread.py
executable file
·47 lines (41 loc) · 2.48 KB
/
odoo_export_thread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
#-*- coding: utf-8 -*-
'''
Copyright (C) Thibault Francois
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Lesser Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import argparse
from odoo_csv_tools import export_threaded
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Import data in batch and in parallel')
parser.add_argument('-c', '--config', dest='config', default="conf/connection.conf", help='Configuration File that contains connection parameters', required = True)
parser.add_argument('--file', dest='filename', help='Output File', required = True)
parser.add_argument('--model', dest='model', help='Model to Export', required = True)
parser.add_argument('--field', dest='fields', help='Fields to Export', required = True)
parser.add_argument('--domain', dest='domain', help='Filter', default="[]")
parser.add_argument('--worker', dest='worker', default=1, help='Number of simultaneous connection')
parser.add_argument('--size', dest='batch_size', default=10, help='Number of line to import per connection')
parser.add_argument('-s', '--sep', dest="separator", default=";", help='CSV separator')
parser.add_argument('--context', dest='context', help='context that will be passed to the load function, need to be a valid python dict', default="{'tracking_disable' : True}")
#TODO args : encoding
#{'update_many2many': True,'tracking_disable' : True, 'create_product_variant' : True, 'check_move_validity' : False}
args = parser.parse_args()
config_file = args.config
file_csv = args.filename
batch_size = int(args.batch_size)
model = args.model
max_connection = int(args.worker)
separator = args.separator
encoding='utf-8-sig'
context= eval(args.context)
domain = eval(args.domain)
header = args.fields.split(',')
export_threaded.export_data(config_file, model, domain, header, context=context, output=file_csv, max_connection=max_connection, batch_size=batch_size, separator=separator, encoding=encoding)