Code Duplication    Length = 31-31 lines in 2 locations

src/senaite/core/content/analysisprofile.py 1 location

@@ 477-507 (lines=31) @@
474
    # BBB: AT schema (computed) field property
475
    TotalPrice = property(getTotalPrice)
476
477
    def remove_service(self, service):
478
        """Remove the service from the profile
479
480
        If the service is not selected in the profile, returns False.
481
482
        NOTE: This method is used when an Analysis Service was deactivated.
483
484
        :param service: The service to be removed from this profile
485
        :type service: AnalysisService
486
        :return: True if the AnalysisService has been removed successfully
487
        """
488
        # get the UID of the service that should be removed
489
        uid = api.get_uid(service)
490
        # get the current raw value of the services field.
491
        current_services = self.getRawServices()
492
        # filter out the UID of the service
493
        new_services = filter(
494
            lambda record: record.get("uid") != uid, current_services)
495
496
        # check if the service was removed or not
497
        current_services_count = len(current_services)
498
        new_services_count = len(new_services)
499
500
        if current_services_count == new_services_count:
501
            # service was not part of the profile
502
            return False
503
504
        # set the new services
505
        self.setServices(new_services)
506
507
        return True
508
509
    @security.protected(permissions.View)
510
    def getRawSampleTypes(self):

src/senaite/core/content/sampletemplate.py 1 location

@@ 621-651 (lines=31) @@
618
            records[record.get("uid")] = record
619
        return records
620
621
    def remove_service(self, service):
622
        """Remove the service from the template
623
624
        If the service is not selected in the profile, returns False.
625
626
        NOTE: This method is used when an Analysis Service was deactivated.
627
628
        :param service: The service to be removed from this template
629
        :type service: AnalysisService
630
        :return: True if the AnalysisService has been removed successfully
631
        """
632
        # get the UID of the service that should be removed
633
        uid = api.get_uid(service)
634
        # get the current raw value of the services field.
635
        current_services = self.getRawServices()
636
        # filter out the UID of the service
637
        new_services = filter(
638
            lambda record: record.get("uid") != uid, current_services)
639
640
        # check if the service was removed or not
641
        current_services_count = len(current_services)
642
        new_services_count = len(new_services)
643
644
        if current_services_count == new_services_count:
645
            # service was not part of the profile
646
            return False
647
648
        # set the new services
649
        self.setServices(new_services)
650
651
        return True
652