alter: alteracao metodo POST osbOrder

This commit is contained in:
2025-03-28 13:20:20 -03:00
parent 8d31a83b13
commit bb51147d99
11 changed files with 73 additions and 40 deletions

View File

@@ -93,21 +93,21 @@ def addProduct(request, product_id, comanda_id):
return render(request, "htmx_components/comandas/htmx_list_products_in_comanda.html",{'config':config, 'valores':valores,'parcials':parcial,'consumo': consumo,'comanda':comanda}) return render(request, "htmx_components/comandas/htmx_list_products_in_comanda.html",{'config':config, 'valores':valores,'parcials':parcial,'consumo': consumo,'comanda':comanda})
@group_required(groupName='Garçom') # @group_required(groupName='Garçom')
def editOrders(request, productComanda_id, obs): # def editOrders(request, productComanda_id, obs):
order = Order.objects.get(productComanda=productComanda_id) # order = Order.objects.get(productComanda=productComanda_id)
order.obs = obs # order.obs = obs
order.save() # order.save()
msg = JsonResponse({ # msg = JsonResponse({
'type': 'broadcast', # 'type': 'broadcast',
'message': obs, # 'message': obs,
'local':'cozinha', # 'local':'cozinha',
'tipo':'edit', # 'tipo':'edit',
'id':order.id, # 'id':order.id,
'speak': f'Pedido alterado! {order.id_product.name}, é {obs}.' # 'speak': f'Pedido alterado! {order.id_product.name}, é {obs}.'
}) # })
asyncio.run(enviar_mensagem(msg)) # # asyncio.run(enviar_mensagem(msg))
return JsonResponse({'status': 'ok'}) # return JsonResponse({'status': 'ok'})
@group_required(groupName='Garçom') @group_required(groupName='Garçom')

View File

@@ -87,7 +87,7 @@ Detalhes {{comanda.name}}
{{item.product.name}} {{item.product.name}}
{% if item.product.cuisine == True %} {% if item.product.cuisine == True %}
<input hidden id="{{item.id}}-obsOrder" type="order" value="{{item.id | obsOrder}}"> <input hidden id="{{item.id}}-obsOrder" type="order" value="{{item.id | obsOrder}}">
<span data-tooltip="{{item.id | obsOrder}}" data-flow="top"> <span id="tooltip-id-{{item.id}}" data-tooltip="{{item.id | obsOrder}}" data-flow="top">
<img <img
onclick="openModalObs({{item.id}})" onclick="openModalObs({{item.id}})"
@@ -106,9 +106,6 @@ Detalhes {{comanda.name}}
</td> </td>
<td>R$ {{item.product.price}}</td> <td>R$ {{item.product.price}}</td>
{% if comanda.status != 'OPEN'%} {% if comanda.status != 'OPEN'%}
{% else %} {% else %}
<td> <td>

View File

@@ -11,6 +11,7 @@ urlpatterns = [
path('editComanda/', views.editComanda, name='editComanda'), path('editComanda/', views.editComanda, name='editComanda'),
path('addContaCliente/', views.addContaCliente, name='addContaCliente'), path('addContaCliente/', views.addContaCliente, name='addContaCliente'),
path('notificacao/', views.notificacao, name='notificacao'), path('notificacao/', views.notificacao, name='notificacao'),
path('editOrders/<int:productComanda_id>/<str:obs>', views.editOrders, name='editOrders'),
@@ -22,7 +23,6 @@ htmx_urlpatterns = [
path('listProduct/<int:comanda_id>/', htmx_views.listProduct, name='listProduct'), path('listProduct/<int:comanda_id>/', htmx_views.listProduct, name='listProduct'),
path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'), path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'),
path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductComanda, name='removeProductComanda'), path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductComanda, name='removeProductComanda'),
path('editOrders/<int:productComanda_id>/<str:obs>', htmx_views.editOrders, name='editOrders'),
path('closeComanda<int:comanda_id>/', htmx_views.closeComanda, name='closeComanda'), path('closeComanda<int:comanda_id>/', htmx_views.closeComanda, name='closeComanda'),
path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'), path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'),
path('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'), path('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'),

