forked from tfrancoi/odoo_import_example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsupplier.py
More file actions
57 lines (49 loc) · 2.31 KB
/
Copy pathsupplier.py
File metadata and controls
57 lines (49 loc) · 2.31 KB
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
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
import os
from fluvo.lib import mapper
from fluvo.lib.transform import Processor
from datetime import datetime
from prefix import *
CONFIG = 'conf%stest_connection.conf' % os.sep
SOURCE = 'origin%ssupplier.csv' % os.sep
##STEP 1 : Define the mapping for every object to import
mapping = {
'id' : mapper.m2o(SUPPLIER_PREFIX, 'Company_ID'),
'name' : mapper.val('Company_Name'),
'phone' : mapper.val('Phone'),
'street' : mapper.val('address1'),
'city' : mapper.val('city'),
'zip' : mapper.val('zip code'),
'country_id/id' : mapper.map_val(country_map, 'country'),
'user_id': mapper.val('Account_Manager'),
}
contact_mapping = {
'id': mapper.m2o(SUPPLIER_CONTACT_PREFIX, 'Contact Email'),
'parent_id/id': mapper.m2o(SUPPLIER_PREFIX, 'Company_ID'),
'email': mapper.val('Contact Email'),
'name': mapper.concat(' ', 'Contact First Name', 'Contact Last Name'),
'title/id': mapper.m2o(TITLE_PREFIX, 'Contact Title'),
}
title_map = {
'id': mapper.m2o(TITLE_PREFIX, 'Contact Title'),
'name': mapper.val('Contact Title', skip=True),
'shortcut': mapper.val('Contact Title')
}
#STEP 2 : Read the source file once and process every mapping.
# Titles and supplier companies are referenced by the contacts, so they are
# written to the load script before the contacts (append=True everywhere
# because client.py already created load.sh in this run).
title_processor = Processor(title_map, source_filename=SOURCE, config_file=CONFIG)
title_processor.process('data%sres.partner.title.csv' % os.sep, {}, 'set')
title_processor.write_to_file("load.sh", python_exe='', path='', append=True)
supplier_processor = Processor(mapping, dataframe=title_processor.dataframe,
config_file=CONFIG)
supplier_processor.process('data%sres.partner.supplier.csv' % os.sep,
{'model': 'res.partner'})
supplier_processor.write_to_file("load.sh", python_exe='', path='', append=True)
contact_processor = Processor(contact_mapping, dataframe=title_processor.dataframe,
config_file=CONFIG)
contact_processor.process('data%sres.partner.supplier.contact.csv' % os.sep,
{'model': 'res.partner'})
contact_processor.write_to_file("load.sh", python_exe='', path='', append=True)
print('Supplier Done')