Code Duplication    Length = 43-44 lines in 2 locations

bika/lims/content/worksheet.py 1 location

@@ 1363-1406 (lines=44) @@
1360
            return analyst_member.getProperty('fullname')
1361
        return analyst
1362
1363
    def isVerifiable(self):
1364
        """
1365
        Checks it the current Worksheet can be verified. This is, its
1366
        not a cancelled Worksheet and all the analyses that contains
1367
        are verifiable too. Note that verifying a Worksheet is in fact,
1368
        the same as verifying all the analyses that contains. Therefore, the
1369
        'verified' state of a Worksheet shouldn't be a 'real' state,
1370
        rather a kind-of computed state, based on the statuses of the analyses
1371
        it contains. This is why this function checks if the analyses
1372
        contained are verifiable, cause otherwise, the Worksheet will
1373
        never be able to reach a 'verified' state.
1374
        :returns: True or False
1375
        """
1376
        # Check if the worksheet is active
1377
        workflow = getToolByName(self, "portal_workflow")
1378
        objstate = workflow.getInfoFor(self, 'cancellation_state', 'active')
1379
        if objstate == "cancelled":
1380
            return False
1381
1382
        # Check if the worksheet state is to_be_verified
1383
        review_state = workflow.getInfoFor(self, "review_state")
1384
        if review_state == 'to_be_verified':
1385
            # This means that all the analyses from this worksheet have
1386
            # already been transitioned to a 'verified' state, and so the
1387
            # woksheet itself
1388
            return True
1389
        else:
1390
            # Check if the analyses contained in this worksheet are
1391
            # verifiable. Only check those analyses not cancelled and that
1392
            # are not in a kind-of already verified state
1393
            canbeverified = True
1394
            omit = ['published', 'retracted', 'rejected', 'verified']
1395
            for a in self.getAnalyses():
1396
                st = workflow.getInfoFor(a, 'cancellation_state', 'active')
1397
                if st == 'cancelled':
1398
                    continue
1399
                st = workflow.getInfoFor(a, 'review_state')
1400
                if st in omit:
1401
                    continue
1402
                # Can the analysis be verified?
1403
                if not a.isVerifiable(self):
1404
                    canbeverified = False
1405
                    break
1406
            return canbeverified
1407
1408
    def isUserAllowedToVerify(self, member):
1409
        """

bika/lims/content/analysisrequest.py 1 location

@@ 2812-2854 (lines=43) @@
2809
        return user_email(self, self.Creator())
2810
2811
    # TODO Workflow, AnalysisRequest Move to guards.verify?
2812
    def isVerifiable(self):
2813
        """Checks it the current Analysis Request can be verified. This is, its
2814
        not a cancelled Analysis Request and all the analyses that contains
2815
        are verifiable too. Note that verifying an Analysis Request is in fact,
2816
        the same as verifying all the analyses that contains. Therefore, the
2817
        'verified' state of an Analysis Request shouldn't be a 'real' state,
2818
        rather a kind-of computed state, based on the statuses of the analyses
2819
        it contains. This is why this function checks if the analyses
2820
        contained are verifiable, cause otherwise, the Analysis Request will
2821
        never be able to reach a 'verified' state.
2822
        :returns: True or False
2823
        """
2824
        # Check if the analysis request is active
2825
        workflow = getToolByName(self, "portal_workflow")
2826
        objstate = workflow.getInfoFor(self, 'cancellation_state', 'active')
2827
        if objstate == "cancelled":
2828
            return False
2829
2830
        # Check if the analysis request state is to_be_verified
2831
        review_state = workflow.getInfoFor(self, "review_state")
2832
        if review_state == 'to_be_verified':
2833
            # This means that all the analyses from this analysis request have
2834
            # already been transitioned to a 'verified' state, and so the
2835
            # analysis request itself
2836
            return True
2837
        else:
2838
            # Check if the analyses contained in this analysis request are
2839
            # verifiable. Only check those analyses not cancelled and that
2840
            # are not in a kind-of already verified state
2841
            canbeverified = True
2842
            omit = ['published', 'retracted', 'rejected', 'verified']
2843
            for a in self.getAnalyses(full_objects=True):
2844
                st = workflow.getInfoFor(a, 'cancellation_state', 'active')
2845
                if st == 'cancelled':
2846
                    continue
2847
                st = workflow.getInfoFor(a, 'review_state')
2848
                if st in omit:
2849
                    continue
2850
                # Can the analysis be verified?
2851
                if not a.isVerifiable(self):
2852
                    canbeverified = False
2853
                    break
2854
            return canbeverified
2855
2856
    def getObjectWorkflowStates(self):
2857
        """