forked from tfrancoi/odoo_import_example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
46 lines (39 loc) · 1.79 KB
/
client.py
File metadata and controls
46 lines (39 loc) · 1.79 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
# -*- coding: utf-8 -*-
import os
from odoo_csv_tools.lib import mapper
from odoo_csv_tools.lib.transform import Processor
from datetime import datetime
from prefix import *
#STEP 1 : read the needed file(s)
processor = Processor('origin%scontact.csv' % os.sep)
##STEP 2 : Define the mapping for every object to import
mapping = {
'id' : mapper.m2o_map(CLIENT_PREFIX, mapper.concat('_', 'Client Name','zip code')),
'name' : mapper.val('Client Name', skip=True),
'phone' : mapper.val('Phone'),
'street' : mapper.val('address1'),
'city' : mapper.val('city'),
'zip' : mapper.val('zip code'),
'country_id/id' : mapper.map_val('country', country_map),
'lang' : mapper.map_val('Language', lang_map),
'image_1920' : mapper.binary("Image", "origin/img/"),
'create_uid': mapper.val('Create BY'),
'create_date': mapper.val('Create ON',
postprocess=lambda x: datetime.strptime(x, "%d/%m/%y").strftime("%Y-%m-%d 00:00:00")),
'category_id/id': mapper.m2m(PARTNER_CATEGORY_PREFIX, 'Tag', 'Fidelity Grade'),
}
tag_mapping = {
'id' : mapper.m2m_id_list(PARTNER_CATEGORY_PREFIX, 'Tag'),
'name' : mapper.m2m_value_list('Tag'),
}
grade_mapping = {
'id' : mapper.m2m_id_list(PARTNER_CATEGORY_PREFIX, 'Fidelity Grade'),
'name' : mapper.m2m_value_list('Fidelity Grade'),
}
#Step 4: Process data
processor.process(tag_mapping, 'data%sres.partner.category.csv' % os.sep, {}, m2m=True)
processor.process(grade_mapping, 'data%sres.partner.category.grade.csv' % os.sep, {'model': 'res.partner.category'}, m2m=True)
processor.process(mapping, 'data%sres.partner.csv' % os.sep, { 'worker' : 2, 'batch_size' : 20, 'context': {'write_metadata': True}})
#Step 5: Define output and import parameter
processor.write_to_file("1_client.sh", python_exe='', path='')
print('Client Done')