view(Purchase): generate purchase from vuetify.
This commit is contained in:
		@@ -22,13 +22,13 @@
 | 
				
			|||||||
          required
 | 
					          required
 | 
				
			||||||
        ></v-text-field>
 | 
					        ></v-text-field>
 | 
				
			||||||
        <v-select
 | 
					        <v-select
 | 
				
			||||||
          v-model="purchase.client"
 | 
					          v-model="purchase.customer"
 | 
				
			||||||
          :items="clients"
 | 
					          :items="clients"
 | 
				
			||||||
 | 
					          item-title="name"
 | 
				
			||||||
 | 
					          item-value="id"
 | 
				
			||||||
          label="Cliente"
 | 
					          label="Cliente"
 | 
				
			||||||
          :rules="[rules.required]"
 | 
					          :rules="[rules.required]"
 | 
				
			||||||
          required
 | 
					          required
 | 
				
			||||||
          item-text="name"
 | 
					 | 
				
			||||||
          item-value="id"
 | 
					 | 
				
			||||||
        ></v-select>
 | 
					        ></v-select>
 | 
				
			||||||
        <v-textarea
 | 
					        <v-textarea
 | 
				
			||||||
          v-model="purchase.notes"
 | 
					          v-model="purchase.notes"
 | 
				
			||||||
@@ -39,12 +39,14 @@
 | 
				
			|||||||
          <v-toolbar>
 | 
					          <v-toolbar>
 | 
				
			||||||
          <v-toolbar-title secondary>Productos</v-toolbar-title>
 | 
					          <v-toolbar-title secondary>Productos</v-toolbar-title>
 | 
				
			||||||
        </v-toolbar>
 | 
					        </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-row>
 | 
				
			||||||
            <v-col>
 | 
					            <v-col>
 | 
				
			||||||
              <v-select
 | 
					              <v-select
 | 
				
			||||||
                v-model="line.product"
 | 
					                v-model="line.product"
 | 
				
			||||||
                :items="products"
 | 
					                :items="products"
 | 
				
			||||||
 | 
					                item-title="name"
 | 
				
			||||||
 | 
					                item-value="id"
 | 
				
			||||||
                label="Producto"
 | 
					                label="Producto"
 | 
				
			||||||
                :rules="[rules.required]"
 | 
					                :rules="[rules.required]"
 | 
				
			||||||
                required
 | 
					                required
 | 
				
			||||||
@@ -52,7 +54,7 @@
 | 
				
			|||||||
            </v-col>
 | 
					            </v-col>
 | 
				
			||||||
            <v-col>
 | 
					            <v-col>
 | 
				
			||||||
              <v-text-field
 | 
					              <v-text-field
 | 
				
			||||||
                v-model.number="line.price"
 | 
					                v-model.number="line.unit_price"
 | 
				
			||||||
                label="Precio"
 | 
					                label="Precio"
 | 
				
			||||||
                type="number"
 | 
					                type="number"
 | 
				
			||||||
                :rules="[rules.required]"
 | 
					                :rules="[rules.required]"
 | 
				
			||||||
@@ -111,7 +113,7 @@
 | 
				
			|||||||
          date: '',
 | 
					          date: '',
 | 
				
			||||||
          client: null,
 | 
					          client: null,
 | 
				
			||||||
          notes: '',
 | 
					          notes: '',
 | 
				
			||||||
          lines: [{product:'', price: 0, quantity: 0}],
 | 
					          saleline_set: [{product:'', unit_price: 0, quantity: 0}],
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        rules: {
 | 
					        rules: {
 | 
				
			||||||
          required: value => !!value || 'Requerido.',
 | 
					          required: value => !!value || 'Requerido.',
 | 
				
			||||||
@@ -130,8 +132,8 @@
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    computed: {
 | 
					    computed: {
 | 
				
			||||||
      calculateTotal() {
 | 
					      calculateTotal() {
 | 
				
			||||||
        return this.purchase.lines.reduce((total, line) => {
 | 
					        return this.purchase.saleline_set.reduce((total, saleline) => {
 | 
				
			||||||
          return total + this.calculateSubtotal(line);
 | 
					          return total + this.calculateSubtotal(saleline);
 | 
				
			||||||
        }, 0);
 | 
					        }, 0);
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@@ -140,7 +142,7 @@
 | 
				
			|||||||
        fetch('/don_confiao/api/customers/')
 | 
					        fetch('/don_confiao/api/customers/')
 | 
				
			||||||
          .then(response => response.json())
 | 
					          .then(response => response.json())
 | 
				
			||||||
          .then(data => {
 | 
					          .then(data => {
 | 
				
			||||||
            this.clients = data.map(client => client.name);
 | 
					            this.clients = data;
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
          .catch(error => {
 | 
					          .catch(error => {
 | 
				
			||||||
            console.error(error);
 | 
					            console.error(error);
 | 
				
			||||||
@@ -151,25 +153,25 @@
 | 
				
			|||||||
          .then(response => response.json())
 | 
					          .then(response => response.json())
 | 
				
			||||||
          .then(data => {
 | 
					          .then(data => {
 | 
				
			||||||
            console.log(data);
 | 
					            console.log(data);
 | 
				
			||||||
            this.products = data.map(product => product.name);
 | 
					            this.products = data;
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
          .catch(error => {
 | 
					          .catch(error => {
 | 
				
			||||||
            console.error(error);
 | 
					            console.error(error);
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      addLine() {
 | 
					      addLine() {
 | 
				
			||||||
        this.purchase.lines.push({ product: '', price: 0, quantity:0 });
 | 
					        this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0 });
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      removeLine(index) {
 | 
					      removeLine(index) {
 | 
				
			||||||
        this.purchase.lines.splice(index, 1);
 | 
					        this.purchase.saleline_set.splice(index, 1);
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      calculateSubtotal(line) {
 | 
					      calculateSubtotal(line) {
 | 
				
			||||||
        return line.price * line.quantity;
 | 
					        return line.unit_price * line.quantity;
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      async submit() {
 | 
					      async submit() {
 | 
				
			||||||
        if (this.$refs.form.validate()) {
 | 
					        if (this.$refs.form.validate()) {
 | 
				
			||||||
          try {
 | 
					          try {
 | 
				
			||||||
            const response = await fetch('http://localhost:8000/don_confiao/', {
 | 
					            const response = await fetch('/don_confiao/api/sales/', {
 | 
				
			||||||
              method: 'POST',
 | 
					              method: 'POST',
 | 
				
			||||||
              headers: {
 | 
					              headers: {
 | 
				
			||||||
                'Content-Type': 'application/json',
 | 
					                'Content-Type': 'application/json',
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,9 +18,9 @@ class SaleSerializer(serializers.ModelSerializer):
 | 
				
			|||||||
class ProductSerializer(serializers.ModelSerializer):
 | 
					class ProductSerializer(serializers.ModelSerializer):
 | 
				
			||||||
    class Meta:
 | 
					    class Meta:
 | 
				
			||||||
        model = Product
 | 
					        model = Product
 | 
				
			||||||
        fields = ['name', 'price', 'measuring_unit', 'categories']
 | 
					        fields = ['id', 'name', 'price', 'measuring_unit', 'categories']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CustomerSerializer(serializers.ModelSerializer):
 | 
					class CustomerSerializer(serializers.ModelSerializer):
 | 
				
			||||||
    class Meta:
 | 
					    class Meta:
 | 
				
			||||||
        model = Customer
 | 
					        model = Customer
 | 
				
			||||||
        fields = ['name', 'address']
 | 
					        fields = ['id', 'name', 'address']
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user