Code Duplication    Length = 20-21 lines in 2 locations

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

@@ 24-44 (lines=21) @@
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

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

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