Code Duplication    Length = 21-21 lines in 2 locations

src/senaite/core/datamanagers/sample.py 1 location

@@ 48-68 (lines=21) @@
45
46
        return field
47
48
    def get(self, name):
49
        """Get sample field
50
        """
51
        # get the schema field
52
        field = self.get_field_by_name(name)
53
54
        # check if the field exists
55
        if field is None:
56
            raise AttributeError("Field '{}' not found".format(name))
57
58
        # Check the permission of the field
59
        if not self.is_field_readable(field):
60
            raise Unauthorized("Field '{}' not readable!".format(name))
61
62
        # return the value with the field accessor
63
        if hasattr(field, "getAccessor"):
64
            accessor = field.getAccessor(self.context)
65
            return accessor()
66
        else:
67
            # Set the value on the field directly
68
            return field.get(self.context)
69
70
    def set_analysis_result(self, name, value):
71
        """Handle Batchbook Results

src/senaite/core/datamanagers/analysisservice.py 1 location

@@ 48-68 (lines=21) @@
45
46
        return field
47
48
    def get(self, name):
49
        """Get sample field
50
        """
51
        # get the schema field
52
        field = self.get_field_by_name(name)
53
54
        # check if the field exists
55
        if field is None:
56
            raise AttributeError("Field '{}' not found".format(name))
57
58
        # Check the permission of the field
59
        if not self.is_field_readable(field):
60
            raise Unauthorized("Field '{}' not readable!".format(name))
61
62
        # return the value with the field accessor
63
        if hasattr(field, "getAccessor"):
64
            accessor = field.getAccessor(self.context)
65
            return accessor()
66
        else:
67
            # Set the value on the field directly
68
            return field.get(self.context)
69
70
    def set(self, name, value):
71
        """Set sample field or analysis result