Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
894 Lượt xem

So Im working on this code that creates new record in 'sign.send.request.signer' model. I currently use some test data

data = {
    "role_id" : 1,
    "partner_id" : 14,
    "mail_sent_order" : 1,
}


# Create the record in sign.send.request.signer
env['sign.send.request.signer'].create(data)


Whenever I run this manually an error shows up


Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 390, in safe_eval
    return unsafe_eval(c, globals_dict, locals_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "ir.actions.server(899,)", line 29, in <module>
  File "/mnt/enterprise_addons/sign/wizard/sign_send_request.py", line 230, in create
    if not vals.get('partner_id'):
           ^^^^^^^^
AttributeError: 'str' object has no attribute 'get'


I assume the error tells me I'm passing a string and not a dictionary when creating a record. However its pretty obvious that Im passing 'data' and its a dictionary. Did I skip something or do something wrong? Or is this a bug?  

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello Johnny Solas,

Please replace your code with the one below and give it a try:

data = [{
    "role_id": 1,
    "partner_id": 14,
    "mail_sent_order": 1,
}]

# Create the record in sign.send.request.signer
env['sign.send.request.signer'].create(data)

Let me know if this works for you.

Thanks!

Ảnh đại diện
Huỷ bỏ
Tác giả

Wow It works, but there is a new error message shows up

"odoo.exceptions.ValidationError: You must specify one signer for each role of your sign template"

After applying you solution this is my code

# Create the sign send request
send_request_data = {
"template_id": int(payload.get("template_id")),
"subject": "test Subject",
"filename": "test.pdf",
}

send_request = env["sign.send.request"].create(send_request_data)

signer_data = [{
"role_id": 1, # Assuming this is a required role ID in your case
"partner_id": int(payload.get("partner_id")),
"mail_sent_order": 1,
"sign_send_request_id": send_request.id
}]

signer = env["sign.send.request.signer"].create(signer_data)
send_request.send_request()

What could be the problem in this?

Hello,

In Odoo, there's a method called _check_signers_roles_validity, which is triggered when the send_request() method is called. This method verifies that each signing role defined in a sign template has exactly one corresponding signer assigned when a sign request is created. If this condition is not met, a ValidationError is raised.

Example Scenarios:
- Valid Case:
The template includes 3 roles (Manager, HR, Employee).
The sign request has 3 signers, each correctly assigned to one of these roles.

- Invalid Case 1:
The template has 3 roles, but the sign request only includes 2 signers → Error raised.

- Invalid Case 2:
The template has no roles defined, but the sign request does not include at least one signer with the default role → Error raised.

I hope this will helpfull for you.

Thanks!

Câu trả lời hay nhất

Hello Johnny Solas,

Try to put something like this:

def create_records(self):
data = {
"role_id": 1,
"partner_id": 14,
"mail_sent_order": 1,
}
self.env['sign.send.request.signer'].create(data)

  Make sure to call the function and verify that the model and field are available.

Thank you,

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 21
4146
1
thg 1 20
4686
1
thg 1 17
4074
0
thg 9 15
3340
0
thg 12 24
4788