-
Notifications
You must be signed in to change notification settings - Fork 3
/
ResUsers.py
88 lines (67 loc) · 2.89 KB
/
ResUsers.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2013-03-19
@author: Martin H. Bramwell
'''
import sys
from OErpModel import OErpModel
OPENERP_MODULE_NAME = 'res.users'
ignored_fields = ["ResUsers", "login"]
indirect_fields = ["company_ids"]
relations = {'company_ids': 'res.company'}
class ResUsers(OErpModel):
def __init__(self):
super(ResUsers, self).__init__()
self.methods = {
'chkTask': self.chkTask, 'update': self.update, 'load': self.load
}
def process(self, wrksht, rowTask):
super(ResUsers, self).process(wrksht, rowTask)
pos = OErpModel.CONSTANTS['MAP_MASKS']
# print '\n # # # # # # # # # # '
for idx, aMethod in enumerate(self.methodNames):
if super(ResUsers, self).todo(idx):
print ' #{} Doing "{}" now.'.format(idx + 1, aMethod)
super(ResUsers, self).starting(idx)
self.methods[aMethod](self.parameters)
super(ResUsers, self).finished(idx)
print '__'
else:
print ' #{} Skipping "{}"!'.format(idx + 1, aMethod)
# Temporary block globals()[aMethod](self.parameters)
pass
# print ' # # # # # # # # # # \n'
def update(self, parms):
oerp = super(ResUsers, self).getConnection()
# Obtain an array of record ids that match the selection criteria (only
# one in this case)
idUser = oerp.search(
OPENERP_MODULE_NAME, [("login", "=", parms['login'])])[0]
# Read the existing data (only what we need)
aUser = oerp.browse(OPENERP_MODULE_NAME, idUser)
print "Login " + parms['login'] + " -- " + aUser.login
# Write it back out with update applied
for key in parms:
if key not in ignored_fields: # Ignore the record key attribute
val = OErpModel.parseSpecial(self, parms[key])
print 'Editing : (User : {}, "{}":"{}") from "{}"'.format(
aUser.login, key, val, parms[key])
if key in indirect_fields:
ext_ids = parms[key].split(',')
aUser.company_ids += list(super(ResUsers, self).get_aliased_records(ext_ids, relations[key]))
pass
else:
setattr(aUser, key, val)
oerp.write_record(aUser)
print 'Written'
def load(self, parms):
print 'Calling parent to load to "{}".'.format(OPENERP_MODULE_NAME)
data = super(ResUsers, self).load(parms, OPENERP_MODULE_NAME)
# print 'Done in ResUsers!'
def chkTask(self, parms):
print 'Task check . . . '
for key in parms:
if key not in ("ResUsers", "login"):
print "Key : " + key + " Parm : "
print OErpModel.parseSpecial(self, parms[key])