Code Duplication    Length = 20-21 lines in 2 locations

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

@@ 37-57 (lines=21) @@
34
        self.checkInstrumentsValidity()
35
        return self.template()
36
37
    def checkInstrumentsValidity(self):
38
        """Checks the validity of the instruments used in the Analyses
39
40
        If an analysis with an invalid instrument (out-of-date or with
41
        calibration tests failed) is found, a warn message will be displayed.
42
        """
43
        invalid = []
44
45
        ans = [a.getObject() for a in self.context.getAnalyses()]
46
        for an in ans:
47
            valid = an.isInstrumentValid()
48
            if not valid:
49
                inv = '%s (%s)' % (safe_unicode(an.Title()),
50
                                   safe_unicode(an.getInstrument().Title()))
51
                if inv not in invalid:
52
                    invalid.append(inv)
53
        if len(invalid) > 0:
54
            message = _("Some analyses use out-of-date or uncalibrated "
55
                        "instruments. Results edition not allowed")
56
            message = "%s: %s" % (message, (', '.join(invalid)))
57
            self.context.plone_utils.addPortalMessage(message, 'warning')
58

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

@@ 182-201 (lines=20) @@
179
                outdict[analysis.getKeyword()] = andict
180
        return outdict
181
182
    def checkInstrumentsValidity(self):
183
        """Checks the validity of the instruments used in the Analyses If an
184
        analysis with an invalid instrument (out-of-date or with calibration
185
        tests failed) is found, a warn message will be displayed.
186
        """
187
        invalid = []
188
        ans = self.context.getAnalyses()
189
        for an in ans:
190
            valid = an.isInstrumentValid()
191
            if not valid:
192
                instrument = an.getInstrument()
193
                inv = "%s (%s)" % (
194
                    safe_unicode(an.Title()), safe_unicode(instrument.Title()))
195
                if inv not in invalid:
196
                    invalid.append(inv)
197
        if len(invalid) > 0:
198
            message = _("Some analyses use out-of-date or uncalibrated "
199
                        "instruments. Results edition not allowed")
200
            message = "%s: %s" % (message, (", ".join(invalid)))
201
            self.context.plone_utils.addPortalMessage(message, "warning")
202