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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
@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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
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