Compare commits

..

No commits in common. "02a010b50d58680542d8552111f60bf2eb3daf1b" and "589b7c0bfb9478e535e053e4a997fd2589312270" have entirely different histories.

View File

@ -1,102 +1,94 @@
<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="line.product" v-model="purchase.customer"
:items="filteredProducts" :items="filteredClients"
:search="product_search" :search="client_search"
@update:modelValue="onProductChange(index)" no-data-text="No se hallaron clientes"
no-data-text="No se hallaron productos"
item-title="name" item-title="name"
item-value="id" item-value="id"
item-subtitle="Price" label="Cliente"
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
v-model="line.measuring_unit" type="number"
label="UdM" :value="calculateSubtotal(line)"
persistent-placeholder="true" label="Subtotal"
readonly prefix="$"
></v-text-field> readonly
</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>
@ -141,7 +133,7 @@
date: this.getCurrentDate(), date: this.getCurrentDate(),
customer: null, customer: null,
notes: '', notes: '',
saleline_set: [{product:'', unit_price: 0, quantity: 0, unit: ''}], saleline_set: [{product:'', unit_price: 0, quantity: 0}],
}, },
rules: { rules: {
required: value => !!value || 'Requerido.', required: value => !!value || 'Requerido.',
@ -203,9 +195,7 @@
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/')
@ -233,7 +223,7 @@
}); });
}, },
addLine() { addLine() {
this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0, measuring_unit: ''}); this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0 });
}, },
removeLine(index) { removeLine(index) {
// Solo elimina si hay más de una línea // Solo elimina si hay más de una línea