1 # Copyright (C) 2010-2011 Richard Lincoln
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to
5 # deal in the Software without restriction, including without limitation the
6 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 # sell copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 from CIM14
.IEC61970
.Core
.IdentifiedObject
import IdentifiedObject
23 class Charge(IdentifiedObject
):
24 """A charge element associated with other entities such as tariff structures, auxiliary agreements or other charge elements. The total charge amount applicable to this instance of Charge is the sum of fixedPortion plus percentagePortion.
27 def __init__(self
, kind
="demandCharge", variablePortion
=0.0, AuxiliaryAccounts
=None, ParentCharge
=None, ChildCharges
=None, fixedPortion
=None, ConsumptionTariffIntervals
=None, TimeTariffIntervals
=None, *args
, **kw_args
):
28 """Initialises a new 'Charge' instance.
30 @param kind: The kind of charge to be applied. Values are: "demandCharge", "other", "auxiliaryCharge", "taxCharge", "consumptionCharge"
31 @param variablePortion: The variable portion of this charge element, calculated as a percentage of the total amount of a parent charge.
32 @param AuxiliaryAccounts: All auxiliary accounts to which this charge must be levied.
34 @param ChildCharges: All sub-components of this complex charge.
35 @param fixedPortion: The fixed portion of this charge element.
36 @param ConsumptionTariffIntervals: Tariff intervals to which this consumption-based charge must be levied.
37 @param TimeTariffIntervals: Tariff intervals to which this time-based charge must be levied.
39 #: The kind of charge to be applied. Values are: "demandCharge", "other", "auxiliaryCharge", "taxCharge", "consumptionCharge"
42 #: The variable portion of this charge element, calculated as a percentage of the total amount of a parent charge.
43 self
.variablePortion
= variablePortion
45 self
._AuxiliaryAccounts
= []
46 self
.AuxiliaryAccounts
= [] if AuxiliaryAccounts
is None else AuxiliaryAccounts
48 self
._ParentCharge
= None
49 self
.ParentCharge
= ParentCharge
51 self
._ChildCharges
= []
52 self
.ChildCharges
= [] if ChildCharges
is None else ChildCharges
54 self
.fixedPortion
= fixedPortion
56 self
._ConsumptionTariffIntervals
= []
57 self
.ConsumptionTariffIntervals
= [] if ConsumptionTariffIntervals
is None else ConsumptionTariffIntervals
59 self
._TimeTariffIntervals
= []
60 self
.TimeTariffIntervals
= [] if TimeTariffIntervals
is None else TimeTariffIntervals
62 super(Charge
, self
).__init
__(*args
, **kw_args
)
64 _attrs
= ["kind", "variablePortion"]
65 _attr_types
= {"kind": str, "variablePortion": float}
66 _defaults
= {"kind": "demandCharge", "variablePortion": 0.0}
67 _enums
= {"kind": "ChargeKind"}
68 _refs
= ["AuxiliaryAccounts", "ParentCharge", "ChildCharges", "fixedPortion", "ConsumptionTariffIntervals", "TimeTariffIntervals"]
69 _many_refs
= ["AuxiliaryAccounts", "ChildCharges", "ConsumptionTariffIntervals", "TimeTariffIntervals"]
71 def getAuxiliaryAccounts(self
):
72 """All auxiliary accounts to which this charge must be levied.
74 return self
._AuxiliaryAccounts
76 def setAuxiliaryAccounts(self
, value
):
77 for p
in self
._AuxiliaryAccounts
:
78 filtered
= [q
for q
in p
.Charges
if q
!= self
]
79 self
._AuxiliaryAccounts
._Charges
= filtered
81 if self
not in r
._Charges
:
82 r
._Charges
.append(self
)
83 self
._AuxiliaryAccounts
= value
85 AuxiliaryAccounts
= property(getAuxiliaryAccounts
, setAuxiliaryAccounts
)
87 def addAuxiliaryAccounts(self
, *AuxiliaryAccounts
):
88 for obj
in AuxiliaryAccounts
:
89 if self
not in obj
._Charges
:
90 obj
._Charges
.append(self
)
91 self
._AuxiliaryAccounts
.append(obj
)
93 def removeAuxiliaryAccounts(self
, *AuxiliaryAccounts
):
94 for obj
in AuxiliaryAccounts
:
95 if self
in obj
._Charges
:
96 obj
._Charges
.remove(self
)
97 self
._AuxiliaryAccounts
.remove(obj
)
99 def getParentCharge(self
):
101 return self
._ParentCharge
103 def setParentCharge(self
, value
):
104 if self
._ParentCharge
is not None:
105 filtered
= [x
for x
in self
.ParentCharge
.ChildCharges
if x
!= self
]
106 self
._ParentCharge
._ChildCharges
= filtered
108 self
._ParentCharge
= value
109 if self
._ParentCharge
is not None:
110 if self
not in self
._ParentCharge
._ChildCharges
:
111 self
._ParentCharge
._ChildCharges
.append(self
)
113 ParentCharge
= property(getParentCharge
, setParentCharge
)
115 def getChildCharges(self
):
116 """All sub-components of this complex charge.
118 return self
._ChildCharges
120 def setChildCharges(self
, value
):
121 for x
in self
._ChildCharges
:
122 x
.ParentCharge
= None
124 y
._ParentCharge
= self
125 self
._ChildCharges
= value
127 ChildCharges
= property(getChildCharges
, setChildCharges
)
129 def addChildCharges(self
, *ChildCharges
):
130 for obj
in ChildCharges
:
131 obj
.ParentCharge
= self
133 def removeChildCharges(self
, *ChildCharges
):
134 for obj
in ChildCharges
:
135 obj
.ParentCharge
= None
137 # The fixed portion of this charge element.
140 def getConsumptionTariffIntervals(self
):
141 """Tariff intervals to which this consumption-based charge must be levied.
143 return self
._ConsumptionTariffIntervals
145 def setConsumptionTariffIntervals(self
, value
):
146 for p
in self
._ConsumptionTariffIntervals
:
147 filtered
= [q
for q
in p
.Charges
if q
!= self
]
148 self
._ConsumptionTariffIntervals
._Charges
= filtered
150 if self
not in r
._Charges
:
151 r
._Charges
.append(self
)
152 self
._ConsumptionTariffIntervals
= value
154 ConsumptionTariffIntervals
= property(getConsumptionTariffIntervals
, setConsumptionTariffIntervals
)
156 def addConsumptionTariffIntervals(self
, *ConsumptionTariffIntervals
):
157 for obj
in ConsumptionTariffIntervals
:
158 if self
not in obj
._Charges
:
159 obj
._Charges
.append(self
)
160 self
._ConsumptionTariffIntervals
.append(obj
)
162 def removeConsumptionTariffIntervals(self
, *ConsumptionTariffIntervals
):
163 for obj
in ConsumptionTariffIntervals
:
164 if self
in obj
._Charges
:
165 obj
._Charges
.remove(self
)
166 self
._ConsumptionTariffIntervals
.remove(obj
)
168 def getTimeTariffIntervals(self
):
169 """Tariff intervals to which this time-based charge must be levied.
171 return self
._TimeTariffIntervals
173 def setTimeTariffIntervals(self
, value
):
174 for p
in self
._TimeTariffIntervals
:
175 filtered
= [q
for q
in p
.Charges
if q
!= self
]
176 self
._TimeTariffIntervals
._Charges
= filtered
178 if self
not in r
._Charges
:
179 r
._Charges
.append(self
)
180 self
._TimeTariffIntervals
= value
182 TimeTariffIntervals
= property(getTimeTariffIntervals
, setTimeTariffIntervals
)
184 def addTimeTariffIntervals(self
, *TimeTariffIntervals
):
185 for obj
in TimeTariffIntervals
:
186 if self
not in obj
._Charges
:
187 obj
._Charges
.append(self
)
188 self
._TimeTariffIntervals
.append(obj
)
190 def removeTimeTariffIntervals(self
, *TimeTariffIntervals
):
191 for obj
in TimeTariffIntervals
:
192 if self
in obj
._Charges
:
193 obj
._Charges
.remove(self
)
194 self
._TimeTariffIntervals
.remove(obj
)