Search code examples
pythonodooodoo-11

creating records from automated action in odoo11


I want to create an automated action where I could create multiple records for a model.

How can I refer to a particular user id from res.partner?

I can create simple records using

env['project.task'].create({'name': 'some_name', 'deadline': 'date' })

I also need to assign a few fields like assigned to and assigned by which have a relation as many2one with res.partner model.

How can I add these relation values and access particular id from the res.partner model?


Solution

  • You can add many2one fields by passing their id in the dict.

    user_id = self.env['res_users'].search([('name', '=', '*User Name*')]).id
    

    Make sure you have only one user with that name or use field login or any as per your requirement.

    Then create your report

    self.env['project.task'].create({
        'name': 'Some Name',
        'user_id': user_id
    })