forked from tfrancoi/odoo_import_example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsupplier_message.py
More file actions
30 lines (25 loc) · 1.13 KB
/
supplier_message.py
File metadata and controls
30 lines (25 loc) · 1.13 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
# -*- coding: utf-8 -*-
from odoo_csv_tools.lib import mapper
from odoo_csv_tools.lib.transform import Processor
from datetime import datetime
from prefix import SUPPLIER_PREFIX, MESSAGE_PREFIX, SUPPLIER_CONTACT_PREFIX
#STEP 1 : read the needed file(s)
processor = Processor('origin/message.csv')
##STEP 2 : Define the mapping for every object to import
mapping = {
# External ID is not allowed to be imported
# 'id' : mapper.m2o_map(MESSAGE_PREFIX, mapper.concat("_", 'Company_ID', 'Date')),
# 'res_external_id' : mapper.m2o(SUPPLIER_PREFIX, 'Company_ID'),
'message_type': mapper.const('email'),
'author_id/id': mapper.m2o(SUPPLIER_CONTACT_PREFIX, 'from'),
'email_from': mapper.val('from'),
'subject': mapper.val('subject'),
'body': mapper.val('body'),
'date': mapper.val('Date',
postprocess=lambda x: datetime.strptime(x, "%d/%m/%y %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S")),
}
#Step 4: Process data
processor.process(mapping, 'data/mail.message.csv', {})
#Step 5: Define output and import parameter
processor.write_to_file("3_supplier_message.sh", python_exe='', path='')
print('Supplier Message Done')