diff --git a/models/sign_document.py b/models/sign_document.py index 9abaf22..5d535f0 100644 --- a/models/sign_document.py +++ b/models/sign_document.py @@ -14,7 +14,7 @@ class SignDocument(models.Model): _inherit = 'sign.document' def render_document_with_items(self, signed_values=None, values_dict=None, final_log_hash=None): - base_output = super(SignDocument, self).render_document_with_items(signed_values, values_dict, final_log_hash) + base_output = super().render_document_with_items(signed_values, values_dict, final_log_hash) if not base_output: return base_output diff --git a/models/sign_request.py b/models/sign_request.py index 631a31d..6d93c4d 100755 --- a/models/sign_request.py +++ b/models/sign_request.py @@ -49,14 +49,18 @@ class SignRequest(models.Model): if sign_item.type_id.item_type == 'sequence' and sign_item.sequence_id: # Find the responsible request item (signer) # Use role_id to match. - # We check if there is a signer for this role in this request. + # Fallback to the first signer if no specific matching signer is found (e.g. role is "Anyone") request_items = request.request_item_ids.filtered(lambda r: r.role_id == sign_item.responsible_id) if not request_items: - continue + request_items = request.request_item_ids[:1] - # We only generate if it hasn't been generated yet. + if not request_items: + continue + + # We only generate if it hasn't been generated yet for this sign_item across the whole request + # to prevent duplicate generation if multiple request_items were somehow matched. existing_value = request.env['sign.request.item.value'].search([ - ('sign_request_item_id', 'in', request_items.ids), + ('sign_request_id', '=', request.id), ('sign_item_id', '=', sign_item.id) ], limit=1) @@ -83,7 +87,7 @@ class SignRequest(models.Model): if not request.reference.startswith(f"{new_seq} - "): request.write({'reference': f"{new_seq} - {request.reference}"}) - return super(SignRequest, self)._sign() + return super()._sign()