Skip to content

Financial¤

Financial dataclass ¤

Financial(
    capital_expenditure: CapitalExpenditure | None = None,
    purchase_year: int = 0,
    warranty_expiration_date: date | None = None,
)

Represents the financial element in an equipment register.

Parameters:

Name Type Description Default
capital_expenditure CapitalExpenditure | None

The equipment is a capital expenditure.

None
purchase_year int

The (approximate) year that the equipment was purchased. A value of 0 represents that the year is unknown.

0
warranty_expiration_date date | None

Approximate date that the warranty expires.

None

capital_expenditure class-attribute instance-attribute ¤

capital_expenditure: CapitalExpenditure | None = None

The equipment is a capital expenditure.

purchase_year class-attribute instance-attribute ¤

purchase_year: int = 0

The (approximate) year that the equipment was purchased. A value of 0 represents that the year is unknown.

warranty_expiration_date class-attribute instance-attribute ¤

warranty_expiration_date: date | None = None

Approximate date that the warranty expires.

from_xml classmethod ¤

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

Convert an XML element into a Financial instance.

Parameters:

Name Type Description Default
element Element[str]

A financial XML element from an equipment register.

required

Returns:

Type Description
Financial

The Financial instance.

Source code in src/msl/equipment/schema.py
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
@classmethod
def from_xml(cls, element: Element[str]) -> Financial:
    """Convert an XML element into a [Financial][msl.equipment.schema.Financial] instance.

    Args:
        element: A [financial][type_financial] XML element from an equipment register.

    Returns:
        The [Financial][msl.equipment.schema.Financial] instance.
    """
    # Schema defines <financial> using xsd:all, which allows sub-elements to appear (or not appear) in any order
    # Using str.endswith() allows for ignoring XML namespaces that may be associated with each tag
    cap_ex, warranty, year = None, None, 0
    for child in element:
        if child.tag.endswith("capitalExpenditure"):
            cap_ex = CapitalExpenditure.from_xml(child)
        elif child.tag.endswith("warrantyExpirationDate"):
            warranty = _date.fromisoformat(child.text or "")
        else:
            year = int(child.text or 0)
    return cls(capital_expenditure=cap_ex, purchase_year=year, warranty_expiration_date=warranty)

to_xml ¤

to_xml() -> Element[str]

Convert the Financial class into an XML element.

Returns:

Type Description
Element[str]

The Financial as an XML element.

Source code in src/msl/equipment/schema.py
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
def to_xml(self) -> Element[str]:
    """Convert the [Financial][msl.equipment.schema.Financial] class into an XML element.

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

    if self.capital_expenditure is not None:
        e.append(self.capital_expenditure.to_xml())

    if self.purchase_year > 0:
        py = SubElement(e, "purchaseYear")
        py.text = str(self.purchase_year)

    if self.warranty_expiration_date is not None:
        wed = SubElement(e, "warrantyExpirationDate")
        wed.text = self.warranty_expiration_date.isoformat()

    return e