Code Duplication    Length = 18-19 lines in 2 locations

bika/lims/browser/worksheet/views/results.py 1 location

@@ 136-153 (lines=18) @@
133
                outdict[analysis.getKeyword()] = andict
134
        return outdict
135
136
    def checkInstrumentsValidity(self):
137
        """ Checks the validity of the instruments used in the Analyses
138
            If an analysis with an invalid instrument (out-of-date or
139
            with calibration tests failed) is found, a warn message
140
            will be displayed.
141
        """
142
        invalid = []
143
        ans = self._getAnalyses()
144
        for an in ans:
145
            valid = an.isInstrumentValid()
146
            if not valid:
147
                inv = '%s (%s)' % (safe_unicode(an.Title()), safe_unicode(an.getInstrument().Title()))
148
                if inv not in invalid:
149
                    invalid.append(inv)
150
        if len(invalid) > 0:
151
            message = _("Some analyses use out-of-date or uncalibrated instruments. Results edition not allowed")
152
            message = "%s: %s" % (message, (', '.join(invalid)))
153
            self.context.plone_utils.addPortalMessage(message, 'warn')
154
155
    def _getAnalyses(self):
156
        """

bika/lims/browser/analysisrequest/manage_results.py 1 location

@@ 24-42 (lines=19) @@
21
        self.checkInstrumentsValidity()
22
        return self.template()
23
24
    def checkInstrumentsValidity(self):
25
        """Checks the validity of the instruments used in the Analyses
26
27
        If an analysis with an invalid instrument (out-of-date or with
28
        calibration tests failed) is found, a warn message will be displayed.
29
        """
30
        invalid = []
31
32
        ans = [a.getObject() for a in self.context.getAnalyses()]
33
        for an in ans:
34
            valid = an.isInstrumentValid()
35
            if not valid:
36
                inv = '%s (%s)' % (safe_unicode(an.Title()),
37
                                   safe_unicode(an.getInstrument().Title()))
38
                if inv not in invalid:
39
                    invalid.append(inv)
40
        if len(invalid) > 0:
41
            message = _("Some analyses use out-of-date or uncalibrated "
42
                        "instruments. Results edition not allowed")
43
            message = "%s: %s" % (message, (', '.join(invalid)))
44
            self.context.plone_utils.addPortalMessage(message, 'warn')
45