Passed
Push — 2.x ( 6121d6...a5fbfb )
by Jordi
08:10
created

senaite.core.patches.cmfcore.workflowtool   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 6
dl 0
loc 46
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A _reindexWorkflowVariables() 0 22 2
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE.
4
#
5
# SENAITE.CORE is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free Software
7
# Foundation, version 2.
8
#
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
# details.
13
#
14
# You should have received a copy of the GNU General Public License along with
15
# this program; if not, write to the Free Software Foundation, Inc., 51
16
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
#
18
# Copyright 2018-2024 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from bika.lims import api
22
23
24
def _reindexWorkflowVariables(self, ob):
25
    """This function is called by DCWorkflow immediately after the workflow
26
    action is invoked in WorkflowTool.doActionFor.
27
28
    The original function is only responsible of reindexing the variables that
29
    may have changed due to the transition (e.g review_state) along with
30
    security-related indexes. However, the original function does two calls
31
    to reindexObject, one for workflow variables and another one for the
32
    security-related indexes. Metadata is updated on both calls as well, cause
33
    those workflow-variables might also be stored as metadata.
34
35
    Since quite often the transition involves changes not only in
36
    workflow-related variables, but to other field values, it becomes almost
37
    a requirement to always reindex the object after a transition. Therefore,
38
    we simply do a full reindexObject here instead of taking only some indexes
39
    into account.
40
    """
41
    if api.is_temporary(ob):
42
        return
43
44
    # do a full reindex
45
    ob.reindexObject()
46