feat: Improve sequence generation logic to handle "Anyone" roles and prevent duplicate sequence generation per request.
This commit is contained in:
parent
8910c89cab
commit
7092737ec4
@ -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
|
||||
|
||||
@ -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:
|
||||
request_items = request.request_item_ids[:1]
|
||||
|
||||
if not request_items:
|
||||
continue
|
||||
|
||||
# We only generate if it hasn't been generated yet.
|
||||
# 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()
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user