Skip to content

Commit

Permalink
Merge pull request #378 from Troter2/dev
Browse files Browse the repository at this point in the history
Sprint 3
  • Loading branch information
Troter2 authored Jun 13, 2024
2 parents aa414de + 7adae3b commit 49d5a82
Show file tree
Hide file tree
Showing 42 changed files with 2,111 additions and 563 deletions.
58 changes: 29 additions & 29 deletions .github/workflows/playwright.yml
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/
9 changes: 7 additions & 2 deletions Billing/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ class Meta:

discount_code = forms.ModelChoiceField(
queryset=Coupon.objects.filter(active=True),
label="Código de Descuento"
)
label="discount_code"
)

class CouponForm(forms.ModelForm):
class Meta:
model = Coupon
fields = ['discount_code', 'discount_percentage']
96 changes: 87 additions & 9 deletions Billing/views.py
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})
7 changes: 4 additions & 3 deletions PlayWright/Reception/test_book_logged.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from playwright.sync_api import Page, expect
import time


def test_book_logged(page: Page) -> None:
Expand All @@ -11,10 +12,10 @@ def test_book_logged(page: Page) -> None:
page.get_by_label("Contraseña").fill("admin")
page.get_by_role("main").get_by_role("button", name="Log in").click()
page.get_by_role("link", name="Reservar").click()
page.get_by_placeholder("Fecha de Entrada ").fill("2024-10-24")
page.get_by_placeholder("Fecha de Salida").fill("2024-10-26")
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("2")
page.get_by_text("Precio Habitación: 0 Importe").click()
page.get_by_role("button", name="Reservar").click()
#expect(page.get_by_role("button", name="Descargar Comprobante")).to_be_visible()
22 changes: 6 additions & 16 deletions PlayWright/Reception/test_book_no_logged.py
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()
3 changes: 1 addition & 2 deletions PlayWright/Reception/test_check_menu_in_receptionist_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ def test_check_menu_in_receptionist_role(page: Page) -> None:
page.goto("http://localhost:8000/")
page.get_by_role("button", name="Log in").click()
page.get_by_label("Usuario").click()
page.get_by_label("Usuario").fill("receptionuser")
page.get_by_label("Usuario").fill("reception")
page.get_by_label("Contraseña").click()
page.get_by_label("Contraseña").fill("admin")
page.get_by_label("Contraseña").press("Enter")
expect(page.get_by_role("button", name="Recepcion")).to_be_visible()
10 changes: 9 additions & 1 deletion PlayWright/Reception/test_go_booking_from_rooms.py
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()
14 changes: 14 additions & 0 deletions Reception/management/commands/delete_after_2_year.py
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.'))
35 changes: 35 additions & 0 deletions Reception/management/commands/send_mail.py
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!")
2 changes: 1 addition & 1 deletion Reception/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RoomReservation(models.Model):
guest_is_here = models.BooleanField(default=False)
guest_leaved = models.BooleanField(default=False)
guests_number = models.IntegerField(default=0)
price = models.DecimalField( max_digits=100, decimal_places=2)
price = models.DecimalField(max_digits=100, decimal_places=2)
room_number = models.ForeignKey(Room, on_delete=models.CASCADE)
room_is_payed = models.BooleanField(default=False)

Expand Down
Loading

0 comments on commit 49d5a82

Please sign in to comment.