Code Duplication    Length = 18-25 lines in 2 locations

bika/health/adapters/widgetvisibility/batch.py 1 location

@@ 26-50 (lines=25) @@
23
from bika.lims.interfaces import IClient
24
25
26
class ClientFieldVisibility(SenaiteATWidgetVisibility):
27
    """Handles the Client field visibility in Batch context
28
    """
29
30
    def __init__(self, context):
31
        super(ClientFieldVisibility, self).__init__(
32
            context=context, field_names=["Client"])
33
34
    def isVisible(self, field, mode="view", default="visible"):
35
        """Renders the Client field as hidden if the current mode is "edit" and
36
        the container is either a Patient or a Client
37
        """
38
        if mode == "edit":
39
            container = self.context.aq_parent
40
41
            # If the Batch is created or edited inside either Client or Patient,
42
            # make Client field to be rendered, but hidden to prevent the error
43
            # message "Patient is required, please correct".
44
            if IPatient.providedBy(container):
45
                return "readonly"
46
47
            elif IClient.providedBy(container):
48
                return "readonly"
49
50
        return default
51
52
53
class PatientFieldsVisibility(SenaiteATWidgetVisibility):

bika/health/adapters/widgetvisibility/patient.py 1 location

@@ 25-42 (lines=18) @@
22
from bika.lims.interfaces import IClient
23
24
25
class ClientFieldVisibility(SenaiteATWidgetVisibility):
26
    """Handles the Client (PrimaryReferrer) field visibility in Patient context
27
    """
28
29
    def __init__(self, context):
30
        super(ClientFieldVisibility, self).__init__(
31
            context=context, field_names=["PrimaryReferrer"])
32
33
    def isVisible(self, field, mode="view", default="visible"):
34
        """Renders the PrimaryReferrer field (Client) as readonly when the
35
        mode is "edit" and the container is a Client
36
        """
37
        if mode == "edit":
38
            container = self.context.aq_parent
39
            if IClient.providedBy(container):
40
                return "readonly"
41
42
        return default
43