from typing import List, cast from .logistics_incoterm_responsibility_data import INCOTERMS from .logistics_incoterm_responsibility_types import IncotermResponsibility, Party def incoterm_responsibility(rule: str, edition: int) -> IncotermResponsibility: """Where the seller delivers (and risk passes) under an Incoterms rule, and which party pays for each stage, from the ICC rules for the edition named.""" if isinstance(edition, bool) or not isinstance(edition, int): raise TypeError("edition must be a year, received %r" % (edition,)) editions: List[int] = [] for r in INCOTERMS: if r.edition not in editions: editions.append(r.edition) if edition not in editions: raise ValueError( "no data for Incoterms %d: this version covers %s" % (edition, ", ".join(str(e) for e in editions)) ) row = next((r for r in INCOTERMS if r.edition == edition and r.rule == rule), None) if row is None: rules = ", ".join(r.rule for r in INCOTERMS if r.edition == edition) raise ValueError('unknown Incoterms %d rule "%s": expected one of %s' % (edition, rule, rules)) return IncotermResponsibility( rule=row.rule, edition=row.edition, name=row.name, any_mode=row.any_mode, delivery=row.delivery, risk_passes_at_destination=row.risk_passes_at_destination, loading_at_origin=cast(Party, row.loading_at_origin), export_clearance=cast(Party, row.export_clearance), main_carriage=cast(Party, row.main_carriage), insurance_by=cast(Party, row.insurance_by) if row.insurance_by is not None else None, insurance_cover=row.insurance_cover, unloading_at_destination=cast(Party, row.unloading_at_destination), import_clearance=cast(Party, row.import_clearance), import_duties=cast(Party, row.import_duties), )