+
!!value || 'Requerido.',
@@ -130,8 +132,8 @@
},
computed: {
calculateTotal() {
- return this.purchase.lines.reduce((total, line) => {
- return total + this.calculateSubtotal(line);
+ return this.purchase.saleline_set.reduce((total, saleline) => {
+ return total + this.calculateSubtotal(saleline);
}, 0);
},
},
@@ -140,7 +142,7 @@
fetch('/don_confiao/api/customers/')
.then(response => response.json())
.then(data => {
- this.clients = data.map(client => client.name);
+ this.clients = data;
})
.catch(error => {
console.error(error);
@@ -151,25 +153,25 @@
.then(response => response.json())
.then(data => {
console.log(data);
- this.products = data.map(product => product.name);
+ this.products = data;
})
.catch(error => {
console.error(error);
});
},
addLine() {
- this.purchase.lines.push({ product: '', price: 0, quantity:0 });
+ this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0 });
},
removeLine(index) {
- this.purchase.lines.splice(index, 1);
+ this.purchase.saleline_set.splice(index, 1);
},
calculateSubtotal(line) {
- return line.price * line.quantity;
+ return line.unit_price * line.quantity;
},
async submit() {
if (this.$refs.form.validate()) {
try {
- const response = await fetch('http://localhost:8000/don_confiao/', {
+ const response = await fetch('/don_confiao/api/sales/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
diff --git a/tienda_ilusion/don_confiao/serializers.py b/tienda_ilusion/don_confiao/serializers.py
index df664c7..61fc9c9 100644
--- a/tienda_ilusion/don_confiao/serializers.py
+++ b/tienda_ilusion/don_confiao/serializers.py
@@ -18,9 +18,9 @@ class SaleSerializer(serializers.ModelSerializer):
class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
- fields = ['name', 'price', 'measuring_unit', 'categories']
+ fields = ['id', 'name', 'price', 'measuring_unit', 'categories']
class CustomerSerializer(serializers.ModelSerializer):
class Meta:
model = Customer
- fields = ['name', 'address']
+ fields = ['id', 'name', 'address']