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]
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
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
Hi,
try this :
partner_objs = self.env['res.partner'].search([])
if partner_objs:
partner_id = partner_objs[len(partner_objs)-1].id
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,
})
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up