def test_can_create_read_update_ticket(self): # create a ticket record ticket = Ticket(**self.ticket) ticket.save() self.assertIsNotNone(ticket.id, None) # test that a ticket record has been added ticket = Ticket.objects.get(id=ticket.id) self.assertIsNotNone(ticket.id) # update a ticket record new_ticket_id = "898273499823hiuh32898w" ticket = Ticket.objects.get(id=ticket.id) ticket.ticket_id = new_ticket_id ticket.save() # update deal title for next test self.ticket['ticket_id'] = new_ticket_id self.assertEquals(ticket.ticket_id, new_ticket_id) # delete a ticket record ticket = Ticket.objects.get(id=ticket.id) Ticket.delete(ticket) with self.assertRaises(Ticket.DoesNotExist) as context: Ticket.objects.get(**self.ticket) self.assertTrue("does not exist" in context.exception.message)
def mutate(self, info, id, title, description, reported_by, assigned_to, status): ticket = Ticket(id=id, title=title, description=description, reported_by=reported_by, assigned_to=assigned_to, status=status) ticket.delete() return DeleteTicket( id=ticket.id, title=ticket.title, description=ticket.description, reported_by=ticket.reported_by, assigned_to=ticket.assigned_to, status=ticket.status, )
def sale_update(request, performance_uuid, sale_uuid): # Get performance, venue and sale performance = get_object_or_404(ShowPerformance, uuid = performance_uuid) assert performance.has_open_checkpoint assert not performance.has_close_checkpoint venue = performance.show.venue sale = get_object_or_404(Sale, uuid = sale_uuid) assert sale.venue == venue # Process sale form sale_form = create_sale_form(performance, sale, request.POST) if sale_form.is_valid(): # Check if there are sufficient tickets requested_tickets = sale_form.ticket_count available_tickets = performance.tickets_available + sale.tickets.count() if requested_tickets <= available_tickets: # Adjust ticket numbers for ticket_type in sale_form.ticket_types: quantity = sale_form.cleaned_data[SaleForm.ticket_field_name(ticket_type)] while sale.tickets.filter(description = ticket_type.name).count() > quantity: ticket = sale.tickets.filter(description = ticket_type.name).last() logger.info(f"{ticket_type.name} ticket {ticket.id} removed from sale {sale.id}") ticket.delete() while sale.tickets.filter(description = ticket_type.name).count() < quantity: ticket = Ticket( sale = sale, user = sale.customer_user, performance = performance, description = ticket_type.name, cost = ticket_type.price, payment = ticket_type.payment, ) ticket.save() logger.info(f"{ticket_type.name} ticket {ticket.id} added to sale {sale.id}") # Update eFringers for efringer in sale_form.efringers: form_is_used = sale_form.cleaned_data[SaleForm.efringer_field_name(efringer)] ticket = sale.tickets.filter(fringer = efringer).first() if form_is_used and not ticket: ticket = Ticket( sale = sale, user = sale.customer_user, performance = performance, fringer = efringer, description = 'eFringer', cost = 0, payment = efringer.payment, ) ticket.save() logger.info(f"eFringer {efringer.name} ticket {ticket.id} added to sale {sale.id}") elif ticket and not form_is_used: logger.info(f"eFringer {efringer.name} ticket {ticket.id} removed from sale {sale.id}") ticket.delete() # Update volunteer complimentary tickets if sale.customer_user and sale.customer_user.is_volunteer: ticket = sale.tickets.filter(user = sale.customer_user, description = 'Volunteer').first() use_volunteer = sale_form.cleaned_data['volunteer'] if use_volunteer and not ticket: ticket = Ticket( sale = sale, user = sale.customer_user, performance = performance, description = 'Volunteer', cost = 0, payment = 0, ) ticket.save() logger.info(f"Volunteer ticket {ticket.id} added to sale {sale.id}") elif ticket and not use_volunteer: logger.info(f"Volunteer ticket {ticket.id} removed from sale {sale.id}") ticket.delete() # Update buttons buttons = sale_form.cleaned_data['buttons'] if sale.buttons != buttons: sale.buttons = buttons sale.save() logger.info(f"Buttons updated to {buttons} for sale {sale.id}") # Update paper fringers fringers = sale_form.cleaned_data['fringers'] if sale.fringers != fringers: while (sale.fringers.count() or 0) > fringers: fringer = sale.fringers.first() logger.info(f"Fringer {fringer.id} removed from sale {sale.id}") fringer.delete() while (sale.fringers.count() or 0) < fringers: fringer = Fringer( description = f'{request.festival.fringer_shows} shows for £{request.festival.fringer_price:.0f}', shows = request.festival.fringer_shows, cost = request.festival.fringer_price, sale = sale, ) fringer.save() logger.info(f"Fringer {fringer.id} added to sale {sale.id}") # If the sale is completed update the amount if sale.completed: sale.amount = sale.total_cost sale.save() logger.warning(f"Completed sale {sale.id} updated") # Destroy sale form sale_form = None # Insufficient tickets else: logger.info(f"Sale {sale.id} insufficient tickets ({requested_tickets} requested, {available_tickets} available)") sale_form.add_error(None, f"There are only {available_tickets} tickets available for this performance.") # Render sales tab content return render_sales(request, performance, sale = sale, sale_form = sale_form)