Reviewed-on: OneTeam/don_confiao#61
This commit is contained in:
		@@ -1,94 +1,102 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <v-container>
 | 
					<v-container>
 | 
				
			||||||
      <v-form ref="form" v-model="valid">
 | 
					  <v-form ref="form" v-model="valid">
 | 
				
			||||||
 | 
					    <v-row>
 | 
				
			||||||
 | 
					      <v-col>
 | 
				
			||||||
 | 
					        <v-autocomplete
 | 
				
			||||||
 | 
					          v-model="purchase.customer"
 | 
				
			||||||
 | 
					          :items="filteredClients"
 | 
				
			||||||
 | 
					          :search="client_search"
 | 
				
			||||||
 | 
					          no-data-text="No se hallaron clientes"
 | 
				
			||||||
 | 
					          item-title="name"
 | 
				
			||||||
 | 
					          item-value="id"
 | 
				
			||||||
 | 
					          label="Cliente"
 | 
				
			||||||
 | 
					          :rules="[rules.required]"
 | 
				
			||||||
 | 
					          required
 | 
				
			||||||
 | 
					          class="mr-4"
 | 
				
			||||||
 | 
					          ></v-autocomplete>
 | 
				
			||||||
 | 
					        <v-btn color="primary" @click="openModal">Agregar Cliente</v-btn>
 | 
				
			||||||
 | 
					        <CreateCustomerModal ref="customerModal" @customerCreated="handleNewCustomer"/>
 | 
				
			||||||
 | 
					      </v-col>
 | 
				
			||||||
 | 
					      <v-col
 | 
				
			||||||
 | 
					        lg="2"
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					        <v-text-field
 | 
				
			||||||
 | 
					          v-model="purchase.date"
 | 
				
			||||||
 | 
					          label="Fecha"
 | 
				
			||||||
 | 
					          type="date"
 | 
				
			||||||
 | 
					          :rules="[rules.required]"
 | 
				
			||||||
 | 
					          required
 | 
				
			||||||
 | 
					          ></v-text-field>
 | 
				
			||||||
 | 
					      </v-col>
 | 
				
			||||||
 | 
					    </v-row>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <v-textarea
 | 
				
			||||||
 | 
					      v-model="purchase.notes"
 | 
				
			||||||
 | 
					      label="Notas"
 | 
				
			||||||
 | 
					      rows="2"
 | 
				
			||||||
 | 
					      ></v-textarea>
 | 
				
			||||||
 | 
					    <v-divider></v-divider>
 | 
				
			||||||
 | 
					    <v-container>
 | 
				
			||||||
 | 
					      <v-toolbar>
 | 
				
			||||||
 | 
					        <v-toolbar-title secondary>Productos</v-toolbar-title>
 | 
				
			||||||
 | 
					      </v-toolbar>
 | 
				
			||||||
 | 
					      <v-container v-for="(line, index) in purchase.saleline_set" :key="line.id">
 | 
				
			||||||
        <v-row>
 | 
					        <v-row>
 | 
				
			||||||
          <v-col>
 | 
					          <v-col>
 | 
				
			||||||
            <v-autocomplete
 | 
					            <v-autocomplete
 | 
				
			||||||
              v-model="purchase.customer"
 | 
					              v-model="line.product"
 | 
				
			||||||
              :items="filteredClients"
 | 
					              :items="filteredProducts"
 | 
				
			||||||
              :search="client_search"
 | 
					              :search="product_search"
 | 
				
			||||||
              no-data-text="No se hallaron clientes"
 | 
					              @update:modelValue="onProductChange(index)"
 | 
				
			||||||
 | 
					              no-data-text="No se hallaron productos"
 | 
				
			||||||
              item-title="name"
 | 
					              item-title="name"
 | 
				
			||||||
              item-value="id"
 | 
					              item-value="id"
 | 
				
			||||||
              label="Cliente"
 | 
					              item-subtitle="Price"
 | 
				
			||||||
 | 
					              label="Producto"
 | 
				
			||||||
              :rules="[rules.required]"
 | 
					              :rules="[rules.required]"
 | 
				
			||||||
              required
 | 
					              required
 | 
				
			||||||
              class="mr-4"
 | 
					 | 
				
			||||||
            ></v-autocomplete>
 | 
					 | 
				
			||||||
            <v-btn color="primary" @click="openModal">Agregar Cliente</v-btn>
 | 
					 | 
				
			||||||
            <CreateCustomerModal ref="customerModal" @customerCreated="handleNewCustomer"/>
 | 
					 | 
				
			||||||
          </v-col>
 | 
					 | 
				
			||||||
          <v-col
 | 
					 | 
				
			||||||
            lg="2"
 | 
					 | 
				
			||||||
          >
 | 
					 | 
				
			||||||
          <v-text-field
 | 
					 | 
				
			||||||
            v-model="purchase.date"
 | 
					 | 
				
			||||||
            label="Fecha"
 | 
					 | 
				
			||||||
            type="date"
 | 
					 | 
				
			||||||
            :rules="[rules.required]"
 | 
					 | 
				
			||||||
            required
 | 
					 | 
				
			||||||
            ></v-text-field>
 | 
					 | 
				
			||||||
          </v-col>
 | 
					 | 
				
			||||||
          </v-row>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        <v-textarea
 | 
					 | 
				
			||||||
          v-model="purchase.notes"
 | 
					 | 
				
			||||||
          label="Notas"
 | 
					 | 
				
			||||||
          rows="2"
 | 
					 | 
				
			||||||
        ></v-textarea>
 | 
					 | 
				
			||||||
        <v-divider></v-divider>
 | 
					 | 
				
			||||||
        <v-container>
 | 
					 | 
				
			||||||
          <v-toolbar>
 | 
					 | 
				
			||||||
            <v-toolbar-title secondary>Productos</v-toolbar-title>
 | 
					 | 
				
			||||||
          </v-toolbar>
 | 
					 | 
				
			||||||
        <v-container v-for="(line, index) in purchase.saleline_set" :key="line.id">
 | 
					 | 
				
			||||||
          <v-row>
 | 
					 | 
				
			||||||
            <v-col>
 | 
					 | 
				
			||||||
              <v-autocomplete
 | 
					 | 
				
			||||||
                v-model="line.product"
 | 
					 | 
				
			||||||
                :items="filteredProducts"
 | 
					 | 
				
			||||||
                :search="product_search"
 | 
					 | 
				
			||||||
                @update:modelValue="onProductChange(index)"
 | 
					 | 
				
			||||||
                no-data-text="No se hallaron productos"
 | 
					 | 
				
			||||||
                item-title="name"
 | 
					 | 
				
			||||||
                item-value="id"
 | 
					 | 
				
			||||||
                item-subtitle="Price"
 | 
					 | 
				
			||||||
                label="Producto"
 | 
					 | 
				
			||||||
                :rules="[rules.required]"
 | 
					 | 
				
			||||||
                required
 | 
					 | 
				
			||||||
              >
 | 
					              >
 | 
				
			||||||
                <template v-slot:item="{ props, item }">
 | 
					              <template v-slot:item="{ props, item }">
 | 
				
			||||||
                  <v-list-item v-bind="props" :title="item.raw.name" :subtitle="formatPrice(item.raw.price)"></v-list-item>
 | 
					                <v-list-item v-bind="props" :title="item.raw.name" :subtitle="formatPrice(item.raw.price)"></v-list-item>
 | 
				
			||||||
                </template>
 | 
					              </template>
 | 
				
			||||||
              </v-autocomplete>
 | 
					            </v-autocomplete>
 | 
				
			||||||
            </v-col>
 | 
					          </v-col>
 | 
				
			||||||
            <v-col>
 | 
					          <v-col>
 | 
				
			||||||
              <v-text-field
 | 
					            <v-text-field
 | 
				
			||||||
                v-model.number="line.unit_price"
 | 
					              v-model.number="line.unit_price"
 | 
				
			||||||
                label="Precio"
 | 
					              label="Precio"
 | 
				
			||||||
                type="number"
 | 
					              type="number"
 | 
				
			||||||
                :rules="[rules.required]"
 | 
					              :rules="[rules.required]"
 | 
				
			||||||
                prefix="$"
 | 
					              prefix="$"
 | 
				
			||||||
                required
 | 
					              required
 | 
				
			||||||
                readonly
 | 
					              readonly
 | 
				
			||||||
              ></v-text-field>
 | 
					              ></v-text-field>
 | 
				
			||||||
            </v-col>
 | 
					          </v-col>
 | 
				
			||||||
            <v-col>
 | 
					          <v-col>
 | 
				
			||||||
              <v-text-field
 | 
					            <v-text-field
 | 
				
			||||||
                v-model.number="line.quantity"
 | 
					              v-model.number="line.quantity"
 | 
				
			||||||
                label="Cantidad"
 | 
					              label="Cantidad"
 | 
				
			||||||
                type="number"
 | 
					              type="number"
 | 
				
			||||||
                :rules="[rules.required]"
 | 
					              :rules="[rules.required]"
 | 
				
			||||||
                required
 | 
					              required
 | 
				
			||||||
              ></v-text-field>
 | 
					              ></v-text-field>
 | 
				
			||||||
            </v-col>
 | 
					          </v-col>
 | 
				
			||||||
            <v-col>
 | 
					          <v-col>
 | 
				
			||||||
              <v-text-field
 | 
					            <v-text-field
 | 
				
			||||||
                type="number"
 | 
					              v-model="line.measuring_unit"
 | 
				
			||||||
                :value="calculateSubtotal(line)"
 | 
					              label="UdM"
 | 
				
			||||||
                label="Subtotal"
 | 
					              persistent-placeholder="true"
 | 
				
			||||||
                prefix="$"
 | 
					              readonly
 | 
				
			||||||
                readonly
 | 
					              ></v-text-field>
 | 
				
			||||||
 | 
					          </v-col>
 | 
				
			||||||
 | 
					          <v-col>
 | 
				
			||||||
 | 
					            <v-text-field
 | 
				
			||||||
 | 
					              type="number"
 | 
				
			||||||
 | 
					              :value="calculateSubtotal(line)"
 | 
				
			||||||
 | 
					              label="Subtotal"
 | 
				
			||||||
 | 
					              prefix="$"
 | 
				
			||||||
 | 
					              readonly
 | 
				
			||||||
                disable
 | 
					                disable
 | 
				
			||||||
                persistent-placeholder="true"
 | 
					                persistent-placeholder="true"
 | 
				
			||||||
              ></v-text-field>
 | 
					              ></v-text-field>
 | 
				
			||||||
