Merge pull request 'ValidarQueNoSePuedaCrearVentaSinLineas' (#58) from ValidarQueNoSePuedaCrearVentaSinLineas into main
Reviewed-on: OneTeam/don_confiao#58
This commit is contained in:
commit
ffa1622870
@ -226,31 +226,47 @@
|
||||
this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0 });
|
||||
},
|
||||
removeLine(index) {
|
||||
this.purchase.saleline_set.splice(index, 1);
|
||||
// Solo elimina si hay más de una línea
|
||||
if (this.purchase.saleline_set.length > 1) {
|
||||
this.purchase.saleline_set.splice(index, 1);
|
||||
} else {
|
||||
// Opcional: puedes mostrar un mensaje o alerta si lo deseas
|
||||
console.log("No se puede eliminar la única línea.");
|
||||
}
|
||||
},
|
||||
calculateSubtotal(line) {
|
||||
return line.unit_price * line.quantity;
|
||||
},
|
||||
async submit() {
|
||||
if (this.$refs.form.validate()) {
|
||||
try {
|
||||
const response = await fetch('/don_confiao/api/sales/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(this.purchase),
|
||||
});
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log('Compra enviada:', data);
|
||||
this.$router.push("SummaryPurchase");
|
||||
} else {
|
||||
console.error('Error al enviar la compra:', response.statusText);
|
||||
const hasInvalidQuantity = this.purchase.saleline_set.some(line => line.quantity <= 0);
|
||||
if (hasInvalidQuantity) {
|
||||
this.errorMessage = 'La cantidad de cada línea de compra debe ser mayor que cero.';
|
||||
|
||||
console.log(this.errorMessage);
|
||||
return; // Detener el submit si hay cantidades inválidas
|
||||
}
|
||||
|
||||
this.errorMessage = ''; // Limpiar el mensaje de error
|
||||
|
||||
try {
|
||||
const response = await fetch('/don_confiao/api/sales/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(this.purchase),
|
||||
});
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log('Compra enviada:', data);
|
||||
this.$router.push("SummaryPurchase");
|
||||
} else {
|
||||
console.error('Error al enviar la compra:', response.statusText);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error de red:', error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error de red:', error);
|
||||
}
|
||||
}
|
||||
},
|
||||
navigate(route) {
|
||||
|
Loading…
Reference in New Issue
Block a user