Passed
Push — master ( d6b140...72cad7 )
by Ramon
05:21
created

bika/lims/browser/analysisrequest/view.py (2 issues)

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-2019 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from bika.lims import api
22
from bika.lims.browser import BrowserView
23
from bika.lims.browser.header_table import HeaderTableView
24
from bika.lims.interfaces import IReceived
25
from bika.lims.permissions import EditFieldResults
26
from bika.lims.permissions import EditResults
27
from bika.lims.utils import check_permission
28
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
29
from resultsinterpretation import ARResultsInterpretationView
30
31
32
class AnalysisRequestViewView(BrowserView):
33
    """Main AR View
34
    """
35
    template = ViewPageTemplateFile("templates/analysisrequest_view.pt")
36
37
    def __init__(self, context, request):
38
        self.init__ = super(
39
            AnalysisRequestViewView, self).__init__(context, request)
40
        self.icon = "{}/{}".format(
41
            self.portal_url,
42
            "/++resource++bika.lims.images/sample_big.png",
43
        )
44
45
    def __call__(self):
46
        # If the analysis request has been received and hasn't been yet
47
        # verified yet, redirect the user to manage_results view, but only if
48
        # the user has privileges to Edit(Field)Results, cause otherwise she/he
49
        # will receive an InsufficientPrivileges error!
50
        if (self.request.PATH_TRANSLATED.endswith(self.context.id) and
51
            self.can_edit_results() and self.can_edit_field_results() and
52
           self.is_received() and not self.is_verified()):
53
54
            # Redirect to manage results view if not cancelled
55
            if not self.is_cancelled():
56
                manage_results_url = "{}/{}".format(
57
                    self.context.absolute_url(), "manage_results")
58
                return self.request.response.redirect(manage_results_url)
59
60
        # render header table
61
        self.header_table = HeaderTableView(self.context, self.request)()
62
63
        # Create the ResultsInterpretation by department view
64
        self.riview = ARResultsInterpretationView(self.context, self.request)
65
66
        return self.template()
67
68
    def render_analyses_table(self, table="lab"):
69
        """Render Analyses Table
70
        """
71
        if table not in ["lab", "field", "qc"]:
72
            raise KeyError("Table '{}' does not exist".format(table))
73
        view_name = "table_{}_analyses".format(table)
74
        view = api.get_view(
75
            view_name, context=self.context, request=self.request)
76
        # Call listing hooks
77
        view.update()
78
        view.before_render()
79
        return view.ajax_contents_table()
80
81
    def has_lab_analyses(self):
82
        """Check if the AR contains lab analyses
83
        """
84
        # Negative performance impact - add a Metadata column
85
        analyses = self.context.getAnalyses(getPointOfCapture="lab")
86
        return len(analyses) > 0
87
88
    def has_field_analyses(self):
89
        """Check if the AR contains field analyses
90
        """
91
        # Negative performance impact - add a Metadata column
92
        analyses = self.context.getAnalyses(getPointOfCapture="field")
93
        return len(analyses) > 0
94
95
    def has_qc_analyses(self):
96
        """Check if the AR contains field analyses
97
        """
98
        # Negative performance impact - add a Metadata column
99
        analyses = self.context.getQCAnalyses()
100
        return len(analyses) > 0
101
102
    def can_edit_results(self):
103
        """Checks if the current user has the permission "EditResults"
104
        """
105
        return check_permission(EditResults, self.context)
106
107
    def can_edit_field_results(self):
108
        """Checks if the current user has the permission "EditFieldResults"
109
        """
110
        return check_permission(EditFieldResults, self.context)
111
112
    def is_received(self):
113
        """Checks if the AR is received
114
        """
115
        return IReceived.providedBy(self.context)
116
117
    def is_verified(self):
118
        """Checks if the AR is verified
119
        """
120
        return IVerified.providedBy(self.context)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable IVerified does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'IVerified'
Loading history...
121
122
    def is_cancelled(self):
123
        """Checks if the AR is cancelled
124
        """
125
        return api.get_review_status(self.context) == "cancelled"
126
127
    def is_hazardous(self):
128
        """Checks if the AR is hazardous
129
        """
130
        return self.context.getHazardous()
131
132
    def is_retest(self):
133
        """Checks if the AR is a retest
134
        """
135
        return self.context.getRetest()
136
137
    def exclude_invoice(self):
138
        """True if the invoice should be excluded
139
        """
140
141
    def show_categories(self):
142
        """Check the setup if analysis services should be categorized
143
        """
144
        setup = api.get_setup()
145
        return setup.getCategoriseAnalysisServices()
146