@@ -133,7 +141,7 @@
 | 
				
			|||||||
         date: this.getCurrentDate(),
 | 
					         date: this.getCurrentDate(),
 | 
				
			||||||
         customer: null,
 | 
					         customer: null,
 | 
				
			||||||
         notes: '',
 | 
					         notes: '',
 | 
				
			||||||
         saleline_set: [{product:'', unit_price: 0, quantity: 0}],
 | 
					         saleline_set: [{product:'', unit_price: 0, quantity: 0, unit: ''}],
 | 
				
			||||||
       },
 | 
					       },
 | 
				
			||||||
       rules: {
 | 
					       rules: {
 | 
				
			||||||
         required: value => !!value || 'Requerido.',
 | 
					         required: value => !!value || 'Requerido.',
 | 
				
			||||||
@@ -195,7 +203,9 @@
 | 
				
			|||||||
     onProductChange(index) {
 | 
					     onProductChange(index) {
 | 
				
			||||||
       const selectedProductId = this.purchase.saleline_set[index].product;
 | 
					       const selectedProductId = this.purchase.saleline_set[index].product;
 | 
				
			||||||
       const selectedProduct = this.products.find(p => p.id == selectedProductId);
 | 
					       const selectedProduct = this.products.find(p => p.id == selectedProductId);
 | 
				
			||||||
       this.purchase.saleline_set[index].unit_price = selectedProduct.price;
 | 
					         this.purchase.saleline_set[index].unit_price = selectedProduct.price;
 | 
				
			||||||
 | 
					         console.log(selectedProduct.measuring_unit);
 | 
				
			||||||
 | 
					         this.purchase.saleline_set[index].measuring_unit = selectedProduct.measuring_unit;
 | 
				
			||||||
     },
 | 
					     },
 | 
				
			||||||
     fetchClients() {
 | 
					     fetchClients() {
 | 
				
			||||||
       fetch('/don_confiao/api/customers/')
 | 
					       fetch('/don_confiao/api/customers/')
 | 
				
			||||||
@@ -223,7 +233,7 @@
 | 
				
			|||||||
         });
 | 
					         });
 | 
				
			||||||
     },
 | 
					     },
 | 
				
			||||||
     addLine() {
 | 
					     addLine() {
 | 
				
			||||||
       this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0 });
 | 
					       this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0, measuring_unit: ''});
 | 
				
			||||||
     },
 | 
					     },
 | 
				
			||||||
     removeLine(index) {
 | 
					     removeLine(index) {
 | 
				
			||||||
         // Solo elimina si hay más de una línea
 | 
					         // Solo elimina si hay más de una línea
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user