Skip to Content
Menu
This question has been flagged
2 Replies
2327 Rodiniai

Hi, getting opcode errors in Odoo Studio V18.0, when using "execute Code" within the Contact model, on save; code: "

# Search for the document template (Make sure the name is correct or use XML ID)

template = env['sign.template'].search([('name', '=', 'Mixbean Non-Disclosure Agreement')], limit=1)


if not template:

    raise UserError("Document template not found.")


# Create a signature request using the template

sign_request = env['sign.request'].create({

    'template_id': record.id,  # Contact is the signatory

    'email': record.email,  # Email for sending the document

})]


# Send the document for signing

sign_request.action_sent()

"

Thanks for all your insights

Portretas
Atmesti
Best Answer

Hi Olivier

The first problem I see is :

template = env['sign.template'].search([('name', '=', 'Mixbean Non-Disclosure Agreement')], limit=1)

if you have multi language setup, it's a bad idea to search by name, it's better to search by id

template = env['sign.template'].browse(x). # where x is the sign.template id


the second problem is that you are creating a record  based on variable of a record that is being created:

sign_request = env['sign.request'].create({

    'template_id': record.id,  

    'email': record.email,  # Email for sending the document

})] => here record is not yet commited into the DB

to solve this, mayv change the trigger from "creation /save" to "after creation"


Hope this helps 

Portretas
Atmesti
Autorius Best Answer

Thank you for your kind response. The full name of the doc needs to include its extension, managed to get that step through. Although my approach was wrong. The elegant solution is to trigger the existing mechanism remotely via automation, ir.actions.act_window ID 271 New Signature Request (no it's not a good idea, it's a window action, but the principle of using an existing preset action remains), then the object sign.send.request, assign the recipients, and the cascading info properly. On this I'm stuck. Only scraped further a bit of info visible at this URL Yourdomain.com/odoo/sign/8/action-sign.Template/ir.model.fields?debug=1 (check the orange circled bug for info) <= change the  /8/ to reflect the ID of your template.


Portretas
Atmesti

But then why not just create a record for that wizard model (triggered by ir.actions.act_window ID 271) directly with
wiz= env['sign.send.request'].create({
'customer': 1,
'provider': ....
})
# call odoo method to send
wiz.send_request()

Related Posts Replies Rodiniai Veikla
0
rugp. 25
668
4
birž. 25
2143
2
lapkr. 23
4200
1
geg. 25
4519
1
rugs. 23
3725