Passed
Push — master ( feb3de...56c573 )
by Jordi
04:25
created

build.bika.lims.content.pricelist.ObjectModifiedEventHandler()   F

Complexity

Conditions 16

Size

Total Lines 78
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 63
dl 0
loc 78
rs 2.4
c 0
b 0
f 0
cc 16
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like build.bika.lims.content.pricelist.ObjectModifiedEventHandler() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE
4
#
5
# Copyright 2018 by it's authors.
6
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.
7
8
from AccessControl import ClassSecurityInfo
9
from bika.lims import bikaMessageFactory as _
10
from bika.lims.browser.fields.remarksfield import RemarksField
11
from bika.lims.browser.widgets import RemarksWidget
12
from bika.lims.config import PRICELIST_TYPES
13
from bika.lims.config import PROJECTNAME
14
from bika.lims.content.bikaschema import BikaSchema
15
from bika.lims.interfaces import IDeactivable
16
from bika.lims.interfaces import IPricelist
17
from DateTime import DateTime
18
from Products.Archetypes.public import BaseFolder
19
from Products.Archetypes.public import BooleanField
20
from Products.Archetypes.public import BooleanWidget
21
from Products.Archetypes.public import DecimalWidget
22
from Products.Archetypes.public import FixedPointField
23
from Products.Archetypes.public import Schema
24
from Products.Archetypes.public import SelectionWidget
25
from Products.Archetypes.public import StringField
26
from Products.Archetypes.public import registerType
27
from zope.interface import implements
28
29
30
schema = BikaSchema.copy() + Schema((
31
32
    StringField(
33
        "Type",
34
        required=1,
35
        vocabulary=PRICELIST_TYPES,
36
        widget=SelectionWidget(
37
            format="select",
38
            label=_("Pricelist for"),
39
        ),
40
    ),
41
42
    BooleanField(
43
        "BulkDiscount",
44
        default=False,
45
        widget=SelectionWidget(
46
            label=_("Bulk discount applies"),
47
        ),
48
    ),
49
50
    FixedPointField(
51
        "BulkPrice",
52
        widget=DecimalWidget(
53
            label=_("Discount %"),
54
            description=_("Enter discount percentage value"),
55
        ),
56
    ),
57
58
    BooleanField(
59
        "Descriptions",
60
        default=False,
61
        widget=BooleanWidget(
62
            label=_("Include descriptions"),
63
            description=_("Select if the descriptions should be included"),
64
        ),
65
    ),
66
67
    RemarksField(
68
        "Remarks",
69
        searchable=True,
70
        widget=RemarksWidget(
71
            label=_("Remarks"),
72
        ),
73
    )),
74
)
75
76
Field = schema["title"]
77
Field.required = 1
78
Field.widget.visible = True
79
80
Field = schema["effectiveDate"]
81
Field.schemata = "default"
82
# If no date is selected the item will be publishedimmediately.
83
Field.required = 0
84
Field.widget.visible = True
85
86
Field = schema["expirationDate"]
87
Field.schemata = "default"
88
# If no date is chosen, it will never expire.
89
Field.required = 0
90
Field.widget.visible = True
91
92
93
class Pricelist(BaseFolder):
94
    """Pricelist content
95
    """
96
    implements(IPricelist, IDeactivable)
97
98
    security = ClassSecurityInfo()
99
    displayContentsTab = False
100
    schema = schema
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable schema does not seem to be defined.
Loading history...
101
    _at_rename_after_creation = True
102
103
    def _renameAfterCreation(self, check_auto_id=False):
104
        from bika.lims.idserver import renameAfterCreation
105
        renameAfterCreation(self)
106
107
    @security.public
108
    def current_date(self):
109
        """ return current date """
110
        return DateTime()
111
112
113
registerType(Pricelist, PROJECTNAME)
114