def get_endicia_shipping_cost(self):
        """Returns the calculated shipping cost as sent by endicia

        :returns: The shipping cost in USD
        """
        endicia_credentials = self.company.get_endicia_credentials()

        if not self.endicia_mailclass:
            self.raise_user_error('mailclass_missing')

        calculate_postage_request = CalculatingPostageAPI(
            mailclass=self.endicia_mailclass.value,
            weightoz=sum(
                map(lambda move: move.get_weight_for_endicia(),
                    self.outgoing_moves)),
            from_postal_code=self.warehouse.address.zip,
            to_postal_code=self.delivery_address.zip,
            to_country_code=self.delivery_address.country.code,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=endicia_credentials.usps_test,
        )

        response = calculate_postage_request.send_request()

        return Decimal(
            objectify_response(response).PostagePrice.get('TotalAmount'))
    def get_endicia_shipping_cost(self):
        """Returns the calculated shipping cost as sent by endicia

        :returns: The shipping cost in USD
        """
        endicia_credentials = self.company.get_endicia_credentials()

        if not self.endicia_mailclass:
            self.raise_user_error('mailclass_missing')

        calculate_postage_request = CalculatingPostageAPI(
            mailclass=self.endicia_mailclass.value,
            weightoz=sum(map(
                lambda move: move.get_weight_for_endicia(), self.outgoing_moves
            )),
            from_postal_code=self.warehouse.address.zip,
            to_postal_code=self.delivery_address.zip,
            to_country_code=self.delivery_address.country.code,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=endicia_credentials.usps_test,
        )

        response = calculate_postage_request.send_request()

        return Decimal(
            objectify_response(response).PostagePrice.get('TotalAmount')
        )
    def get_endicia_shipping_cost(self, mailclass=None):
        """Returns the calculated shipping cost as sent by endicia

        :param mailclass: endicia mailclass for which cost to be fetched

        :returns: The shipping cost in USD
        """
        Carrier = Pool().get('carrier')
        EndiciaConfiguration = Pool().get('endicia.configuration')

        endicia_credentials = EndiciaConfiguration(1).get_endicia_credentials()
        carrier, = Carrier.search(['carrier_cost_method', '=', 'endicia'])

        if not mailclass and not self.endicia_mailclass:
            self.raise_user_error('mailclass_missing')

        from_address = self._get_ship_from_address()
        to_address = self.shipment_address
        to_zip = to_address.zip

        if to_address.country and to_address.country.code == 'US':
            # Domestic
            to_zip = to_zip and to_zip[:5]
        else:
            # International
            to_zip = to_zip and to_zip[:15]

        # Endicia only support 1 decimal place in weight
        weight_oz = self.package_weight.quantize(
            Decimal('.1'), rounding=ROUND_UP
        )
        calculate_postage_request = CalculatingPostageAPI(
            mailclass=mailclass or self.endicia_mailclass.value,
            MailpieceShape=self.endicia_mailpiece_shape,
            weightoz=weight_oz,
            from_postal_code=from_address.zip and from_address.zip[:5],
            to_postal_code=to_zip,
            to_country_code=to_address.country and to_address.country.code,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=endicia_credentials.is_test,
        )

        # Logging.
        logger.debug(
            'Making Postage Request for shipping cost of'
            'Sale ID: {0} and Carrier ID: {1}'
            .format(self.id, carrier.id)
        )
        logger.debug('--------POSTAGE REQUEST--------')
        logger.debug(str(calculate_postage_request.to_xml()))
        logger.debug('--------END REQUEST--------')

        try:
            response = calculate_postage_request.send_request()
        except RequestError, e:
            self.raise_user_error(unicode(e))
    def get_endicia_shipping_cost(self):
        """Returns the calculated shipping cost as sent by endicia

        :returns: The shipping cost in USD
        """
        Carrier = Pool().get('carrier')
        EndiciaConfiguration = Pool().get('endicia.configuration')

        endicia_credentials = EndiciaConfiguration(1).get_endicia_credentials()
        carrier, = Carrier.search(['carrier_cost_method', '=', 'endicia'])

        if not self.endicia_mailclass:
            self.raise_user_error('mailclass_missing')

        from_address = self._get_ship_from_address()
        to_address = self.delivery_address
        to_zip = to_address.zip

        if to_address.country and to_address.country.code == 'US':
            # Domestic
            to_zip = to_zip and to_zip[:5]
        else:
            # International
            to_zip = to_zip and to_zip[:15]

        # Endicia only support 1 decimal place in weight
        weight_oz = "%.1f" % self.weight
        calculate_postage_request = CalculatingPostageAPI(
            mailclass=self.endicia_mailclass.value,
            MailpieceShape=self.endicia_mailpiece_shape,
            weightoz=weight_oz,
            from_postal_code=from_address.zip and from_address.zip[:5],
            to_postal_code=to_zip,
            to_country_code=to_address.country and to_address.country.code,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=endicia_credentials.is_test,
        )

        # Logging.
        logger.debug(
            'Making Postage Request for'
            'Shipment ID: {0} and Carrier ID: {1}'
            .format(self.id, carrier.id)
        )
        logger.debug('--------POSTAGE REQUEST--------')
        logger.debug(str(calculate_postage_request.to_xml()))
        logger.debug('--------END REQUEST--------')

        try:
            response = calculate_postage_request.send_request()
        except RequestError, error:
            self.raise_user_error('error_label', error_args=(error,))
    def get_endicia_shipping_cost(self, mailclass=None):
        """Returns the calculated shipping cost as sent by endicia

        :param mailclass: endicia mailclass for which cost to be fetched

        :returns: The shipping cost in USD
        """
        Carrier = Pool().get('carrier')
        EndiciaConfiguration = Pool().get('endicia.configuration')

        endicia_credentials = EndiciaConfiguration(1).get_endicia_credentials()
        carrier, = Carrier.search(['carrier_cost_method', '=', 'endicia'])

        if not mailclass and not self.endicia_mailclass:
            self.raise_user_error('mailclass_missing')

        from_address = self._get_ship_from_address()
        to_address = self.shipment_address
        to_zip = to_address.zip

        if to_address.country and to_address.country.code == 'US':
            # Domestic
            to_zip = to_zip and to_zip[:5]
        else:
            # International
            to_zip = to_zip and to_zip[:15]

        # Endicia only support 1 decimal place in weight
        weight_oz = "%.1f" % self.package_weight
        calculate_postage_request = CalculatingPostageAPI(
            mailclass=mailclass or self.endicia_mailclass.value,
            MailpieceShape=self.endicia_mailpiece_shape,
            weightoz=weight_oz,
            from_postal_code=from_address.zip and from_address.zip[:5],
            to_postal_code=to_zip,
            to_country_code=to_address.country and to_address.country.code,
            accountid=endicia_credentials.account_id,
            requesterid=endicia_credentials.requester_id,
            passphrase=endicia_credentials.passphrase,
            test=endicia_credentials.is_test,
        )

        # Logging.
        logger.debug('Making Postage Request for shipping cost of'
                     'Sale ID: {0} and Carrier ID: {1}'.format(
                         self.id, carrier.id))
        logger.debug('--------POSTAGE REQUEST--------')
        logger.debug(str(calculate_postage_request.to_xml()))
        logger.debug('--------END REQUEST--------')

        try:
            response = calculate_postage_request.send_request()
        except RequestError, e:
            self.raise_user_error(unicode(e))
    def get_endicia_shipping_cost(self):
        """Returns the calculated shipping cost as sent by endicia

        :returns: The shipping cost in USD
        """
        Carrier = Pool().get('carrier')

        carrier, = Carrier.search(['carrier_cost_method', '=', 'endicia'])

        if not self.endicia_mailclass:
            self.raise_user_error('mailclass_missing')

        from_address = self._get_ship_from_address()
        to_address = self.delivery_address
        to_zip = to_address.zip

        if to_address.country and to_address.country.code == 'US':
            # Domestic
            to_zip = to_zip and to_zip[:5]
        else:
            # International
            to_zip = to_zip and to_zip[:15]

        # Endicia only support 1 decimal place in weight
        weight_oz = "%.1f" % self.weight
        calculate_postage_request = CalculatingPostageAPI(
            mailclass=self.endicia_mailclass.value,
            weightoz=weight_oz,
            from_postal_code=from_address.zip and from_address.zip[:5],
            to_postal_code=to_zip,
            to_country_code=to_address.country and to_address.country.code,
            accountid=carrier.endicia_account_id,
            requesterid=carrier.endicia_requester_id,
            passphrase=carrier.endicia_passphrase,
            test=carrier.endicia_is_test,
        )
        calculate_postage_request.mailpieceshape = self.endicia_mailpiece_shape

        # Logging.
        logger.debug('Making Postage Request for'
                     'Shipment ID: {0} and Carrier ID: {1}'.format(
                         self.id, carrier.id))
        logger.debug('--------POSTAGE REQUEST--------')
        logger.debug(str(calculate_postage_request.to_xml()))
        logger.debug('--------END REQUEST--------')

        try:
            response = calculate_postage_request.send_request()
        except RequestError, error:
            self.raise_user_error('error_label', error_args=(error, ))
