Skip to content

Commit

Permalink
fixing budget syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
paulorosadodev committed Jun 10, 2024
1 parent 76fd03d commit 5d13c15
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TARGET_ENV=Dev
EMAIL_HOST_USER=voltzcorporation@gmail.com
EMAIL_HOST_PASSWORD=lqfh fwmr fgww cdwz
EMAIL_HOST_USER=taverna.hub@gmail.com
EMAIL_HOST_PASSWORD=mhpn rxtr nsju fkgn
EMAIL_USE_TLS=True
EMAIL_PORT=587
EMAIL_HOST=smtp.gmail.com
18 changes: 18 additions & 0 deletions app_client/migrations/0014_alter_orderrequest_budget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-06-10 23:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app_client', '0013_alter_orderrequest_status_and_more'),
]

operations = [
migrations.AlterField(
model_name='orderrequest',
name='budget',
field=models.CharField(blank=True, max_length=9, null=True),
),
]
2 changes: 1 addition & 1 deletion app_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OrderRequest(models.Model):
userClient = models.ForeignKey(Users, on_delete=models.CASCADE)
employee = models.ForeignKey(Users, on_delete=models.SET_NULL, null=True, blank=True, related_name='assigned_orders')
status = models.CharField(max_length=30, choices=STATUS_CHOICES, default='EM_ANALISE')
budget = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
budget = models.CharField(max_length=9, null=True, blank=True)
detailedProblemDescription = models.TextField(blank=True, null=True)
necessaryParts = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
Expand Down
6 changes: 5 additions & 1 deletion app_client/templates/email/emailtemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ <h2>Olá, {{name}}</h2>
<div>Leve o seu equipamento para a assistência entre os dias:<br><strong>{{date}}</strong> e <strong>{{finaldate}}</strong></div>
{% endif %}
{% if budget %}
<div>Orçamento definido: <strong id="budget">R$ {{budget}},00</strong></div>
{% if comma %}
<div>Orçamento definido: <strong id="budget">R$ {{budget}}</strong></div>
{% else %}
<div>Orçamento definido: <strong id="budget">R$ {{budget}},00</strong></div>
{% endif %}
<a href="https://voltz-eceeltec.azurewebsites.net/cliente/visualizar/{{order_id}}/">Clique aqui para aceitar ou recusar o orçamento</a>
{% endif %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h1>Solicitação {{order_request.id}}</h1>
{% if order_request.status == "AGUARDANDO_ORCAMENTO" %}
<div class="budgetContainer">
<label for="budget">Valor do orçamento: </label>
<input type="{% if not order_request.budget %}number{% else %}text{% endif %}" name="budget" placeholder="Insira o valor do orçamento" value="{{ order_request.budget }}">
<input type="text" name="budget" placeholder="Insira o valor do orçamento"value="{% if order_request.budget %}{{order_request.budget}}{% endif %}">
{% if errors %}
<span>
<i data-lucide="octagon-alert"></i>
Expand Down
28 changes: 20 additions & 8 deletions app_company/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,25 @@ def post(self, request, pk):
order_request.status = status

if budget:
if (float(budget.replace(",", ".")) <= 50000):
order_request.budget = float(budget.replace(",", "."))
order_request.status = "AGUARDANDO_CONFIRMACAO"
else:
ctx = {
"order_request": order_request,
"errors": {
"message": f"O orçamento máximo é R$50.000!"
try:
if (float(budget.replace(".", "").replace(",", ".")) <= 50000):
order_request.budget = budget
order_request.status = "AGUARDANDO_CONFIRMACAO"
else:
ctx = {
"order_request": order_request,
"errors": {
"message": f"O orçamento máximo é R$50.000,00!"
}
}
return render(request, "app_company/order-request-detail.html", ctx)
except:
print(budget, budget.replace(",", "."))
ctx = {
"order_request": order_request,
"errors": {
"message": f"Insira um valor válido"
}
}
return render(request, "app_company/order-request-detail.html", ctx)
else:
Expand All @@ -312,6 +322,8 @@ def post(self, request, pk):

if budget:
ctx["budget"] = budget
if "," in str(budget):
ctx["comma"] = 1
html_content = render_to_string('email/emailtemplate.html', ctx)
text_content = strip_tags(html_content)
email = EmailMultiAlternatives('Sua solicitação de serviço foi atualizada', text_content, '[email protected]', [user.username])
Expand Down

0 comments on commit 5d13c15

Please sign in to comment.