コード例 #1
0
ファイル: stock.py プロジェクト: mbehrle/trytond-shipping-ups
    def _get_shipment_confirm_xml(self):
        """
        Return XML of shipment for shipment_confirm
        """
        Company = Pool().get('company.company')
        UPSConfiguration = Pool().get('ups.configuration')

        ups_config = UPSConfiguration(1)
        if not self.ups_service_type:
            self.raise_user_error('ups_service_type_missing')

        payment_info_prepaid = \
            ShipmentConfirm.payment_information_prepaid_type(
                AccountNumber=ups_config.shipper_no
            )
        payment_info = ShipmentConfirm.payment_information_type(
            payment_info_prepaid)
        packages = self._get_ups_packages()
        shipment_service = ShipmentConfirm.shipment_service_option_type(
            SaturdayDelivery='1' if self.ups_saturday_delivery
            else 'None'
        )
        description = ','.join([
            move.product.name for move in self.outgoing_moves
        ])

        shipment_args = [
            self.warehouse.address.to_ups_shipper(),
            self.delivery_address.to_ups_to_address(),
            self.warehouse.address.to_ups_from_address(),
            ShipmentConfirm.service_type(Code=self.ups_service_type.code),
            payment_info, shipment_service,
        ]
        if ups_config.negotiated_rates:
            shipment_args.append(
                ShipmentConfirm.rate_information_type(negotiated=True)
            )
        if self.warehouse.address.country.code == 'US' and \
                self.delivery_address.country.code in ['PR', 'CA']:
            # Special case for US to PR or CA InvoiceLineTotal should be sent
            monetary_value = str(sum(map(
                lambda move: move.get_monetary_value_for_ups(),
                self.outgoing_moves
            )))

            company_id = Transaction().context.get('company')
            if not company_id:
                self.raise_user_error("Company is not in context")

            company = Company(company_id)
            shipment_args.append(ShipmentConfirm.invoice_line_total_type(
                MonetaryValue=monetary_value,
                CurrencyCode=company.currency.code
            ))

        shipment_args.extend(packages)
        shipment_confirm = ShipmentConfirm.shipment_confirm_request_type(
            *shipment_args, Description=description[:35]
        )
        return shipment_confirm
コード例 #2
0
    def _get_shipment_confirm_xml(self):
        """
        Return XML of shipment for shipment_confirm
        """
        Company = Pool().get('company.company')
        UPSConfiguration = Pool().get('ups.configuration')

        ups_config = UPSConfiguration(1)
        if not self.ups_service_type:
            self.raise_user_error('ups_service_type_missing')

        payment_info_prepaid = \
            ShipmentConfirm.payment_information_prepaid_type(
                AccountNumber=ups_config.shipper_no
            )
        payment_info = ShipmentConfirm.payment_information_type(
            payment_info_prepaid)
        packages = self._get_ups_packages()
        shipment_service = ShipmentConfirm.shipment_service_option_type(
            SaturdayDelivery='1' if self.ups_saturday_delivery
            else 'None'
        )
        description = ','.join([
            move.product.name for move in self.outgoing_moves
        ])

        shipment_args = [
            self.warehouse.address.to_ups_shipper(),
            self.delivery_address.to_ups_to_address(),
            self.warehouse.address.to_ups_from_address(),
            ShipmentConfirm.service_type(Code=self.ups_service_type.code),
            payment_info, shipment_service,
        ]
        if ups_config.negotiated_rates:
            shipment_args.append(
                ShipmentConfirm.rate_information_type(negotiated=True)
            )
        if self.warehouse.address.country.code == 'US' and \
                self.delivery_address.country.code in ['PR', 'CA']:
            # Special case for US to PR or CA InvoiceLineTotal should be sent
            monetary_value = str(sum(map(
                lambda move: move.get_monetary_value_for_ups(),
                self.outgoing_moves
            )))

            company_id = Transaction().context.get('company')
            if not company_id:
                self.raise_user_error("Company is not in context")

            company = Company(company_id)
            shipment_args.append(ShipmentConfirm.invoice_line_total_type(
                MonetaryValue=monetary_value,
                CurrencyCode=company.currency.code
            ))

        shipment_args.extend(packages)
        shipment_confirm = ShipmentConfirm.shipment_confirm_request_type(
            *shipment_args, Description=description[:35]
        )
        return shipment_confirm
コード例 #3
0
    def get_payment_info(type="prepaid", **kwargs):
        """Returns the payment info filled

        :param type: The payment type.

        .. note::
            if payment type is prepaid AccountNumber must be provided.
        """
        if type == 'prepaid':
            assert 'AccountNumber' in kwargs
            return ShipmentConfirm.payment_information_type(
                ShipmentConfirm.payment_information_prepaid_type(
                    AccountNumber=kwargs['AccountNumber']))
        else:
            raise Exception("Type %s is not supported" % type)
コード例 #4
0
    def get_payment_info(type="prepaid", **kwargs):
        """Returns the payment info filled

        :param type: The payment type.

        .. note::
            if payment type is prepaid AccountNumber must be provided.
        """
        if type == 'prepaid':
            assert 'AccountNumber' in kwargs
            return ShipmentConfirm.payment_information_type(
                ShipmentConfirm.payment_information_prepaid_type(
                    AccountNumber=kwargs['AccountNumber'])
            )
        else:
            raise Exception("Type %s is not supported" % type)
コード例 #5
0
    def _get_shipment_confirm_xml(self):
        """
        Return XML of shipment for shipment_confirm
        """
        Company = Pool().get("company.company")

        carrier = self.carrier
        if not self.ups_service_type:
            self.raise_user_error("ups_service_type_missing")

        payment_info_prepaid = ShipmentConfirm.payment_information_prepaid_type(AccountNumber=carrier.ups_shipper_no)
        payment_info = ShipmentConfirm.payment_information_type(payment_info_prepaid)
        packages = self._get_ups_packages()
        shipment_service = ShipmentConfirm.shipment_service_option_type(
            SaturdayDelivery="1" if self.ups_saturday_delivery else "None"
        )
        description = ",".join([move.product.name for move in self.outgoing_moves])
        from_address = self._get_ship_from_address()

        shipment_args = [
            from_address.to_ups_shipper(carrier=carrier),
            self.delivery_address.to_ups_to_address(),
            from_address.to_ups_from_address(),
            ShipmentConfirm.service_type(Code=self.ups_service_type.code),
            payment_info,
            shipment_service,
        ]
        if carrier.ups_negotiated_rates:
            shipment_args.append(ShipmentConfirm.rate_information_type(negotiated=True))
        if from_address.country.code == "US" and self.delivery_address.country.code in ["PR", "CA"]:
            # Special case for US to PR or CA InvoiceLineTotal should be sent
            monetary_value = str(sum(map(lambda move: move.get_monetary_value_for_ups(), self.outgoing_moves)))

            company_id = Transaction().context.get("company")
            if not company_id:
                self.raise_user_error("Company is not in context")

            company = Company(company_id)
            shipment_args.append(
                ShipmentConfirm.invoice_line_total_type(
                    MonetaryValue=monetary_value, CurrencyCode=company.currency.code
                )
            )

        shipment_args.extend(packages)
        shipment_confirm = ShipmentConfirm.shipment_confirm_request_type(*shipment_args, Description=description[:35])
        return shipment_confirm