Skip to Content
Menu
This question has been flagged
3 Replies
1560 Views

I'm trying to create a user using "auth_signup". How do I get the last ID!?

[code]## INSERT NEW USER
_logger.warn('\n\n\n\n\n\n\n\n Hello world!! :-)')
request.env['res.partner'].sudo().create({
'name': post.get('firstname', '') + ' ' + post.get('lastname', ''),
'login': post.get('email', ''),
'email': post.get('email', ''),
'reseller_id': reseller_id,
})
## GET LAST ID
partner_id = self.env['res.partner'].search([])[-1].id

_logger.warn('\n\n\n\n\n\n\n\n partner_id: %s' % partner_id )
_logger.warn('\n\n\n\n\n\n\n\n Hello world!! 22222')
request.env['res.users'].sudo().signup({
'name': post.get('firstname', '') + ' ' + post.get('lastname', ''),
'street': post.get('street', ''),
'zip': post.get('zip', ''),
'city': post.get('city', ''),
'country_id': post.get('country_id', ''),
'login': post.get('email', ''),
'email': post.get('email', ''),
'reseller_id': reseller_id,
'partner_id': partner_id,
})[/code]

Avatar
Discard
Best Answer

Hi,

If you are looking to get the ID of the user you have created in the code, what you can do is assign the record creation to a variable like,

new_user = request.env['res.users'].create(vals)

then you will have the object of newly created user in the variable new_user, using . operation you can get the id, new_user.id

Thanks

Avatar
Discard
Best Answer

Hi,

try this :

partner_objs = self.env['res.partner'].search([])
if partner_objs:
partner_id =   partner_objs[len(partner_objs)-1].id
Avatar
Discard
Author Best Answer

Thank you! 

## INSERT NEW USER
_logger.warn('\n\n\n\n\n\n\n\n Hello world!! :-)')
partner = request.env['res.partner'].sudo().create({
'name': post.get('firstname', '') + ' ' + post.get('lastname', ''),
'login': post.get('email', ''),
'email': post.get('email', ''),
'reseller_id': reseller_id,
})
_logger.warn('\n\n\n\n\n\n\n\n partner: %s' % partner )
_logger.warn('\n\n\n\n\n\n\n\n Hello world!! 22222')
request.env['res.users'].sudo().signup({
'name': post.get('firstname', '') + ' ' + post.get('lastname', ''),
'street': post.get('street', ''),
'zip': post.get('zip', ''),
'city': post.get('city', ''),
'country_id': post.get('country_id', ''),
'login': post.get('email', ''),
'email': post.get('email', ''),
'reseller_id': reseller_id,
'partner_id': partner.id,
})​

Avatar
Discard