Exemple #7
0
 def test0030_calculating_postage_request(self):
     calculate_postage_request = CalculatingPostageAPI(
         mailclass='First',
         weightoz=10.00,
         from_postal_code="83702",
         to_postal_code="84301",
         to_country_code="US",
         requesterid=REQUESTER_ID,
         accountid=ACCOUNT_ID,
         passphrase=PASSPHRASE,
         test=True,
     )
     print calculate_postage_request.to_xml()
     response = calculate_postage_request.send_request()
     print objectify_response(response)
Exemple #8
0
 def test0030_calculating_postage_request(self):
     calculate_postage_request = CalculatingPostageAPI(
         mailclass='First',
         weightoz=10.00,
         from_postal_code="83702",
         to_postal_code="84301",
         to_country_code="US",
         requesterid=REQUESTER_ID,
         accountid=ACCOUNT_ID,
         passphrase=PASSPHRASE,
         test=True,
     )
     print calculate_postage_request.to_xml()
     response = calculate_postage_request.send_request()
     print objectify_response(response)
    def get_sale_price(self, carrier):
        """Estimates the shipment rate for the provided shipment
        """
        company_obj = self.pool.get('company.company')
        shipment_obj = self.pool.get('stock.shipment.out')
        if carrier.carrier_cost_method != 'endicia-usps':
            return super(CarrierUSPS, self).get_sale_price(carrier)
        # Getting the api credentials to be used in shipping label generation
        # endicia credentials are in the format : 
        # EndiciaSettings(account_id, requester_id, passphrase, is_test)
        endicia_credentials = company_obj.get_endicia_credentials()
        shipment_id = Transaction().context['id']

        if shipment_id:
            shipment = shipment_obj.browse(shipment_id)

            #From location is the warehouse location. So it must be filled.
            location = shipment.warehouse.address
            if not location:
                self.raise_user_error('location_required')
            line_weights = shipment_obj.get_move_line_weights(shipment_id, 'oz')
            calculate_postage_request = CalculatingPostageAPI(
                mailclass = carrier.carrier_product.code,
                weightoz = sum(line_weights.values()),
                from_postal_code = location.zip,
                to_postal_code = shipment.delivery_address.zip,
                to_country_code = shipment.delivery_address.country.code,
                accountid = endicia_credentials.account_id,
                requesterid = endicia_credentials.requester_id,
                passphrase = endicia_credentials.passphrase,
                test = endicia_credentials.usps_test,
                )
            response = calculate_postage_request.send_request()
            return objectify_response(response).PostagePrice.\
                get('TotalAmount'), False
        else:
            return 0, False
Exemple #10
0
                                   accountid=ACCOUNT_ID,
                                   passphrase=PASSPHRASE,
                                   test=True,
                                      )
change_pp_api.to_xml()
response = change_pp_api.send_request()
objectify_response(response)
#
#Calculate postage
#
calculate_postage_request = CalculatingPostageAPI(
                               mailclass='First',
                               weightoz=10.00,
                               from_postal_code="83702",
                               to_postal_code="84301",
                               to_country_code="US",
                               requesterid=REQUESTER_ID,
                               accountid=ACCOUNT_ID,
                               passphrase=PASSPHRASE,
                               test=True,                                    
                            )
print calculate_postage_request.to_xml()
response = calculate_postage_request.send_request()
print response
print 'calculate', objectify_response(response).PostagePrice.get('TotalAmount')

#
#Refund Request API
#
refund_request = RefundRequestAPI(
                               pic_number=pic_number,