def get_worldship_xml(self): """ Return shipment data with worldship understandable xml """ if not self.carrier: self.raise_user_error("Carrier is not defined for shipment.") if self.carrier.carrier_cost_method != "ups_worldship": self.raise_user_error( "Shipment %s is to be shipped with %s, not Worldship.", (self.reference, self.carrier.rec_name) ) description = ",".join([move.product.name for move in self.outgoing_moves]) ship_to = self.delivery_address.to_worldship_to_address() ship_from = self._get_ship_from_address().to_worldship_from_address() shipment_information = WorldShip.shipment_information_type( ServiceType="Standard", # Worldease DescriptionOfGoods=description[:50], GoodsNotInFreeCirculation="0", BillTransportationTo="Shipper", ) xml_packages = [] for package in self.packages: xml_packages.append( WorldShip.package_type( PackageID=str(package.id), PackageType="CP", Weight="%.2f" % package.weight # Custom Package ) ) final_xml = WorldShip.get_xml( ship_to, ship_from, shipment_information, *(xml_packages + self.get_worldship_goods()) ) rv = {"id": self.id, "worldship_xml": final_xml} return rv
def to_worldship_to_address(self): """ Return xml object of to address """ values = self.to_worldship_address() values["CompanyOrName"] = self.name or self.party.name return WorldShip.ship_to_type(**values)
def test_creating_xml(self): "Test worldship" package = WorldShip.package_type( PackageType='CP', Weight='15', Length='10', Width='15', Height='8' ) ship_to = WorldShip.ship_to_type( CompanyOrName="Openlabs", Attention="Tarun Bhardwaj", Address1="48 Bismark St.", CountryTerritory="US", PostalCode="07712", CityOrTown="Asbury Park", StateProvinceCounty="NJ", Telephone="1234567891", ReceiverUpsAccountNumber="123456", ) ship_from = WorldShip.ship_from_type( CompanyOrName="Amazon LLC", Attention="Amazon India", Address1="123 Main Street", CountryTerritory="US", PostalCode="59484", CityOrTown="Sweet Grass", StateProvinceCounty="MT", Telephone="9876543211", UpsAccountNumber="654321", ) shipment_information = WorldShip.shipment_information_type( ServiceType="1DA", DescriptionOfGoods="Super Cool Stuff", GoodsNotInFreeCirculation="0", BillTransportationTo="Shipper", ) final_xml = WorldShip.get_xml( ship_to, ship_from, shipment_information, package ) print final_xml xml = objectify.fromstring(final_xml) self.assertTrue(xml.tag.endswith('OpenShipments'))
def get_worldship_xml(self): """ Return shipment data with worldship understandable xml """ if not self.carrier: self.raise_user_error('Carrier is not defined for shipment.') if self.carrier.carrier_cost_method != 'ups_worldship': self.raise_user_error( 'Shipment %s is to be shipped with %s, not Worldship.', (self.reference, self.carrier.rec_name)) description = ','.join( [move.product.name for move in self.outgoing_moves]) ship_to = self.delivery_address.to_worldship_to_address() ship_from = self._get_ship_from_address().to_worldship_from_address() shipment_information = WorldShip.shipment_information_type( ServiceType="Standard", # Worldease DescriptionOfGoods=description[:50], GoodsNotInFreeCirculation="0", BillTransportationTo="Shipper", ) xml_packages = [] for package in self.packages: xml_packages.append( WorldShip.package_type( PackageID=str(package.id), PackageType='CP', # Custom Package Weight="%.2f" % package.weight, )) final_xml = WorldShip.get_xml(ship_to, ship_from, shipment_information, *xml_packages) rv = { 'id': self.id, 'worldship_xml': final_xml, } return rv
def to_worldship_from_address(self): """ Return xml object from address """ values = self.to_worldship_address() return WorldShip.ship_from_type(**values)