Пример #1
0
def _extract_pickup_details(
    response: PickupCreationResponse, settings: Settings
) -> PickupDetails:
    pickup = XP.build(
        PickupCreationResponse,
        next(
            iter(
                response.xpath(
                    ".//*[local-name() = $name]", name="PickupCreationResponse"
                )
            ),
            None,
        ),
    )
    rate = XP.build(
        RateResultType,
        next(
            iter(response.xpath(".//*[local-name() = $name]", name="RateResult")), None
        ),
    )

    return PickupDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        confirmation_number=pickup.PRN,
        pickup_charge=ChargeDetails(
            name=rate.RateType,
            currency=rate.CurrencyCode,
            amount=NF.decimal(rate.GrandTotalOfAllCharge),
        ),
    )
Пример #2
0
def _extract_pickup_details(response: Element,
                            settings: Settings) -> PickupDetails:
    header = next((XP.build(PickupRequestHeaderType, elt)
                   for elt in response.xpath(".//*[local-name() = $name]",
                                             name="pickup-request-header")))
    price = next((XP.build(PickupRequestPriceType, elt)
                  for elt in response.xpath(".//*[local-name() = $name]",
                                            name="pickup-request-price")),
                 None)

    price_amount = sum(
        [
            NF.decimal(price.hst_amount or 0.0),
            NF.decimal(price.gst_amount or 0.0),
            NF.decimal(price.due_amount or 0.0),
        ],
        0.0,
    ) if price is not None else None

    return PickupDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        confirmation_number=header.request_id,
        pickup_date=DF.fdate(header.next_pickup_date),
        pickup_charge=ChargeDetails(name="Pickup fees",
                                    amount=NF.decimal(price_amount),
                                    currency="CAD")
        if price is not None else None,
    )
Пример #3
0
def _extract_pickup_details(reply: CreatePickupReply,
                            settings: Settings) -> PickupDetails:
    return PickupDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        confirmation_number=reply.PickupConfirmationNumber,
    )
Пример #4
0
def _extract_pickup(response: Element, settings: Settings) -> PickupDetails:
    pickup = ModifyPUResponse()
    pickup.build(response)
    pickup_charge = (
        ChargeDetails(
            name="Pickup Charge",
            amount=NF.decimal(pickup.PickupCharge),
            currency=pickup.CurrencyCode,
        )
        if pickup.PickupCharge is not None
        else None
    )
    pickup_date = (
        DF.fdate(pickup.NextPickupDate)
        if pickup.NextPickupDate is not None
        else None
    )

    return PickupDetails(
        carrier_name=settings.carrier_name,
        carrier_id=settings.carrier_id,
        confirmation_number=str(pickup.ConfirmationNumber[0]),
        pickup_date=pickup_date,
        pickup_charge=pickup_charge,
        ready_time=DF.ftime(pickup.ReadyByTime),
        closing_time=DF.ftime(pickup.CallInTime),
    )
Пример #5
0
def _extract_details(pickup: Pickup, settings: Settings) -> PickupDetails:

    return PickupDetails(carrier_id=settings.carrier_id,
                         carrier_name=settings.carrier_name,
                         confirmation_number=str(pickup.id),
                         closing_time=pickup.officeClose,
                         pickup_date=pickup.date,
                         ready_time=pickup.ready)
Пример #6
0
def _extract_pickup_details(reply: SchedulePickUpResponse,
                            settings: Settings) -> PickupDetails:

    return PickupDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        confirmation_number=reply.PickUpConfirmationNumber,
    )
Пример #7
0
def parse_pickup_response(response: Element, settings: Settings) -> Tuple[PickupDetails, List[Message]]:
    pickup_node = next(iter(response.xpath(".//*[local-name() = $name]", name="pickup")), None)
    pickup = XP.build(PickupV2, pickup_node)
    details: PickupDetails = PickupDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        confirmation_number=str(pickup.id),
        pickup_date=DF.fdatetime(pickup.pickup_date, '%Y-%m-%dT%H:%M:%S')
    )

    return details, parse_error_response(response, settings)
Пример #8
0
def _extract_pickup_details(response: Element, settings: Settings) -> PickupDetails:
    pickup = XP.find(
        "PickupCreationResponse", response, PickupCreationResponse, first=True
    )
    rate = XP.find("RateResult", response, RateResultType, first=True)

    return PickupDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        confirmation_number=pickup.PRN,
        pickup_charge=ChargeDetails(
            name=rate.RateType,
            currency=rate.CurrencyCode,
            amount=NF.decimal(rate.GrandTotalOfAllCharge),
        ),
    )
Пример #9
0
    ],
    "ready_time": "14:30",
    "closing_time": "17:00",
    "instruction": "Should not be folded",
    "package_location": "At the main entrance hall",
}

PICKUP_CANCEL_DATA = {"confirmation_number": "00110215"}


SCHEDULE_RETURNED_VALUE = (
    PickupDetails(
        carrier_id="canadapost",
        carrier_name="canadapost",
        confirmation_number="27241",
        pickup_date="2020-10-25",
        pickup_charge=ChargeDetails(name="Pickup fees", amount=0.0, currency="CAD"),
        ready_time="13:00",
        closing_time="17:00",
    ),
    [],
)

UPDATE_RETURNED_VALUE = (
    PickupDetails(
        carrier_id="canadapost",
        carrier_name="canadapost",
        confirmation_number="27241",
        pickup_date="2020-10-23",
        ready_time="14:30",
        closing_time="17:00",