-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from Troter2/dev
Sprint 3
- Loading branch information
Showing
42 changed files
with
2,111 additions
and
563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [ main, master, dev ] | ||
pull_request: | ||
branches: [ main, master, dev ] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Ensure browsers are installed | ||
run: python manage.py runserver & python -m playwright install --with-deps | ||
- name: Run your tests | ||
run: pytest --tracing=retain-on-failure | ||
- uses: actions/upload-artifact@v4 | ||
if: ${{ !cancelled() }} | ||
with: | ||
name: playwright-traces | ||
path: test-results/ | ||
#name: Playwright Tests | ||
#on: | ||
# push: | ||
# branches: [ main, master, dev ] | ||
# pull_request: | ||
# branches: [ main, master, dev ] | ||
#jobs: | ||
# test: | ||
# timeout-minutes: 60 | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - uses: actions/checkout@v4 | ||
# - name: Set up Python | ||
# uses: actions/setup-python@v4 | ||
# with: | ||
# python-version: '3.11' | ||
# - name: Install dependencies | ||
# run: | | ||
# python -m pip install --upgrade pip | ||
# pip install -r requirements.txt | ||
# - name: Ensure browsers are installed | ||
# run: python manage.py runserver & python -m playwright install --with-deps | ||
# - name: Run your tests | ||
# run: pytest --tracing=retain-on-failure | ||
# - uses: actions/upload-artifact@v4 | ||
# if: ${{ !cancelled() }} | ||
# with: | ||
# name: playwright-traces | ||
# path: test-results/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,100 @@ | ||
from django.shortcuts import render, redirect | ||
from django.shortcuts import render, redirect, get_object_or_404 | ||
|
||
from Billing.forms import PromotionForm | ||
from Billing.models import Promotion | ||
from Billing.forms import PromotionForm, CouponForm | ||
from Billing.models import Promotion, Coupon | ||
from Reception.models import RoomReservation | ||
from Restaurant.models import RestaurantReservation | ||
|
||
|
||
# Create your views here. | ||
def list_offers(request): | ||
if request.user.has_perm('accountant'): | ||
promotions = Promotion.objects.all() | ||
return render(request, 'billing/list_offers.html', {'ofertas': promotions}) | ||
coupons = Coupon.objects.all() | ||
return render(request, 'billing/list_offers.html', {'ofertas': promotions, 'cupones': coupons}) | ||
return redirect('home') | ||
|
||
|
||
def list_coupons(request): | ||
if request.user.has_perm('accountant'): | ||
coupons = Coupon.objects.all() | ||
return render(request, 'billing/list_coupons.html', {'cupones': coupons}) | ||
return redirect('home') | ||
|
||
|
||
def edit_status_coupon(request): | ||
if request.user.has_perm('accountant') and request.method == 'POST': | ||
coupon_id = request.POST['id_coupon'] | ||
coupon = get_object_or_404(Coupon, pk=coupon_id) | ||
if coupon.active == True: | ||
coupon.active = False | ||
else: | ||
coupon.active = True | ||
coupon.save() | ||
return redirect('list_coupons') | ||
return redirect('home') | ||
|
||
|
||
def create_coupon(request): | ||
if request.user.has_perm('accountant') and request.method == 'POST': | ||
form = CouponForm(request.POST) | ||
if form.is_valid(): | ||
form.save() | ||
return redirect('list_coupons') | ||
return redirect('home') | ||
|
||
|
||
def edit_coupon(request): | ||
if request.user.has_perm('accountant') and request.method == 'POST': | ||
coupon_id = request.POST['id'] | ||
coupon = get_object_or_404(Coupon, pk=coupon_id) | ||
coupon.discount_percentage = request.POST['discount_percentage'] | ||
coupon.discount_code = request.POST['discount_code'] | ||
coupon.save() | ||
return redirect('list_coupons') | ||
return redirect('home') | ||
|
||
|
||
def create_offer(request): | ||
if request.method == 'POST': | ||
if request.user.has_perm('accountant') and request.method == 'POST': | ||
form = PromotionForm(request.POST, request.FILES) | ||
if form.is_valid(): | ||
form.save() | ||
return redirect('list_offers') | ||
else: | ||
form = PromotionForm() | ||
return render(request, 'billing/create_offer.html', {'form': form}) | ||
return redirect('list_offers') | ||
return redirect('home') | ||
|
||
|
||
def list_restaurant_and_room(request): | ||
if request.user.has_perm('accountant'): | ||
reservations = RoomReservation.objects.filter(guest_leaved=True) | ||
return render(request, 'billing/list_reservations.html', {'reservas': reservations}) | ||
|
||
|
||
def edit_offer(request): | ||
if request.user.has_perm('accountant'): | ||
offer = Promotion.objects.get(pk=request.POST['id']) | ||
if 'image' in request.FILES: | ||
offer.image = request.FILES['image'] | ||
offer.title = request.POST['title'] | ||
offer.description = request.POST['description'] | ||
offer.save() | ||
return redirect('list_offers') | ||
return redirect('home') | ||
|
||
|
||
def delete_offer(request, offer_id): | ||
if request.method == 'POST' and request.user.has_perm('accountant'): | ||
promotion = get_object_or_404(Promotion, id=offer_id) | ||
coupon = promotion.discount_code | ||
coupon.active = False | ||
coupon.save() | ||
promotion.delete() | ||
return redirect('list_offers') | ||
return redirect('home') | ||
|
||
|
||
def details_reservation(request, reservation_id): | ||
room_reservation = get_object_or_404(RoomReservation, pk=reservation_id) | ||
restaurant_reservations = RestaurantReservation.objects.filter(room_reservation=room_reservation) | ||
return render(request, 'billing/details_reservation.html', | ||
{'room_reservation': room_reservation, 'restaurant_reservations': restaurant_reservations}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,14 @@ | ||
import re | ||
from playwright.sync_api import Page, expect | ||
|
||
import time | ||
|
||
def test_book_no_logged(page: Page) -> None: | ||
page.goto("http://localhost:8000/") | ||
page.get_by_role("link", name="Reservar").click() | ||
page.get_by_placeholder("DNI").click() | ||
page.get_by_placeholder("DNI").fill("12312312a") | ||
page.get_by_placeholder("DNI").press("Tab") | ||
page.get_by_placeholder("Nombre").fill("test") | ||
page.get_by_placeholder("Nombre").press("Tab") | ||
page.get_by_placeholder("Apellidos").fill("test") | ||
page.get_by_placeholder("Apellidos").press("Tab") | ||
page.get_by_placeholder("Correo Electrónico").fill("[email protected]") | ||
page.get_by_placeholder("Correo Electrónico").press("Tab") | ||
page.get_by_placeholder("Teléfono").fill("123123123") | ||
page.get_by_placeholder("Fecha de Entrada ").fill("2024-10-22") | ||
page.get_by_placeholder("Fecha de Salida").fill("2024-10-24") | ||
time.sleep(1) | ||
page.get_by_placeholder("Fecha de Entrada ").fill("2024-12-12") | ||
page.get_by_placeholder("Fecha de Salida").fill("2024-12-25") | ||
page.get_by_placeholder("Número de Huéspedes").click() | ||
page.get_by_placeholder("Número de Huéspedes").fill("3") | ||
page.get_by_text("Volver Reservar DNI Nombre").click() | ||
page.get_by_placeholder("Número de Huéspedes").fill("2") | ||
page.get_by_role("button", name="Reservar").click() | ||
#expect(page.get_by_role("button", name="Descargar Comprobante")).to_be_visible() | ||
# expect(page.get_by_role("button", name="Descargar Comprobante")).to_be_visible() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import re | ||
from playwright.sync_api import Page, expect | ||
import time | ||
|
||
|
||
|
||
def test_go_booking_from_rooms(page: Page) -> None: | ||
page.goto("http://localhost:8000/") | ||
page.get_by_role("link", name="Habitaciones", exact=True).click() | ||
page.get_by_role("link", name="Reservar").nth(1).click() | ||
page.get_by_placeholder("DNI").click() | ||
time.sleep(1) | ||
page.get_by_placeholder("Fecha de Entrada ").fill("2024-12-12") | ||
page.get_by_placeholder("Fecha de Entrada ").press("Enter") | ||
page.get_by_placeholder("Fecha de Salida").fill("2024-12-25") | ||
page.get_by_placeholder("Número de Huéspedes").click() | ||
page.get_by_placeholder("Número de Huéspedes").fill("2") | ||
page.get_by_role("button", name="Reservar").click() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.utils import timezone | ||
|
||
from Reception.models import RoomReservation | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Deletes room reservations older than 2 years' | ||
|
||
def handle(self, *args, **kwargs): | ||
two_years_ago = timezone.now() - timezone.timedelta(days=365 * 2) | ||
old_reservations = RoomReservation.objects.filter(guest_checkout__lt=two_years_ago) | ||
old_reservations.delete() | ||
self.stdout.write(self.style.SUCCESS('Deleted room reservations where checkout date is older than 2 years.')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
from django.core.management import BaseCommand | ||
from django.utils import timezone | ||
|
||
from Reception.models import RoomReservation | ||
import smtplib | ||
from email.mime.text import MIMEText | ||
|
||
class Command(BaseCommand): | ||
help = "Set rooms to not clean if occupied." | ||
|
||
def handle(self, *args, **options): | ||
cur_date = timezone.now() | ||
reservations = RoomReservation.objects.filter(guest_checkin__lte=cur_date, guest_checkout__gt=cur_date) | ||
rooms = [reservation.room_number for reservation in reservations] | ||
for room in rooms: | ||
room.is_clean = False | ||
room.save() | ||
self.stdout.write(self.style.SUCCESS('Successfully set rooms to not clean')) | ||
|
||
|
||
def handle(self, *args, **options): | ||
subject = "Email Subject" | ||
body = "This is the body of the text message" | ||
sender = "[email protected]" | ||
recipients = ["[email protected]"] | ||
password = ".abcd1234" | ||
msg = MIMEText(body) | ||
msg['Subject'] = subject | ||
msg['From'] = sender | ||
msg['To'] = ', '.join(recipients) | ||
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp_server: | ||
smtp_server.login(sender, password) | ||
smtp_server.sendmail(sender, recipients, msg.as_string()) | ||
print("Message sent!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.