def do_move_orders(self): info("Moving orders...", extra={"url": "task://rent/move_orders"}) for o in RentOrder.objects.filter(status=RentOrderStatus.Pending): try: if o.source_dc.is_game_available( o.item, exclude_rent_order=o, for_rent=True ): continue p = o.user.get_profile() zip = p.shipping_zip if not zip: o.put_back_to_list() continue o.source_dc = None o.save() dc = Dropship.find_closest_dc(zip, o.item, p.dropship) if dc: o.source_dc = dc o.save() info("%s --> %s %s", o.source_dc.code, dc.code, o) else: info("Put back to list %s", o) o.put_back_to_list() except Exception, _e: error("Error occurs when moving order %s", o.id, exc_info=sys.exc_info(), extra={"url": reverse("staff:rent_order_details", args=[o.id])})
def process_item(rent_list_item): """ Blah """ user = rent_list_item.user profile = user.get_profile() zip_code = profile.shipping_zip rent_list = RentList.objects.filter(user=user, rent_order=None) def chain_objects(o1, objects=[]): return itertools.chain([o1] if o1 else [], itertools.ifilter(lambda x: x != o1, objects)) debug("Home DC: %s", profile.dropship) from project.inventory.models import Dropship dropships = list(chain_objects(profile.dropship, Dropship.list_by_distance(zip_code))) def find_dropship(item): for dropship in dropships: if dropship.is_game_available(item, for_rent=True): return dropship return None rent_plan = MemberRentalPlan.get_current_plan(user) for list_item in chain_objects(rent_list_item, rent_list): dc = find_dropship(list_item.item) debug("Processing: %s %s...", list_item.user, list_item.item) if not dc: # TODO: Create report debug("Create report") continue if not rent_plan.is_valid(): return False order = RentOrder.create(user, list_item, dc) debug("Rent order was created: %s", order) return True return False
def complete(self, silent=False): def chain_objects(o1, objects=[]): return itertools.chain([o1] if o1 else [], itertools.ifilter(lambda x: x != o1, objects)) zip_code = self.shipping_zip_code profile = self.user.get_profile() logger.debug('Home DC: %s', profile.dropship) from project.inventory.models import Dropship dropships = list(chain_objects(profile.dropship, Dropship.list_by_distance(zip_code))) def find_dropship(item, is_new): for dropship in dropships: if dropship.is_game_available(item, is_new, for_rent=False): return dropship return None self.change_status(BuyOrderStatus.Checkout) for order_item in self.items.all(): if order_item.item.is_prereleased_game(): order_item.set_status(BuyOrderItemStatus.PreOrder) logger.debug('Pre-order item') continue logger.debug('Processing: %s %s...', self.user, order_item.item) dc = find_dropship(order_item.item, order_item.is_new) if not dc: order_item.set_status(BuyOrderItemStatus.Checkout) logger.debug('No inventory found') continue logger.debug('Item found in: %s', dc) order_item.source_dc = dc order_item.set_status(BuyOrderItemStatus.Pending) if not silent: self.send_order_creation_confirmation_email()
def link_to_dropship(self, dropship=None, save=True): from project.inventory.models import Dropship self.dropship = dropship or Dropship.find_closest(self.shipping_zip) if save: self.save()
def find_dropship(item, is_new, zip_code, profile): dropships = list(chain_objects(profile.dropship, Dropship.list_by_distance(zip_code))) for dropship in dropships: if dropship.is_game_available(item, is_new): return dropship return None
def orders(request, **kwargs): message = '' if 'cancel' in request.GET: order = get_object_or_404(RentOrder, id=int(request.GET['cancel']), status=RentOrderStatus.Prepared) inventory_barcode = order.inventory.barcode order.inventory = None order.status = RentOrderStatus.Pending order.date_prepared = None order.outgoing_endicia_data = None order.outgoing_mail_label = None order.outgoing_tracking_number = None order.outgoing_tracking_scans = None order.incoming_endicia_data = None order.incoming_mail_label = None order.incoming_tracking_number = None order.incoming_tracking_scans = None profile = order.user.get_profile() dc = Dropship.find_closest_dc(profile.shipping_zip, order.item, profile.dropship) if dc: order.source_dc = dc order.save() if RentOrder.objects.filter(inventory__barcode=inventory_barcode, status=RentOrderStatus.Prepared).count() == 0: inventory = Inventory.objects.get(barcode=inventory_barcode) inventory.status = InventoryStatus.InStock inventory.save() return redirect('staff:page', 'Rent/Orders') if request.method == 'POST': barcode = request.POST.get('barcode') if barcode: try: inventory = Inventory.objects.exclude(buy_only=True).get(barcode=barcode, status=InventoryStatus.InStock) dc = request.user.get_profile().dc if dc and dc.code != inventory.dropship.code: message = 'Barcode "<strong>%s</strong>" doesn\'t found in <strong>%s</strong>.' % (barcode, str(dc)) else: order = RentOrder.objects.filter(status=RentOrderStatus.Pending, source_dc__code=inventory.dropship.code, item__id=inventory.item.id).order_by('-map') if order.count(): order = order[0] order.inventory = inventory order.status = RentOrderStatus.Prepared order.date_prepared = datetime.now() order.prepared_by = request.user order.save() inventory.status = InventoryStatus.Pending inventory.tmp_new_dc_code_aproved = True inventory.save() message = 'Barcode "<strong>%s</strong>" was successfully added to the Prepared List.' % barcode else: message = 'Barcode "<strong>%s</strong>" does not match any item in Picked List.' % barcode except Inventory.DoesNotExist, e: #@UnusedVariable message = 'Barcode "<strong>%s</strong>" does not exist or not in stock.' % barcode