View File

@@ -138,3 +138,21 @@ def notificacao(request):
'notificacao': 'false', 'notificacao': 'false',
'pronto':len(ordersPronto), 'pronto':len(ordersPronto),
}) })
@group_required(groupName='Garçom')
def editOrders(request, productComanda_id, obs):
order = Order.objects.get(productComanda=productComanda_id)
order.obs = obs
order.save()
msg = JsonResponse({
'type': 'broadcast',
'message': obs,
'local':'cozinha',
'tipo':'edit',
'id':order.id,
'speak': f'Pedido alterado! {order.id_product.name}, é {obs}.'
})
# asyncio.run(enviar_mensagem(msg))
return JsonResponse({'status': 'ok', 'obs':order.obs})

Binary file not shown.

View File

@@ -213,22 +213,43 @@ function troco(){
function addOrder(){ function addOrder(){
obs = document.getElementById('obs').value obs = document.getElementById('obs')
var id = document.getElementById('id-temp').value id = document.getElementById('id-temp').value
fetch(`/comandas/editOrders/${id}/${obs}`, { tooltipObs = document.getElementById('tooltip-id-'+id)
method: 'GET',
fetch(`/comandas/editOrders/${id}/${obs.value}`, {
method: 'POST',
headers: { headers: {
'Content-Type': 'application/json'} 'Content-Type': 'application/json',
'X-CSRFToken': document.querySelector('[name="csrfmiddlewaretoken"]').value}
}) })
.then(function(response) { .then(response => response.json())
if(response.status == 200){ .then(data => {
closeModalObs() if(data.status == 'ok'){
showToast('✅Pedido atualizado com sucesso!😁','success') showToast('✅Pedido atualizado com sucesso!😁','success')
}else{ tooltipObs.dataset.tooltip = data.obs
showToast('❌Ocorreu um erro!😢','error') obs.value = ''
} document.getElementById('modal-obs').style.display = 'none';
}
}) })
.catch(error => {
showToast('❌Ocorreu um erro!😢','error')
});
// .then(function(response) {
// if(response.status == 200){
// closeModalObs()
// showToast('✅Pedido atualizado com sucesso!😁','success')
// tooltipObs.dataset.tooltip = response.data
// }else{
// showToast('❌Ocorreu um erro!😢','error')
// }
// })
} }
function showToastAdd(message, type ,duration = 3000) { function showToastAdd(message, type ,duration = 3000) {
const toast = document.getElementById('toast-add'); const toast = document.getElementById('toast-add');
@@ -281,9 +302,4 @@ function taxa(){
} }
} }
// document.getElementById('taxa').addEventListener("change", taxa);
// document.getElementById('productForm').addEventListener('submit', function(event) {
// event.preventDefault();
// });

View File

@@ -53,11 +53,13 @@ if (parentNodeClass == 'espaco' || targetId == 'drop'){
const url = `/mesas/locationMesa/${mesaId}/${targetId}/`; const url = `/mesas/locationMesa/${mesaId}/${targetId}/`;
var resposta = fetch(url, {method: 'POST', var resposta = fetch(url, {method: 'POST',
headers: {'Content-Type': 'application/json', headers: {
'Content-Type': 'application/json',
'X-CSRFToken': document.querySelector('[name="csrfmiddlewaretoken"]').value 'X-CSRFToken': document.querySelector('[name="csrfmiddlewaretoken"]').value
},}).then(response => response.json()) },})
.then(data => { .then(response => response.json())
if(data.status != 'ok'){ .then(data => {
if(data.status != 'ok'){
alert('Erro ao salvar local:', error) alert('Erro ao salvar local:', error)
} }
}) })