def create_inbound_parcels(cls, count): combine_id_count = count // 4 tracking_prefix = "CP{0}".format(datetime.now().strftime("%Y%m%d%H%M")) combine_id_pool = [str(ObjectId()) for i in range(combine_id_count)] for i in range(count): combine_id = combine_id_pool[random.randint( 0, combine_id_count - 1)] tracking_id = tracking_prefix + "{:03d}".format(i) InboundParcelUtil.create_parcel( tracking_id=tracking_id, combine_id=combine_id, warehouse_id="SHYW", inbound_carrier=0, latest_ship_datetime=datetime.now() + timedelta(days=random.randint(3, 5)) )
def on_get(self, req, resp, tracking_id): try: detail = InboundParcelUtil.get_inbound_parcel_detail(tracking_id) except ValueError: raise falcon.HTTPNotFound(description="包裹不存在!") resp.media = {"parcel_detail": detail}
def inbound_all_parcels(cls, user): inbound_parcels = CPInboundParcel.find( { "status": CPInboundParcel.Status.Pending } ) for parcel in inbound_parcels: InboundParcelUtil.inbound_parcel( tracking_id=parcel.tracking_id, parcel_type=CPInboundParcel.ParcelType.Ordinary, weight=random.uniform(0.1, 1.2), has_battery=False, has_liquid=False, has_sensitive=False, sensitive_reason=None, user=user )
def on_directship(self, req, resp, tracking_id): user = req.context['session'].user job_id = req.media["job_id"] weight = req.media["weight"] try: logistics_order = InboundParcelUtil.directship_parcel( job_id, tracking_id, weight, user) resp.media = {"logistics_order": logistics_order.to_dict()} except InvalidOperationException as ex: raise falcon.HTTPBadRequest(description=str(ex))
def on_inbound(self, req, resp, tracking_id): user = req.context['session'].user parcel_type = req.media["parcel_type"] weight = req.media["weight"] has_battery = req.media.get("has_battery", False) has_liquid = req.media.get("has_liquid", False) sensitive_reason = req.media.get("sensitive_reason") try: InboundParcelUtil.inbound_parcel( tracking_id=tracking_id, parcel_type=parcel_type, weight=weight, has_battery=has_battery, has_liquid=has_liquid, has_sensitive=bool(sensitive_reason), sensitive_reason=sensitive_reason, user=user) except ValueError: raise falcon.HTTPNotFound(description="物流订单不存在!") except InvalidOperationException: raise falcon.HTTPBadRequest(description="非法操作!")
def on_combine(self, req, resp): user = req.context['session'].user job_id = req.media["job_id"] weight = req.media["weight"] tracking_ids = req.media["tracking_ids"] try: logistics_order = InboundParcelUtil.combine_parcels( job_id, tracking_ids, weight, user) # Fake, For testing from wms.model.mongo.logistics.logistics_order import LogisticsOrder logistics_order = LogisticsOrder.by_id("5cc08900e48ab70040272e98") resp.media = {"logistics_order": logistics_order.to_dict()} except ValidationFailedException as ex: raise falcon.HTTPBadRequest(description=str(ex)) except InvalidOperationException as ex: raise falcon.HTTPBadRequest(description=str(ex))