feat: allow setting product prices and commission for all zones upon creation via modal
This commit is contained in:
@@ -281,16 +281,21 @@ def manage_products():
|
||||
|
||||
now = datetime.now()
|
||||
for zona in Zona.query.all():
|
||||
p_val = request.form.get(f'price_{zona.id}', '0')
|
||||
c_val = request.form.get(f'comm_{zona.id}', '0')
|
||||
price = int(str(p_val).replace('.', '').replace('$', '')) if p_val else 0
|
||||
commission = int(str(c_val).replace('.', '').replace('$', '')) if c_val else 0
|
||||
|
||||
db.session.add(PrecioHistorico(
|
||||
producto_id=new_producto.id,
|
||||
zona_id=zona.id,
|
||||
price=0,
|
||||
commission=0,
|
||||
price=price,
|
||||
commission=commission,
|
||||
fecha_activacion=now,
|
||||
))
|
||||
|
||||
db.session.commit()
|
||||
flash("Producto maestro creado. No olvides configurar sus precios.", "success")
|
||||
flash("Producto maestro y sus precios creados exitosamente.", "success")
|
||||
except IntegrityError:
|
||||
db.session.rollback()
|
||||
flash("Ese producto ya existe en el catálogo.", "danger")
|
||||
|
||||
@@ -1,31 +1,21 @@
|
||||
{% extends "macros/base.html" %}
|
||||
{% from 'macros/modals.html' import confirm_modal, edit_product_modal %}
|
||||
{% from 'macros/modals.html' import confirm_modal, edit_product_modal, add_product_modal %}
|
||||
{% from "macros/ui.html" import flashed_messages %}
|
||||
|
||||
{% block title %}Catálogo de Productos{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2 class="mb-4">Catálogo de Productos por Zona</h2>
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h2 class="mb-0">Catálogo de Productos por Zona</h2>
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addProductModal">
|
||||
<i class="bi bi-plus-lg"></i> Agregar Producto
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{{ flashed_messages() }}
|
||||
|
||||
{{ edit_product_modal(zonas) }}
|
||||
|
||||
<div class="card mb-4 shadow-sm">
|
||||
<div class="card-header bg-primary text-white">Agregar Producto Maestro</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ url_for('admin.manage_products') }}">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-10">
|
||||
<input type="text" class="form-control" name="name" placeholder="Nombre del Producto" required>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="submit" class="btn btn-primary w-100">Crear Producto</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{ add_product_modal(zonas) }}
|
||||
|
||||
<div class="input-group mb-3 shadow-sm">
|
||||
<span class="input-group-text bg-body-tertiary"><i class="bi bi-search"></i></span>
|
||||
|
||||
@@ -82,6 +82,57 @@
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro add_product_modal(zonas) %}
|
||||
<div class="modal fade" id="addProductModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Agregar Nuevo Producto</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form method="POST" action="{{ url_for('admin.manage_products') }}">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-bold">Nombre del Producto</label>
|
||||
<input type="text" class="form-control" name="name" placeholder="Nombre del Producto" required>
|
||||
</div>
|
||||
<hr>
|
||||
<h6 class="fw-bold mb-3">Precios y Comisiones por Zona</h6>
|
||||
<div class="row fw-bold mb-2">
|
||||
<div class="col-4">Zona</div>
|
||||
<div class="col-4">Precio</div>
|
||||
<div class="col-4">Comisión</div>
|
||||
</div>
|
||||
{% for z in zonas %}
|
||||
<div class="row mb-2">
|
||||
<div class="col-4 d-flex align-items-center">
|
||||
<span class="badge bg-info text-dark w-100">{{ z[1] }}</span>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="input-group input-group-sm">
|
||||
<span class="input-group-text">$</span>
|
||||
<input type="text" class="form-control money-input" name="price_{{ z[0] }}" placeholder="0" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="input-group input-group-sm">
|
||||
<span class="input-group-text">$</span>
|
||||
<input type="text" class="form-control money-input" name="comm_{{ z[0] }}" placeholder="0" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="submit" class="btn btn-primary">Crear Producto</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro edit_worker_modal(modulos, bancos) %}
|
||||
<div class="modal fade" id="editWorkerModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
|
||||
Reference in New Issue
Block a user