Пример #1
0
    def _get_rate_request_xml(self, carrier, carrier_service):
        SaleConfiguration = Pool().get("sale.configuration")
        Uom = Pool().get("product.uom")
        config = SaleConfiguration(1)

        code = length = width = height = dimensions_symbol = None
        box_type = config.ups_box_type
        if box_type:
            code = box_type.code
            length = box_type.length
            height = box_type.height
            width = box_type.width
            dimensions_symbol = box_type.distance_unit and box_type.distance_unit.symbol.upper()

        package_type = RatingService.packaging_type(Code=code)

        package_weight = RatingService.package_weight_type(
            Weight="%.2f" % Uom.compute_qty(self.weight_uom, self.weight, carrier.ups_weight_uom),
            Code=carrier.ups_weight_uom_code,
        )
        package_service_options = RatingService.package_service_options_type(
            RatingService.insured_value_type(MonetaryValue="0")
        )

        args = [package_type, package_weight, package_service_options]

        # Only send dimensions if box type has all information
        if length and width and height and dimensions_symbol:
            package_dimensions = RatingService.dimensions_type(
                Code=dimensions_symbol, Length=str(length), Width=str(width), Height=str(height)
            )
            args.append(package_dimensions)

        shipment_args = [RatingService.package_type(*args)]

        from_address = self._get_ship_from_address()

        shipment_args.extend(
            [
                from_address.to_ups_shipper(carrier=carrier),  # Shipper
                self.shipment_address.to_ups_to_address(),  # Ship to
                from_address.to_ups_from_address(),  # Ship from
            ]
        )

        if carrier.ups_negotiated_rates:
            shipment_args.append(RatingService.rate_information_type(negotiated=True))

        if carrier_service:
            # TODO: handle ups_saturday_delivery
            shipment_args.append(RatingService.service_type(Code=carrier_service.code))
            request_option = E.RequestOption("Rate")
        else:
            request_option = E.RequestOption("Shop")

        return RatingService.rating_request_type(E.Shipment(*shipment_args), RequestOption=request_option)
Пример #2
0
    def get_ups_package_container_rate(self):
        """
        Return UPS package container for a single package
        """
        Uom = Pool().get('product.uom')

        shipment = self.shipment
        carrier = shipment.carrier

        if self.box_type:
            code = self.box_type.code
            length = self.box_type.length
            height = self.box_type.height
            width = self.box_type.width
            dimensions_symbol = self.box_type.distance_unit and \
                self.box_type.distance_unit.symbol.upper()
        else:
            code = '02'
            length = self.length
            height = self.height
            width = self.width
            dimensions_symbol = self.distance_unit and \
                self.distance_unit.symbol.upper()

        package_type = RatingService.packaging_type(Code=code)
        package_weight = RatingService.package_weight_type(
            Weight="%.2f" % Uom.compute_qty(
                self.weight_uom, self.weight, carrier.ups_weight_uom
            ),
            Code=carrier.ups_weight_uom_code,
        )
        package_service_options = RatingService.package_service_options_type(
            RatingService.insured_value_type(MonetaryValue='0')
        )

        args = [package_type, package_weight, package_service_options]

        # Only send dimensions if the box type is 'Customer Supplied Package'
        if code == '02' and length and width and height and dimensions_symbol:
            package_dimensions = RatingService.dimensions_type(
                Code=dimensions_symbol,
                Length=str(length),
                Width=str(width),
                Height=str(height)
            )
            args.append(package_dimensions)

        package_container = RatingService.package_type(*args)
        return package_container