[fix] address generation & use brand new multiple inheritance & cross osv/osv_memory instead of _columns hack
bzr revid: xmo@tinyerp.com-20091217194250-cvta8ckyuqslv3qm
This commit is contained in:
parent
5cba98ef43
commit
4730f553f9
|
@ -210,20 +210,12 @@
|
|||
|
||||
<group string="res_config_contents" position="replace">
|
||||
<separator string="New User" colspan="4"/>
|
||||
<field name="previous_signature" invisible="1"/>
|
||||
<field name="name"
|
||||
on_change="generate_signature(name, email,
|
||||
previous_signature, signature)"/>
|
||||
<field name="email"
|
||||
on_change="generate_signature(name, email,
|
||||
previous_signature, signature)"/>
|
||||
<field name="name"/>
|
||||
<field name="email"/>
|
||||
<field name="login"/>
|
||||
<field name="password" password="True"/>
|
||||
<field name="context_lang"/>
|
||||
<field name="context_tz"/>
|
||||
<field colspan="4" name="signature"
|
||||
on_change="generate_signature(name, email,
|
||||
previous_signature, signature)"/>
|
||||
|
||||
<separator string="Group" colspan="4"/>
|
||||
<label align="0.0" colspan="4" string="
|
||||
|
|
|
@ -271,7 +271,15 @@ class res_partner(osv.osv):
|
|||
if (not context.get('category_id', False)):
|
||||
return False
|
||||
return _('Partners: ')+self.pool.get('res.partner.category').browse(cr, uid, context['category_id'], context).name
|
||||
|
||||
def main_partner(self, cr, uid):
|
||||
''' Return the id of the main partner
|
||||
'''
|
||||
model_data = self.pool.get('ir.model.data')
|
||||
return model_data.browse(
|
||||
cr, uid,
|
||||
model_data.search(cr, uid, [('module','=','base'),
|
||||
('name','=','main_partner')])[0],
|
||||
).res_id
|
||||
res_partner()
|
||||
|
||||
class res_partner_address(osv.osv):
|
||||
|
|
|
@ -196,6 +196,7 @@ class users(osv.osv):
|
|||
'action_id': _get_menu,
|
||||
'company_id': _get_company,
|
||||
'groups_id': _get_group,
|
||||
'address_id': False,
|
||||
}
|
||||
def company_get(self, cr, uid, uid2):
|
||||
company_id = self.pool.get('res.users').browse(cr, uid, uid2).company_id.id
|
||||
|
@ -259,50 +260,35 @@ class users(osv.osv):
|
|||
]
|
||||
users()
|
||||
|
||||
SIGNATURE_FORMAT = '''--
|
||||
%(name)s %(email)s
|
||||
'''
|
||||
class config_users(osv.osv_memory):
|
||||
_name = 'res.config.users'
|
||||
_inherit = 'res.config'
|
||||
_inherit = ['res.users', 'res.config']
|
||||
|
||||
_columns = dict(
|
||||
users._columns,
|
||||
previous_signature=fields.text(),
|
||||
)
|
||||
_defaults = users._defaults
|
||||
def _generate_signature(self, cr, name, email, context=None):
|
||||
return _('--\n%(name)s %(email)s\n') % {
|
||||
'name': name or '',
|
||||
'email': email and ' <'+email+'>' or '',
|
||||
}
|
||||
|
||||
def user_data(self, cr, uid, new_id, context=None):
|
||||
''' Gets the purely user part of the current config_user
|
||||
instance, without the fields inherited from res.config
|
||||
'''
|
||||
return self.read(cr, uid, new_id,
|
||||
users._columns.keys(),
|
||||
context=context)
|
||||
def create_user(self, cr, uid, new_id, context=None):
|
||||
''' create a new res.user instance from the data stored
|
||||
in the current res.config.users
|
||||
'''
|
||||
base_data = self.read(cr, uid, new_id, context=context)
|
||||
partner_id = self.pool.get('res.partner').main_partner(cr, uid)
|
||||
address = self.pool.get('res.partner.address').create(
|
||||
cr, uid, {'name': base_data['name'],
|
||||
'email': base_data['email'],
|
||||
'partner_id': partner_id,},
|
||||
context)
|
||||
user_data = dict(
|
||||
user_data,
|
||||
signature=self._generate_signature(
|
||||
cr, base_data['name'], base_data['email'], context=context),
|
||||
address_id=address,
|
||||
)
|
||||
self.pool.get('res.users').create(
|
||||
cr, uid, self.user_data(cr, uid, new_id, context), context)
|
||||
|
||||
def generate_signature(self, cr, uid, ids, name, email,
|
||||
previous_signature, signature, context=None):
|
||||
''' If the admin sets the name or email, regenerate the signature
|
||||
except if the admin has previously edited the signature manually,
|
||||
in this case stop generating the signature unless the admin completely
|
||||
empties the custom sig.
|
||||
'''
|
||||
if signature != previous_signature:
|
||||
return {'value': {'previous_signature':''}}
|
||||
signature = SIGNATURE_FORMAT % {
|
||||
'name': name or '',
|
||||
'email': email and ' <'+email+'>' or '',
|
||||
}
|
||||
return {'value': {
|
||||
'previous_signature': signature,
|
||||
'signature': signature,
|
||||
}}
|
||||
cr, uid, user_data, context)
|
||||
|
||||
def execute(self, cr, uid, ids, context=None):
|
||||
self.create_user(cr, uid, ids[0], context=context)
|
||||
|
|
Loading…
Reference in New Issue