view(Purchase): generate purchase from vuetify.
This commit is contained in:
		| @@ -22,13 +22,13 @@ | ||||
|           required | ||||
|         ></v-text-field> | ||||
|         <v-select | ||||
|           v-model="purchase.client" | ||||
|           v-model="purchase.customer" | ||||
|           :items="clients" | ||||
|           item-title="name" | ||||
|           item-value="id" | ||||
|           label="Cliente" | ||||
|           :rules="[rules.required]" | ||||
|           required | ||||
|           item-text="name" | ||||
|           item-value="id" | ||||
|         ></v-select> | ||||
|         <v-textarea | ||||
|           v-model="purchase.notes" | ||||
| @@ -39,12 +39,14 @@ | ||||
|           <v-toolbar> | ||||
|           <v-toolbar-title secondary>Productos</v-toolbar-title> | ||||
|         </v-toolbar> | ||||
|         <div v-for="(line, index) in purchase.lines" :key="line.id"> | ||||
|         <div v-for="(line, index) in purchase.saleline_set" :key="line.id"> | ||||
|           <v-row> | ||||
|             <v-col> | ||||
|               <v-select | ||||
|                 v-model="line.product" | ||||
|                 :items="products" | ||||
|                 item-title="name" | ||||
|                 item-value="id" | ||||
|                 label="Producto" | ||||
|                 :rules="[rules.required]" | ||||
|                 required | ||||
| @@ -52,7 +54,7 @@ | ||||
|             </v-col> | ||||
|             <v-col> | ||||
|               <v-text-field | ||||
|                 v-model.number="line.price" | ||||
|                 v-model.number="line.unit_price" | ||||
|                 label="Precio" | ||||
|                 type="number" | ||||
|                 :rules="[rules.required]" | ||||
| @@ -111,7 +113,7 @@ | ||||
|           date: '', | ||||
|           client: null, | ||||
|           notes: '', | ||||
|           lines: [{product:'', price: 0, quantity: 0}], | ||||
|           saleline_set: [{product:'', unit_price: 0, quantity: 0}], | ||||
|         }, | ||||
|         rules: { | ||||
|           required: value => !!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', | ||||
|   | ||||
| @@ -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'] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user