Skip to content

CapitalExpenditure¤

CapitalExpenditure dataclass ¤

CapitalExpenditure(
    asset_number: str,
    depreciation_end_year: int,
    price: float,
    currency: str,
)

Represents the capitalExpenditure element in an equipment register.

Parameters:

Name Type Description Default
asset_number str

The asset number in the financial system.

required
depreciation_end_year int

The year (inclusive) that depreciation ends for the asset.

required
price float

The purchase price of the asset.

required
currency str

The currency associated with the price.

required

asset_number instance-attribute ¤

asset_number: str

The asset number in the financial system.

currency instance-attribute ¤

currency: str

The currency associated with the price.

depreciation_end_year instance-attribute ¤

depreciation_end_year: int

The year (inclusive) that depreciation ends for the asset.

price instance-attribute ¤

price: float

The price of the asset.

from_xml classmethod ¤

from_xml(element: Element[str]) -> CapitalExpenditure

Convert an XML element into a CapitalExpenditure instance.

Parameters:

Name Type Description Default
element Element[str]

A capitalExpenditure XML element from an equipment register.

required

Returns:

Type Description
CapitalExpenditure

The CapitalExpenditure instance.

Source code in src/msl/equipment/schema.py
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
@classmethod
def from_xml(cls, element: Element[str]) -> CapitalExpenditure:
    """Convert an XML element into a [CapitalExpenditure][msl.equipment.schema.CapitalExpenditure] instance.

    Args:
        element: A [capitalExpenditure][type_capitalExpenditure] XML element
            from an equipment register.

    Returns:
        The [CapitalExpenditure][msl.equipment.schema.CapitalExpenditure] instance.
    """
    # Schema forces order
    return cls(
        asset_number=element[0].text or "",
        depreciation_end_year=int(element[1].text or 0),
        price=float(element[2].text or 0),
        currency=element[2].attrib["currency"],
    )

to_xml ¤

to_xml() -> Element[str]

Convert the CapitalExpenditure class into an XML element.

Returns:

Type Description
Element[str]

The CapitalExpenditure as an XML element.

Source code in src/msl/equipment/schema.py
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
def to_xml(self) -> Element[str]:
    """Convert the [CapitalExpenditure][msl.equipment.schema.CapitalExpenditure] class into an XML element.

    Returns:
        The [CapitalExpenditure][msl.equipment.schema.CapitalExpenditure] as an XML element.
    """
    e = Element("capitalExpenditure")

    an = SubElement(e, "assetNumber")
    an.text = self.asset_number

    dey = SubElement(e, "depreciationEndYear")
    dey.text = str(self.depreciation_end_year)

    p = SubElement(e, "price", attrib={"currency": self.currency})
    p.text = f"{self.price:.14g}"

    return e