1 # Copyright (C) 2010 Richard Lincoln
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, USA
17 from CIM14
.IEC61970
.Core
.IdentifiedObject
import IdentifiedObject
19 class Charge(IdentifiedObject
):
20 """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.
23 def __init__(self
, kind
="demandCharge", variablePortion
=0.0, AuxiliaryAccounts
=None, ParentCharge
=None, ChildCharges
=None, fixedPortion
=None, ConsumptionTariffIntervals
=None, TimeTariffIntervals
=None, *args
, **kw_args
):
24 """Initialises a new 'Charge' instance.
26 @param kind: The kind of charge to be applied. Values are: "demandCharge", "other", "auxiliaryCharge", "taxCharge", "consumptionCharge"
27 @param variablePortion: The variable portion of this charge element, calculated as a percentage of the total amount of a parent charge.
28 @param AuxiliaryAccounts: All auxiliary accounts to which this charge must be levied.
30 @param ChildCharges: All sub-components of this complex charge.
31 @param fixedPortion: The fixed portion of this charge element.
32 @param ConsumptionTariffIntervals: Tariff intervals to which this consumption-based charge must be levied.
33 @param TimeTariffIntervals: Tariff intervals to which this time-based charge must be levied.
35 #: The kind of charge to be applied. Values are: "demandCharge", "other", "auxiliaryCharge", "taxCharge", "consumptionCharge"
38 #: The variable portion of this charge element, calculated as a percentage of the total amount of a parent charge.
39 self
.variablePortion
= variablePortion
41 self
._AuxiliaryAccounts
= []
42 self
.AuxiliaryAccounts
= [] if AuxiliaryAccounts
is None else AuxiliaryAccounts
44 self
._ParentCharge
= None
45 self
.ParentCharge
= ParentCharge
47 self
._ChildCharges
= []
48 self
.ChildCharges
= [] if ChildCharges
is None else ChildCharges
50 self
.fixedPortion
= fixedPortion
52 self
._ConsumptionTariffIntervals
= []
53 self
.ConsumptionTariffIntervals
= [] if ConsumptionTariffIntervals
is None else ConsumptionTariffIntervals
55 self
._TimeTariffIntervals
= []
56 self
.TimeTariffIntervals
= [] if TimeTariffIntervals
is None else TimeTariffIntervals
58 super(Charge
, self
).__init
__(*args
, **kw_args
)
60 _attrs
= ["kind", "variablePortion"]
61 _attr_types
= {"kind": str, "variablePortion": float}
62 _defaults
= {"kind": "demandCharge", "variablePortion": 0.0}
63 _enums
= {"kind": "ChargeKind"}
64 _refs
= ["AuxiliaryAccounts", "ParentCharge", "ChildCharges", "fixedPortion", "ConsumptionTariffIntervals", "TimeTariffIntervals"]
65 _many_refs
= ["AuxiliaryAccounts", "ChildCharges", "ConsumptionTariffIntervals", "TimeTariffIntervals"]
67 def getAuxiliaryAccounts(self
):
68 """All auxiliary accounts to which this charge must be levied.
70 return self
._AuxiliaryAccounts
72 def setAuxiliaryAccounts(self
, value
):
73 for p
in self
._AuxiliaryAccounts
:
74 filtered
= [q
for q
in p
.Charges
if q
!= self
]
75 self
._AuxiliaryAccounts
._Charges
= filtered
77 if self
not in r
._Charges
:
78 r
._Charges
.append(self
)
79 self
._AuxiliaryAccounts
= value
81 AuxiliaryAccounts
= property(getAuxiliaryAccounts
, setAuxiliaryAccounts
)
83 def addAuxiliaryAccounts(self
, *AuxiliaryAccounts
):
84 for obj
in AuxiliaryAccounts
:
85 if self
not in obj
._Charges
:
86 obj
._Charges
.append(self
)
87 self
._AuxiliaryAccounts
.append(obj
)
89 def removeAuxiliaryAccounts(self
, *AuxiliaryAccounts
):
90 for obj
in AuxiliaryAccounts
:
91 if self
in obj
._Charges
:
92 obj
._Charges
.remove(self
)
93 self
._AuxiliaryAccounts
.remove(obj
)
95 def getParentCharge(self
):
97 return self
._ParentCharge
99 def setParentCharge(self
, value
):
100 if self
._ParentCharge
is not None:
101 filtered
= [x
for x
in self
.ParentCharge
.ChildCharges
if x
!= self
]
102 self
._ParentCharge
._ChildCharges
= filtered
104 self
._ParentCharge
= value
105 if self
._ParentCharge
is not None:
106 if self
not in self
._ParentCharge
._ChildCharges
:
107 self
._ParentCharge
._ChildCharges
.append(self
)
109 ParentCharge
= property(getParentCharge
, setParentCharge
)
111 def getChildCharges(self
):
112 """All sub-components of this complex charge.
114 return self
._ChildCharges
116 def setChildCharges(self
, value
):
117 for x
in self
._ChildCharges
:
118 x
.ParentCharge
= None
120 y
._ParentCharge
= self
121 self
._ChildCharges
= value
123 ChildCharges
= property(getChildCharges
, setChildCharges
)
125 def addChildCharges(self
, *ChildCharges
):
126 for obj
in ChildCharges
:
127 obj
.ParentCharge
= self
129 def removeChildCharges(self
, *ChildCharges
):
130 for obj
in ChildCharges
:
131 obj
.ParentCharge
= None
133 # The fixed portion of this charge element.
136 def getConsumptionTariffIntervals(self
):
137 """Tariff intervals to which this consumption-based charge must be levied.
139 return self
._ConsumptionTariffIntervals
141 def setConsumptionTariffIntervals(self
, value
):
142 for p
in self
._ConsumptionTariffIntervals
:
143 filtered
= [q
for q
in p
.Charges
if q
!= self
]
144 self
._ConsumptionTariffIntervals
._Charges
= filtered
146 if self
not in r
._Charges
:
147 r
._Charges
.append(self
)
148 self
._ConsumptionTariffIntervals
= value
150 ConsumptionTariffIntervals
= property(getConsumptionTariffIntervals
, setConsumptionTariffIntervals
)
152 def addConsumptionTariffIntervals(self
, *ConsumptionTariffIntervals
):
153 for obj
in ConsumptionTariffIntervals
:
154 if self
not in obj
._Charges
:
155 obj
._Charges
.append(self
)
156 self
._ConsumptionTariffIntervals
.append(obj
)
158 def removeConsumptionTariffIntervals(self
, *ConsumptionTariffIntervals
):
159 for obj
in ConsumptionTariffIntervals
:
160 if self
in obj
._Charges
:
161 obj
._Charges
.remove(self
)
162 self
._ConsumptionTariffIntervals
.remove(obj
)
164 def getTimeTariffIntervals(self
):
165 """Tariff intervals to which this time-based charge must be levied.
167 return self
._TimeTariffIntervals
169 def setTimeTariffIntervals(self
, value
):
170 for p
in self
._TimeTariffIntervals
:
171 filtered
= [q
for q
in p
.Charges
if q
!= self
]
172 self
._TimeTariffIntervals
._Charges
= filtered
174 if self
not in r
._Charges
:
175 r
._Charges
.append(self
)
176 self
._TimeTariffIntervals
= value
178 TimeTariffIntervals
= property(getTimeTariffIntervals
, setTimeTariffIntervals
)
180 def addTimeTariffIntervals(self
, *TimeTariffIntervals
):
181 for obj
in TimeTariffIntervals
:
182 if self
not in obj
._Charges
:
183 obj
._Charges
.append(self
)
184 self
._TimeTariffIntervals
.append(obj
)
186 def removeTimeTariffIntervals(self
, *TimeTariffIntervals
):
187 for obj
in TimeTariffIntervals
:
188 if self
in obj
._Charges
:
189 obj
._Charges
.remove(self
)
190 self
._TimeTariffIntervals
.remove(obj
)