def get_shipping_rate(self, carrier, carrier_service=None, silent=False): """ Call the rates service and get possible quotes for shipment for eligible mail classes """ Currency = Pool().get('currency.currency') UOM = Pool().get('product.uom') ModelData = Pool().get('ir.model.data') if carrier.carrier_cost_method != "endicia": return super(Sale, self).get_shipping_rate( carrier, carrier_service, silent ) from_address = self._get_ship_from_address() if self.shipment_address.country.code == "US": mailclass_type = "Domestic" else: mailclass_type = "International" uom_oz = UOM.search([('symbol', '=', 'oz')])[0] # Endicia only support 1 decimal place in weight weight_oz = "%.1f" % UOM.compute_qty( self.weight_uom, self.weight, uom_oz ) to_zip = self.shipment_address.zip if mailclass_type == 'Domestic': to_zip = to_zip and to_zip[:5] else: # International to_zip = to_zip and to_zip[:15] postage_rates_request = PostageRatesAPI( mailclass=mailclass_type, weightoz=weight_oz, from_postal_code=from_address.zip[:5], to_postal_code=to_zip, to_country_code=self.shipment_address.country.code, accountid=carrier.endicia_account_id, requesterid=carrier.endicia_requester_id, passphrase=carrier.endicia_passphrase, test=carrier.endicia_is_test, ) # Logging. logger.debug( 'Making Postage Rates Request for shipping rates of' 'Sale ID: {0} and Carrier ID: {1}' .format(self.id, carrier.id) ) logger.debug('--------POSTAGE RATES REQUEST--------') logger.debug(str(postage_rates_request.to_xml())) logger.debug('--------END REQUEST--------') try: response_xml = postage_rates_request.send_request() response = objectify_response(response_xml) except RequestError, e: self.raise_user_error(unicode(e))
def get_endicia_shipping_rates(self, silent=True): """ Call the rates service and get possible quotes for shipment for eligible mail classes """ Carrier = Pool().get('carrier') UOM = Pool().get('product.uom') EndiciaConfiguration = Pool().get('endicia.configuration') endicia_credentials = EndiciaConfiguration(1).get_endicia_credentials() carrier, = Carrier.search(['carrier_cost_method', '=', 'endicia']) from_address = self._get_ship_from_address() mailclass_type = "Domestic" if self.shipment_address.country.code == 'US' \ else "International" uom_oz = UOM.search([('symbol', '=', 'oz')])[0] # Endicia only support 1 decimal place in weight weight_oz = self._get_package_weight(uom_oz).quantize( Decimal('.1'), rounding=ROUND_UP ) to_zip = self.shipment_address.zip if mailclass_type == 'Domestic': to_zip = to_zip and to_zip[:5] else: # International to_zip = to_zip and to_zip[:15] postage_rates_request = PostageRatesAPI( mailclass=mailclass_type, weightoz=weight_oz, from_postal_code=from_address.zip[:5], to_postal_code=to_zip, to_country_code=self.shipment_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 Rates Request for shipping rates of' 'Sale ID: {0} and Carrier ID: {1}' .format(self.id, carrier.id) ) logger.debug('--------POSTAGE RATES REQUEST--------') logger.debug(str(postage_rates_request.to_xml())) logger.debug('--------END REQUEST--------') try: response_xml = postage_rates_request.send_request() response = objectify_response(response_xml) except RequestError, e: self.raise_user_error(unicode(e))
def get_endicia_shipping_rates(self, silent=True): """ Call the rates service and get possible quotes for shipment for eligible mail classes """ Carrier = Pool().get('carrier') UOM = Pool().get('product.uom') EndiciaConfiguration = Pool().get('endicia.configuration') endicia_credentials = EndiciaConfiguration(1).get_endicia_credentials() carrier, = Carrier.search(['carrier_cost_method', '=', 'endicia']) from_address = self._get_ship_from_address() mailclass_type = "Domestic" if self.shipment_address.country.code == 'US' \ else "International" uom_oz = UOM.search([('symbol', '=', 'oz')])[0] # Endicia only support 1 decimal place in weight weight_oz = "%.1f" % self._get_package_weight(uom_oz) to_zip = self.shipment_address.zip if mailclass_type == 'Domestic': to_zip = to_zip and to_zip[:5] else: # International to_zip = to_zip and to_zip[:15] postage_rates_request = PostageRatesAPI( mailclass=mailclass_type, weightoz=weight_oz, from_postal_code=from_address.zip[:5], to_postal_code=to_zip, to_country_code=self.shipment_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 Rates Request for shipping rates of' 'Sale ID: {0} and Carrier ID: {1}'.format( self.id, carrier.id)) logger.debug('--------POSTAGE RATES REQUEST--------') logger.debug(str(postage_rates_request.to_xml())) logger.debug('--------END REQUEST--------') try: response_xml = postage_rates_request.send_request() response = objectify_response(response_xml) except RequestError, e: self.raise_user_error(unicode(e))
def test0035_calculating_postage_rates_request(self): calculate_postage_request = PostageRatesAPI( mailclass='Domestic', 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() rv_obj = objectify_response(response) print rv_obj self.assertTrue(len(rv_obj.PostagePrice) > 1)