From 4aa050d249a41d8b95af6160b5b268d1727a59f6 Mon Sep 17 00:00:00 2001 From: Joan Carles Turegano Date: Wed, 12 Jun 2024 21:01:56 +0200 Subject: [PATCH 1/2] list_coupons_done --- Billing/forms.py | 9 +- Billing/views.py | 65 +++++-- hotelManagementProject/urls.py | 6 +- templates/base.html | 7 + templates/billing/list_coupons.html | 134 +++++++++++++ templates/billing/list_offers.html | 288 +++++++++++++++++----------- 6 files changed, 382 insertions(+), 127 deletions(-) create mode 100644 templates/billing/list_coupons.html diff --git a/Billing/forms.py b/Billing/forms.py index c35f9e3..b47fc73 100644 --- a/Billing/forms.py +++ b/Billing/forms.py @@ -10,5 +10,10 @@ class Meta: discount_code = forms.ModelChoiceField( queryset=Coupon.objects.filter(active=True), - label="Código de Descuento" - ) \ No newline at end of file + label="discount_code" + ) + +class CouponForm(forms.ModelForm): + class Meta: + model = Coupon + fields = ['discount_code', 'discount_percentage'] \ No newline at end of file diff --git a/Billing/views.py b/Billing/views.py index fa26fcd..14eb05f 100644 --- a/Billing/views.py +++ b/Billing/views.py @@ -1,28 +1,67 @@ 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 # 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 create_offer(request): + +def list_coupons(request): if request.user.has_perm('accountant'): - if request.method == 'POST': - form = PromotionForm(request.POST, request.FILES) - if form.is_valid(): - form.save() - return redirect('list_offers') + 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: - form = PromotionForm() - return render(request, 'billing/create_offer.html', {'form': form}) + 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.user.has_perm('accountant') and request.method == 'POST': + form = PromotionForm(request.POST, request.FILES) + if form.is_valid(): + form.save() + return redirect('list_offers') + return redirect('home') + + def edit_offer(request): if request.user.has_perm('accountant'): offer = Promotion.objects.get(pk=request.POST['id']) @@ -34,6 +73,7 @@ def edit_offer(request): 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) @@ -43,4 +83,3 @@ def delete_offer(request, offer_id): promotion.delete() return redirect('list_offers') return redirect('home') - diff --git a/hotelManagementProject/urls.py b/hotelManagementProject/urls.py index 00022e6..5d7ffcd 100644 --- a/hotelManagementProject/urls.py +++ b/hotelManagementProject/urls.py @@ -17,7 +17,7 @@ from django.contrib import admin from django.contrib.auth import login from django.urls import path, include -from Billing.views import list_offers, create_offer, edit_offer, delete_offer +from Billing.views import list_offers, create_offer, edit_offer, delete_offer, list_coupons, create_coupon,edit_status_coupon, edit_coupon from Cleaning.views import cleaner_page, update_room_status from User.views import add_guest_view, save_more_guest, save_guest, user_profile, user_edit_profile, \ list_reservations_user, booking_filter_user, delete_booking_user, list_users, delete_user, edit_user, \ @@ -107,6 +107,10 @@ path('rrhh/users/create', register_admin, name='register_admin'), path('rrhh/users/search', search_user_rrhh, name='search_user_rrhh'), path('offer/delete//', delete_offer, name='delete_offer'), + path('coupon/', list_coupons, name='list_coupons'), + path('coupon/create_coupon', create_coupon, name='create_coupon'), + path('coupon/edit_status_coupon/', edit_status_coupon, name='edit_status_coupon'), + path('coupon/edit_coupon/',edit_coupon, name='edit_coupon' ) ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/templates/base.html b/templates/base.html index 7a4b917..f370c22 100644 --- a/templates/base.html +++ b/templates/base.html @@ -166,6 +166,13 @@ + {% endif %} diff --git a/templates/billing/list_coupons.html b/templates/billing/list_coupons.html new file mode 100644 index 0000000..54a1091 --- /dev/null +++ b/templates/billing/list_coupons.html @@ -0,0 +1,134 @@ +{% extends "base.html" %} +{% load static %} +{% block title %} Promociones del Hotel {% endblock %} +{% block content %} +

Lista de Cupones del Hotel

+
+
+
+ +
+
+
+ +
+
+ + + + + + + + + + + {% for cupon in cupones %} + + + + {% if cupon.active == True %} + + {% else %} + + {% endif %} + + + + + + + {% endfor %} + + + + + +
Codigo de descuentoPorcentage de descuentoEstado
{{ cupon.discount_code }}{{ cupon.discount_percentage }} +
+ {% csrf_token %} + + +
+
+
+ {% csrf_token %} + + +
+
+ +
+
+
+{% endblock %} diff --git a/templates/billing/list_offers.html b/templates/billing/list_offers.html index 72960e6..48b2e49 100644 --- a/templates/billing/list_offers.html +++ b/templates/billing/list_offers.html @@ -6,134 +6,200 @@

Lista de Promociones del Hotel

- Crear Oferta +
- -
-
- - - - - - - - - - - {% for oferta in ofertas %} - - - - - -
TítuloDescripciónCódigo de Descuento
{{ oferta.title }}{{ oferta.description }}{{ oferta.discount_code.discount_code }} - - - +
+ +
- {% endfor %} -
+
- + {% endblock %} From 627fa6cef0aee6bee7965f3d88214db321d65769 Mon Sep 17 00:00:00 2001 From: Juanca192001 Date: Wed, 12 Jun 2024 21:41:13 +0200 Subject: [PATCH 2/2] Coupons_and_offers_done --- templates/billing/list_coupons.html | 4 ++-- templates/billing/list_offers.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/billing/list_coupons.html b/templates/billing/list_coupons.html index 54a1091..05b9408 100644 --- a/templates/billing/list_coupons.html +++ b/templates/billing/list_coupons.html @@ -34,7 +34,7 @@

Lista de Cupones del Hotel

{% csrf_token %} - +
{% else %} @@ -42,7 +42,7 @@

Lista de Cupones del Hotel

{% csrf_token %} - +
{% endif %} diff --git a/templates/billing/list_offers.html b/templates/billing/list_offers.html index 48b2e49..bcaa535 100644 --- a/templates/billing/list_offers.html +++ b/templates/billing/list_offers.html @@ -187,7 +187,7 @@