Passed
Push — master ( 5e306e...e48f16 )
by Jordi
04:40
created

guard_activate()   A

Complexity

Conditions 5

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 20
rs 9.3333
c 0
b 0
f 0
cc 5
nop 1
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE
4
#
5
# Copyright 2018 by it's authors.
6
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.
7
8
from bika.lims import api
9
10
11
def guard_activate(analysis_service):
12
    """Returns whether the transition activate can be performed for the
13
    analysis service passed in
14
    """
15
    calculation = analysis_service.getCalculation()
16
    if not calculation:
17
        return True
18
19
    # If the calculation is inactive, we cannot activate the service
20
    if not api.is_active(calculation):
21
        return False
22
23
    # All services that we depend on to calculate our result are active or we
24
    # don't depend on other services.
25
    dependencies = calculation.getDependentServices()
26
    for dependency in dependencies:
27
        if not api.is_active(dependency):
28
            return False
29
30
    return True
31
32
33
def guard_deactivate(analysis_service):
34
    """Returns whether the transition deactivate can be performed for the
35
    analysis service passed in
36
    """
37
    for dependant in analysis_service.getServiceDependants():
38
        status = api.get_workflow_status_of(dependant)
39
        if status == "active":
40
            return False
41
42
    return True
43