From fe1e6e83361f4494b56a5d9b3e53dd1605f71273 Mon Sep 17 00:00:00 2001
From: Rodia <alejandro.ayala@onecluster.org>
Date: Sat, 16 Nov 2024 15:59:56 -0500
Subject: [PATCH] Fix: closed #79

---
 .../don-confiao/src/components/Purchase.vue   | 68 +++++++++----------
 ...t_type_payment_alter_sale_date_and_more.py | 28 ++++++++
 tienda_ilusion/don_confiao/models.py          |  2 +-
 tienda_ilusion/don_confiao/tests/tests.py     |  4 +-
 4 files changed, 64 insertions(+), 38 deletions(-)
 create mode 100644 tienda_ilusion/don_confiao/migrations/0034_alter_payment_type_payment_alter_sale_date_and_more.py

diff --git a/tienda_ilusion/don_confiao/frontend/don-confiao/src/components/Purchase.vue b/tienda_ilusion/don_confiao/frontend/don-confiao/src/components/Purchase.vue
index 9340e08..0747b8a 100644
--- a/tienda_ilusion/don_confiao/frontend/don-confiao/src/components/Purchase.vue
+++ b/tienda_ilusion/don_confiao/frontend/don-confiao/src/components/Purchase.vue
@@ -2,36 +2,34 @@
 <v-container>
   <v-form ref="purchase" v-model="valid" @change="onFormChange">
     <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"
-          @update:model-value="onFormChange"
-          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-autocomplete
+                v-model="purchase.customer"
+                :items="filteredClients"
+                :search="client_search"
+                no-data-text="No se hallaron clientes"
+                item-title="name"
+                item-value="id"
+                @update:model-value="onFormChange"
+                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-col lg="4">
+          <v-text-field
+              v-model="purchase.date"
+              label="Fecha"
+              type="datetime-local"
+              :rules="[rules.required]"
+              required
+              readonly
           ></v-text-field>
       </v-col>
-    </v-row>
-
+     </v-row>
     <v-textarea
       v-model="purchase.notes"
       label="Notas"
@@ -247,15 +245,15 @@
        }
      },
      getCurrentDate() {
-       const today = new Date();
-       const yyyy = today.getFullYear();
-       const mm = String(today.getMonth() + 1).padStart(2, '0');
-       const dd = String(today.getDate()).padStart(2, '0');
-       return `${yyyy}-${mm}-${dd}`;
+         const today = new Date();
+         const gmtOffSet = -5;
+         const localDate = new Date(today.getTime() + (gmtOffSet * 60 * 60 * 1000));
+         // Formatear la fecha y hora en el formato YYYY-MM-DDTHH:MM
+         const formattedDate = localDate.toISOString().slice(0,16);
+         return formattedDate;
      },
-
-     onProductChange(index) {
-       const selectedProductId = this.purchase.saleline_set[index].product;
+       onProductChange(index) {
+           const selectedProductId = this.purchase.saleline_set[index].product;
        const selectedProduct = this.products.find(p => p.id == selectedProductId);
          this.purchase.saleline_set[index].unit_price = selectedProduct.price;
          this.purchase.saleline_set[index].measuring_unit = selectedProduct.measuring_unit;
diff --git a/tienda_ilusion/don_confiao/migrations/0034_alter_payment_type_payment_alter_sale_date_and_more.py b/tienda_ilusion/don_confiao/migrations/0034_alter_payment_type_payment_alter_sale_date_and_more.py
new file mode 100644
index 0000000..c6dc291
--- /dev/null
+++ b/tienda_ilusion/don_confiao/migrations/0034_alter_payment_type_payment_alter_sale_date_and_more.py
@@ -0,0 +1,28 @@
+# Generated by Django 5.0.6 on 2024-11-16 20:55
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('don_confiao', '0033_sale_payment_method'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='payment',
+            name='type_payment',
+            field=models.CharField(choices=[('CASH', 'Efectivo'), ('CONFIAR', 'Confiar'), ('BANCOLOMBIA', 'Bancolombia')], default='CASH', max_length=30),
+        ),
+        migrations.AlterField(
+            model_name='sale',
+            name='date',
+            field=models.DateTimeField(verbose_name='Date'),
+        ),
+        migrations.AlterField(
+            model_name='sale',
+            name='payment_method',
+            field=models.CharField(choices=[('CASH', 'Efectivo'), ('CONFIAR', 'Confiar'), ('BANCOLOMBIA', 'Bancolombia')], default='CASH', max_length=30),
+        ),
+    ]
diff --git a/tienda_ilusion/don_confiao/models.py b/tienda_ilusion/don_confiao/models.py
index ff21a72..5ded6db 100644
--- a/tienda_ilusion/don_confiao/models.py
+++ b/tienda_ilusion/don_confiao/models.py
@@ -64,7 +64,7 @@ class Product(models.Model):
 
 class Sale(models.Model):
     customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
-    date = models.DateField("Date")
+    date = models.DateTimeField("Date")
     phone = models.CharField(max_length=13, null=True, blank=True)
     description = models.CharField(max_length=255, null=True, blank=True)
     payment_method = models.CharField(
diff --git a/tienda_ilusion/don_confiao/tests/tests.py b/tienda_ilusion/don_confiao/tests/tests.py
index 672d3b4..976518b 100644
--- a/tienda_ilusion/don_confiao/tests/tests.py
+++ b/tienda_ilusion/don_confiao/tests/tests.py
@@ -19,7 +19,7 @@ class ConfiaoTest(TestCase):
     def test_create_sale(self):
         sale = Sale()
         sale.customer = self.customer
-        sale.date = "2024-06-22"
+        sale.date = "2024-06-22 12:05:00"
         sale.phone = '666666666'
         sale.description = "Description"
         sale.save()
@@ -29,7 +29,7 @@ class ConfiaoTest(TestCase):
     def test_can_create_sale_without_payment_method(self):
         sale = Sale()
         sale.customer = self.customer
-        sale.date = "2024-06-22"
+        sale.date = "2024-06-22 12:05:00"
         sale.phone = '666666666'
         sale.description = "Description"
         sale.payment_method = ''