Compare commits
	
		
			1 Commits
		
	
	
		
			main
			...
			TrytonApiC
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| efb33ef011 | 
							
								
								
									
										4
									
								
								Rakefile
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Rakefile
									
									
									
									
									
								
							| @@ -12,12 +12,12 @@ namespace :live do | ||||
|  | ||||
|   desc 'monitorear salida' | ||||
|   task :tail do | ||||
|     compose('logs', '-f', 'frontend', compose: DOCKER_COMPOSE) | ||||
|     compose('logs', '-f', 'django', compose: DOCKER_COMPOSE) | ||||
|   end | ||||
|  | ||||
|   desc 'monitorear salida' | ||||
|   task :tail_end do | ||||
|     compose('logs', '-f', '-n 50', 'frontend', compose: DOCKER_COMPOSE) | ||||
|     compose('logs', '-f', '-n 50', 'django', compose: DOCKER_COMPOSE) | ||||
|   end | ||||
|  | ||||
|   desc 'iniciar entorno' | ||||
|   | ||||
| @@ -7,7 +7,4 @@ services: | ||||
|       - ./:/app/ | ||||
|     ports: | ||||
|       - "7001:3000" | ||||
|     environment: | ||||
|       - VITE_DJANGO_BASE_URL=http://localhost:7000 | ||||
|       - VITE_API_IMPLEMENTATION=django | ||||
|  | ||||
|   | ||||
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -31,7 +31,7 @@ | ||||
|         "unplugin-fonts": "^1.1.1", | ||||
|         "unplugin-vue-components": "^0.27.2", | ||||
|         "unplugin-vue-router": "^0.10.0", | ||||
|         "vite": "^5.3.3", | ||||
|         "vite": "^5.4.14", | ||||
|         "vite-plugin-vue-layouts": "^0.11.0", | ||||
|         "vite-plugin-vuetify": "^2.0.3", | ||||
|         "vue-router": "^4.4.0" | ||||
| @@ -5229,9 +5229,9 @@ | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/vite": { | ||||
|       "version": "5.4.4", | ||||
|       "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.4.tgz", | ||||
|       "integrity": "sha512-RHFCkULitycHVTtelJ6jQLd+KSAAzOgEYorV32R2q++M6COBjKJR6BxqClwp5sf0XaBDjVMuJ9wnNfyAJwjMkA==", | ||||
|       "version": "5.4.14", | ||||
|       "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.14.tgz", | ||||
|       "integrity": "sha512-EK5cY7Q1D8JNhSaPKVK4pwBFvaTmZxEnoKXLG/U9gmdDcihQGNzFlgIvaxezFR4glP1LsuiedwMBqCXH3wZccA==", | ||||
|       "devOptional": true, | ||||
|       "license": "MIT", | ||||
|       "dependencies": { | ||||
|   | ||||
| @@ -31,7 +31,7 @@ | ||||
|     "unplugin-fonts": "^1.1.1", | ||||
|     "unplugin-vue-components": "^0.27.2", | ||||
|     "unplugin-vue-router": "^0.10.0", | ||||
|     "vite": "^5.3.3", | ||||
|     "vite": "^5.4.14", | ||||
|     "vite-plugin-vue-layouts": "^0.11.0", | ||||
|     "vite-plugin-vuetify": "^2.0.3", | ||||
|     "vue-router": "^4.4.0" | ||||
|   | ||||
| @@ -1 +0,0 @@ | ||||
| <svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" version="1.0"><path d="M256 196.25c0 40.122-21.534 60.038-64.603 59.747H67.495C22.498 255.997 0 236.663 0 197.994V60.184C0 20.06 22.016 0 66.049 0h124.384C234.144 0 256 20.206 256 60.62v135.63" style="text-align:start;line-height:125%;-inkscape-font-specification:Kimberley" font-size="108.872" font-weight="400" fill="#1b2019" font-family="Kimberley"/><path d="M19.006 169.515c5.949-3.124 17.076 1.966 22.115 10.12 4.518 7.31 27.406 14.114 35.516 10.558 5.412-2.372 6.779-5.378 7.202-15.844.798-19.685-3.636-35.098-17.99-62.536-7.205-13.77-14.753-29-16.775-33.835C47.052 73.14 41.601 64.6 36.961 59c-9.876-11.91-10.183-15.164-2.078-22.074C47.02 26.581 67.52 43.327 63.095 59.97c-2.178 8.191 2.003 20.14 15.85 45.295 16.431 29.85 33.084 41.94 43.03 31.243 2.57-2.763 5.759-18.178 8.698-42.04 4.421-35.889 4.399-38.037-.47-45.252-8.418-12.475-.48-25.42 12.84-20.943 13.43 4.513 22.192 22.778 13.775 28.714-3.735 2.633-4.942 10.29-6.636 42.097-2.173 40.785-.53 51.7 8.609 57.187 8.121 4.876 10.946 3.885 28.067-9.889 18.167-14.612 25.636-24.069 26.115-33.067.446-8.37 5.992-12.847 14.832-11.972 5.635.56 8.15 2.41 11.3 8.312 6.431 12.053 4.589 19.71-5.212 21.667-7.987 1.592-21.708 19.27-42.815 55.16-22.288 37.897-27.173 41.845-52.152 42.147-10.268.123-24.634-3.295-58.453-13.914-24.663-7.746-48.043-14.468-51.957-14.943-14.142-1.708-21.187-24.12-9.51-30.257z" fill="#ededed"/></svg> | ||||
| Before Width: | Height: | Size: 1.4 KiB | 
| @@ -1,341 +0,0 @@ | ||||
| <template> | ||||
| <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-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-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> | ||||
| p      </v-toolbar> | ||||
|       <v-container v-for="(line, index) in purchase.saleline_set" :key="line.id"> | ||||
|         <v-row> | ||||
|             <v-col | ||||
|                 lg="9"> | ||||
|             <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 }"> | ||||
|                 <v-list-item v-bind="props" :title="item.raw.name" :subtitle="formatPrice(item.raw.price)"></v-list-item> | ||||
|               </template> | ||||
|             </v-autocomplete> | ||||
|           </v-col> | ||||
|           <v-col | ||||
|               lg="2" | ||||
|           > | ||||
|               <v-text-field | ||||
|                   v-model.number="line.quantity" | ||||
|                   label="Cantidad" | ||||
|                   type="number" | ||||
|                   :rules="[rules.required,rules.positive]" | ||||
|                   required | ||||
|               ></v-text-field> | ||||
|           </v-col> | ||||
|         </v-row> | ||||
|         <v-row> | ||||
|           <v-col> | ||||
|             <v-text-field | ||||
|               v-model.number="line.unit_price" | ||||
|               label="Precio" | ||||
|               type="number" | ||||
|               :rules="[rules.required]" | ||||
|               prefix="$" | ||||
|               required | ||||
|               ></v-text-field> | ||||
|           </v-col> | ||||
|           <v-col> | ||||
|             <v-text-field | ||||
|               v-model="line.measuring_unit" | ||||
|               label="UdM" | ||||
|               persistent-placeholder="true" | ||||
|               readonly | ||||
|               ></v-text-field> | ||||
|           </v-col> | ||||
|           <v-col> | ||||
|             <v-text-field | ||||
|               type="number" | ||||
|               :value="calculateSubtotal(line)" | ||||
|               label="Subtotal" | ||||
|               prefix="$" | ||||
|               readonly | ||||
|                 disable | ||||
|                 persistent-placeholder="true" | ||||
|               ></v-text-field> | ||||
|             </v-col> | ||||
|             <v-col> | ||||
|               <v-btn @click="removeLine(index)" color="red">Eliminar</v-btn> | ||||
|             </v-col> | ||||
|         </v-row> | ||||
|         <v-alert type="warning" :duration="2000" closable v-model="show_alert_lines"> | ||||
|           No se puede eliminar la única línea. | ||||
|         </v-alert> | ||||
|       </v-container> | ||||
|         <v-btn @click="addLine" color="blue">Agregar</v-btn> | ||||
|         </v-container> | ||||
|         <v-divider></v-divider> | ||||
|         <v-text-field | ||||
|           :value="calculateTotal" | ||||
|           label="Total" | ||||
|           prefix="$" | ||||
|           readonly | ||||
|           persistent-placeholder="true" | ||||
|         ></v-text-field> | ||||
|         <v-container v-if="calculateTotal > 0"> | ||||
|           <v-select | ||||
|             :items="payment_methods" | ||||
|             v-model="purchase.payment_method" | ||||
|             item-title="text" | ||||
|             item-value="value" | ||||
|             label="Pago en" | ||||
|             :rules="[rules.required]" | ||||
|             required | ||||
|           ></v-select> | ||||
|           <v-btn @click="openCasherModal" v-if="purchase.payment_method === 'CASH'">Calcular Devuelta</v-btn> | ||||
|           <CasherModal :total_purchase="calculateTotal" ref="casherModal"</CasherModal> | ||||
|         </v-container> | ||||
|         <v-btn @click="submit" color="green">Comprar</v-btn> | ||||
|         <v-alert type="error" :duration="2000" closable v-model="show_alert_purchase"> | ||||
|           Verifique los campos obligatorios. | ||||
|         </v-alert> | ||||
|   </v-form> | ||||
| </v-container> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
|   import CustomerForm from './CreateCustomerModal.vue'; | ||||
|   import CasherModal from './CasherModal.vue'; | ||||
|   import { inject } from 'vue'; | ||||
|  | ||||
|   export default { | ||||
|     name: 'DonConfiao', | ||||
|     components: { | ||||
|      CustomerForm, | ||||
|      CasherModal, | ||||
|    }, | ||||
|    props: { | ||||
|      msg: String | ||||
|    }, | ||||
|    data() { | ||||
|      return { | ||||
|        api: inject('api'), | ||||
|        valid: false, | ||||
|        form_changed: false, | ||||
|        show_alert_lines: false, | ||||
|        show_alert_purchase: false, | ||||
|        client_search: '', | ||||
|        product_search: '', | ||||
|        payment_methods: null, | ||||
|        purchase: { | ||||
|          date: this.getCurrentDate(), | ||||
|          customer: null, | ||||
|          notes: '', | ||||
|          payment_method: null, | ||||
|          saleline_set: [{product:'', unit_price: 0, quantity: 0, unit: ''}], | ||||
|        }, | ||||
|        rules: { | ||||
|            required: value => !!value || 'Requerido.', | ||||
|            positive: value => value > 0 || 'La cantidad debe ser mayor que 0.', | ||||
|        }, | ||||
|          menuItems: [ | ||||
|              { title: 'Inicio', route: '/'}, | ||||
|              { title: 'Compras', route:'/compras'}, | ||||
|          ], | ||||
|          clients: [], | ||||
|          products: [], | ||||
|      }; | ||||
|    }, | ||||
|      created() { | ||||
|      this.fetchClients(); | ||||
|      this.fetchProducts(); | ||||
|      this.fetchPaymentMethods(); | ||||
|    }, | ||||
|    watch: { | ||||
|      group () { | ||||
|        this.drawer = false | ||||
|      }, | ||||
|    }, | ||||
|    beforeMount() { | ||||
|       window.addEventListener('beforeunload', this.confirmLeave); | ||||
|    }, | ||||
|    beforeDestroy() { | ||||
|       window.removeEventListener('beforeunload', this.confirmLeave); | ||||
|    }, | ||||
|    computed: { | ||||
|      calculateTotal() { | ||||
|        return this.purchase.saleline_set.reduce((total, saleline) => { | ||||
|          return total + this.calculateSubtotal(saleline); | ||||
|        }, 0); | ||||
|      }, | ||||
|      filteredClients() { | ||||
|        return this.clients.filter(client => { | ||||
|          if (this.client_search === '') { | ||||
|            return []; | ||||
|          } else { | ||||
|            return client.name.toLowerCase().includes(this.client_search.toLowerCase()); | ||||
|          } | ||||
|        }); | ||||
|      }, | ||||
|      filteredProducts() { | ||||
|        return this.products.filter(product => { | ||||
|          if (this.product_search === '') { | ||||
|            return []; | ||||
|          } else { | ||||
|            return product.name.toLowerCase().includes(this.product_search.toLowerCase()); | ||||
|          } | ||||
|        }); | ||||
|      }, | ||||
|    }, | ||||
|    methods: { | ||||
|      openModal() { | ||||
|       this.$refs.customerModal.openModal(); | ||||
|      }, | ||||
|      onFormChange() { | ||||
|        this.form_changed = true; | ||||
|      }, | ||||
|      openCasherModal() { | ||||
|        this.$refs.casherModal.dialog = true | ||||
|      }, | ||||
|      confirmLeave(event) { | ||||
|        if (this.form_changed) { | ||||
|          const message = '¿seguro que quieres salir? Perderas la información diligenciada'; | ||||
|          event.preventDefault(); | ||||
|          event.returnValue = message; | ||||
|          return message; | ||||
|        } | ||||
|      }, | ||||
|      getCurrentDate() { | ||||
|          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; | ||||
|        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; | ||||
|      }, | ||||
|      fetchClients() { | ||||
|        this.api.getCustomers() | ||||
|            .then(data => { | ||||
|              this.clients = data; | ||||
|            }) | ||||
|            .catch(error => { | ||||
|              console.error(error); | ||||
|            }); | ||||
|      }, | ||||
|        handleNewCustomer(newCustomer){ | ||||
|            this.clients.push(newCustomer); | ||||
|            this.purchase.customer = newCustomer.id; | ||||
|        }, | ||||
|      fetchProducts() { | ||||
|        this.api.getProducts() | ||||
|            .then(data => { | ||||
|              this.products = data; | ||||
|            }) | ||||
|            .catch(error => { | ||||
|              console.error(error); | ||||
|            }); | ||||
|      }, | ||||
|      fetchPaymentMethods() { | ||||
|        this.api.getPaymentMethods() | ||||
|            .then(data => { | ||||
|              this.payment_methods = data; | ||||
|            }) | ||||
|            .catch(error => { | ||||
|              console.error(error); | ||||
|            }); | ||||
|      }, | ||||
|      addLine() { | ||||
|        this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0, measuring_unit: ''}); | ||||
|      }, | ||||
|      removeLine(index) { | ||||
|          if (this.purchase.saleline_set.length > 1) { | ||||
|              this.purchase.saleline_set.splice(index, 1); | ||||
|          } else { | ||||
|            this.show_alert_lines = true; | ||||
|            setTimeout(() => { | ||||
|              this.show_alert_lines = false; | ||||
|            }, 2000); | ||||
|          } | ||||
|      }, | ||||
|      calculateSubtotal(line) { | ||||
|        return line.unit_price * line.quantity; | ||||
|      }, | ||||
|      async submit() { | ||||
|        this.$refs.purchase.validate(); | ||||
|          if (this.valid) { | ||||
|            this.api.createPurchase(this.purchase) | ||||
|                .then(data => { | ||||
|                  console.log('Compra enviada:', data); | ||||
|                  this.$router.push({ | ||||
|                    path: "/summary_purchase", | ||||
|                    query : {id: parseInt(data.id)} | ||||
|                  }); | ||||
|                }) | ||||
|            .catch(error => console.error('Error al enviarl la compra:', error)); | ||||
|        } else { | ||||
|          this.show_alert_purchase = true; | ||||
|            setTimeout(() => { | ||||
|              this.show_alert_purchase = false; | ||||
|            }, 4000); | ||||
|        } | ||||
|      }, | ||||
|      navigate(route) { | ||||
|        this.$router.push(route); | ||||
|      }, | ||||
|      formatPrice(price) { | ||||
|        return new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'COP' }).format(price); | ||||
|      }, | ||||
|    }, | ||||
|      mounted() { | ||||
|          this.fetchClients(); | ||||
|      } | ||||
|  }; | ||||
| </script> | ||||
| <style> | ||||
| </style> | ||||
| @@ -10,8 +10,7 @@ | ||||
|         </v-form> | ||||
|       </v-card-text> | ||||
|       <v-card-actions> | ||||
|         <v-btn type="submit" form="code-form" color="green">Aceptar</v-btn> | ||||
|         <v-btn :to="{ path: '/' }" color="red">Cancelar</v-btn> | ||||
|         <v-btn type="submit" form="code-form">Aceptar</v-btn> | ||||
|       </v-card-actions> | ||||
|     </v-card> | ||||
|   </v-dialog> | ||||
|   | ||||
| @@ -1,39 +0,0 @@ | ||||
| <template> | ||||
|   <div> | ||||
|     <v-btn @click="downloadCSV">Descargar CSV</v-btn> | ||||
|   </div> | ||||
| </template> | ||||
| <script> | ||||
|   import { inject } from 'vue'; | ||||
|  | ||||
|   export default { | ||||
|     name: 'ExportPurchasesForTryton', | ||||
|     data() { | ||||
|       return { | ||||
|         api: inject('api'), | ||||
|       }; | ||||
|     }, | ||||
|     methods: { | ||||
|       downloadCSV() { | ||||
|         this.api.getCSVForTryton() | ||||
|             .then(data => { | ||||
|               const blob = new Blob([data['csv']], {type: 'text/csv'}); | ||||
|               const pattern = /[/: ]/g; | ||||
|               const datetime = new Date(); | ||||
|               const date = datetime.toLocaleDateString().replace(pattern, '-'); | ||||
|               const time = datetime.toLocaleTimeString().replace(pattern, '-'); | ||||
|               const name = `VentasTryton_${date}_${time}.csv`; | ||||
|               const link = document.createElement('a'); | ||||
|  | ||||
|               link.href = URL.createObjectURL(blob); | ||||
|               link.download = name; | ||||
|               link.click(); | ||||
|               URL.revokeObjectURL(link.href); | ||||
|             }) | ||||
|             .catch(error => { | ||||
|               console.error(error); | ||||
|             }); | ||||
|       }, | ||||
|     }, | ||||
|   }; | ||||
| </script> | ||||
| @@ -12,53 +12,25 @@ | ||||
|   <v-navigation-drawer v-model="drawer" | ||||
|                        :location="$vuetify.display.mobile ? 'bottom' : undefined" | ||||
|                        temporary> | ||||
|     <v-list | ||||
|       density="compact" | ||||
|       nav | ||||
|     > | ||||
|       <v-list-item | ||||
|         v-for="item in menuItems" | ||||
|         :key="item.title" | ||||
|         :title="item.title" | ||||
|         :prepend-icon="item.icon" | ||||
|         @click="navigate(item.route)" | ||||
|       ></v-list-item> | ||||
|       <v-list-item prepend-icon="mdi-cog" title="Administracion" @click="toggleAdminMenu()"></v-list-item> | ||||
|       <v-list-item> | ||||
|         <v-list v-if="showAdminMenu"> | ||||
|           <v-list-item | ||||
|             v-for="item in menuAdminItems" | ||||
|             :key="item.title" | ||||
|             :title="item.title" | ||||
|             :prepend-icon="item.icon" | ||||
|             @click="navigateAdmin(item.route)" | ||||
|           ></v-list-item> | ||||
|         </v-list> | ||||
|       </v-list-item> | ||||
|     </v-list> | ||||
|       <v-list> | ||||
|           <v-list-item v-for="item in menuItems" :key="item.title" @click="navigate(item.route)"> | ||||
|               <v-list-item-title>{{ item.title }}</v-list-item-title> | ||||
|           </v-list-item> | ||||
|       </v-list> | ||||
|   </v-navigation-drawer> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
|  import trytonIcon from '../assets/icons/tryton-icon.svg'; | ||||
|  export default { | ||||
|      name: 'NavBar', | ||||
|      data: () => ({ | ||||
|          drawer: false, | ||||
|          group: null, | ||||
|          showAdminMenu: false, | ||||
|          menuItems: [ | ||||
|              { title: 'Inicio', route: '/', icon: 'mdi-home'}, | ||||
|              { title: 'Comprar', route:'/comprar', icon: 'mdi-cart'}, | ||||
|          ], | ||||
|          menuAdminItems: [ | ||||
|              { title: 'Cuadrar tarro', route: '/cuadrar_tarro', icon: 'mdi-calculator'}, | ||||
|              { title: 'Cuadres de tarro', route: '/cuadres_de_tarro', icon: 'mdi-chart-bar'}, | ||||
|              { title: 'CSV Tryton', route: '/ventas_para_tryton', icon: 'mdi-file-table'}, | ||||
|              { title: 'Compra adm', route: '/compra_admin', icon: 'mdi-cart'}, | ||||
|              { title: 'Actualizar Productos De Tryton', route: '/sincronizar_productos_tryton', icon: 'trytonIcon'}, | ||||
|              { title: 'Actualizar Clientes De Tryton', route: '/sincronizar_clientes_tryton', icon: 'trytonIcon'}, | ||||
|              { title: 'Actualizar Ventas Tryton', route: '/sincronizar_ventas_tryton', icon: 'trytonIcon'} | ||||
|              { title: 'Inicio', route: '/'}, | ||||
|              { title: 'Comprar', route:'/comprar'}, | ||||
|              { title: 'Cuadrar tarro', route: '/cuadrar_tarro'}, | ||||
|              { title: 'Cuadres de tarro', route: '/cuadres_de_tarro'}, | ||||
|          ], | ||||
|      }), | ||||
|      watch: { | ||||
| @@ -70,13 +42,6 @@ | ||||
|          navigate(route) { | ||||
|              this.$router.push(route); | ||||
|          }, | ||||
|          navigateAdmin(route) { | ||||
|              this.toggleAdminMenu(); | ||||
|              this.navigate(route); | ||||
|          }, | ||||
|          toggleAdminMenu() { | ||||
|              this.showAdminMenu = !this.showAdminMenu; | ||||
|          }, | ||||
|      } | ||||
|   } | ||||
|  } | ||||
| </script> | ||||
|   | ||||
| @@ -16,7 +16,7 @@ | ||||
|                 required | ||||
|                 class="mr-4" | ||||
|             ></v-autocomplete> | ||||
|             <!--<v-btn color="primary" @click="openModal">Agregar Cliente</v-btn>--> | ||||
|             <v-btn color="primary" @click="openModal">Agregar Cliente</v-btn> | ||||
|             <CreateCustomerModal ref="customerModal" @customerCreated="handleNewCustomer"/> | ||||
|       </v-col> | ||||
|       <v-col lg="4"> | ||||
| @@ -256,10 +256,10 @@ | ||||
|      }, | ||||
|        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; | ||||
|      }, | ||||
|            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; | ||||
|        }, | ||||
|      fetchClients() { | ||||
|        this.api.getCustomers() | ||||
|            .then(data => { | ||||
| @@ -276,7 +276,14 @@ | ||||
|      fetchProducts() { | ||||
|        this.api.getProducts() | ||||
|            .then(data => { | ||||
|              this.products = data; | ||||
|                const transformed_products = data.map(item => ({ | ||||
|                    id: item.id, | ||||
|                    name: item.name, | ||||
|                    price: item["template."]?.list_price?.decimal, | ||||
|                    measuring_unit: item["default_uom."]?.name, | ||||
|                    categories: [] | ||||
|                })); | ||||
|                this.products = transformed_products; | ||||
|            }) | ||||
|            .catch(error => { | ||||
|              console.error(error); | ||||
| @@ -285,7 +292,7 @@ | ||||
|      fetchPaymentMethods() { | ||||
|        this.api.getPaymentMethods() | ||||
|            .then(data => { | ||||
|              this.payment_methods = data; | ||||
|                this.payment_methods = data[0]?.payment_methods; | ||||
|            }) | ||||
|            .catch(error => { | ||||
|              console.error(error); | ||||
| @@ -309,8 +316,21 @@ | ||||
|      }, | ||||
|      async submit() { | ||||
|        this.$refs.purchase.validate(); | ||||
|          const tryton_sale = { | ||||
|              party: this.purchase.customer, | ||||
|              company: "1", | ||||
|              currency: "31", | ||||
|              pickup_location: "on_site", | ||||
|              lines: [[ | ||||
|                  "create", this.purchase.saleline_set.map(item => ({ | ||||
|                      product: item.product, | ||||
|                      quantity: item.quantity, | ||||
|                      unitprice: item.unit_price | ||||
|                  }) | ||||
|              )]]}; | ||||
|  | ||||
|          if (this.valid) { | ||||
|            this.api.createPurchase(this.purchase) | ||||
|              this.api.createPurchase(tryton_sale) | ||||
|                .then(data => { | ||||
|                  console.log('Compra enviada:', data); | ||||
|                  this.$router.push({ | ||||
|   | ||||
| @@ -39,26 +39,8 @@ | ||||
|           {{ currencyFormat(calculateSubtotal(item.unit_price, item.quantity)) }} | ||||
|         </template> | ||||
|       </v-data-table-virtual> | ||||
|       <v-alert type="info" class="my-4"> | ||||
|         Recuerda adicionar a la planilla física lo siguiente | ||||
|         <v-data-table | ||||
|           :headers="headersTemplate" | ||||
|           :items="[purchase]" | ||||
|           item-key="id" | ||||
|           hide-default-footer | ||||
|         > | ||||
|           <template v-slot:item="{ item }"> | ||||
|             <tr> | ||||
|               <td>{{ item.id }}</td> | ||||
|               <td>{{ item.date }}</td> | ||||
|               <td><span v-if="item.customer">{{ item.customer.name }}</span></td> | ||||
|               <td><span v-if="item.lines">{{ currencyFormat(calculateTotal(item.lines)) }}</span></td> | ||||
|             </tr> | ||||
|           </template> | ||||
|         </v-data-table> | ||||
|       </v-alert> | ||||
|       <div class="text-center"> | ||||
|         <v-btn :to="{ path: '/' }" color="green">Ir al inicio</v-btn> | ||||
|         <v-btn :to="{ path: 'comprar' }" color="green">Ir a Comprar</v-btn> | ||||
|       </div> | ||||
|     </v-container> | ||||
|   </v-container> | ||||
| @@ -83,12 +65,6 @@ | ||||
|           { title: 'Cantidad', value: 'quantity' }, | ||||
|           { title: 'Subtotal', value: 'subtotal' }, | ||||
|         ], | ||||
|         headersTemplate: [ | ||||
|           {title: 'Compra', value: 'id'}, | ||||
|           {title: 'Fecha', value: 'date'}, | ||||
|           {title: 'Nombre', value: 'customer.name'}, | ||||
|           {title: 'Valor', value: ''}, | ||||
|         ], | ||||
|       }; | ||||
|     }, | ||||
|     created() { | ||||
|   | ||||
| @@ -14,6 +14,7 @@ import ApiImplementation from './services/api-implementation'; | ||||
| // Composables | ||||
| import { createApp } from 'vue' | ||||
|  | ||||
| process.env.API_IMPLEMENTATION = 'tryton'; | ||||
| let apiImplementation = new ApiImplementation(); | ||||
| const api = apiImplementation.getApi(); | ||||
|  | ||||
|   | ||||
| @@ -1,20 +0,0 @@ | ||||
| <template> | ||||
|   <div> | ||||
|     <CodeDialog @code-verified="(verified) => showComponent = verified"/> | ||||
|   </div> | ||||
|   <AdminPurchase v-if="showComponent"/> | ||||
| </template> | ||||
|  | ||||
| <script > | ||||
|   import CodeDialog from '../components/CodeDialog.vue' | ||||
|  | ||||
|   export default { | ||||
|     data() { | ||||
|       return { | ||||
|         showComponent: false, | ||||
|       } | ||||
|     }, | ||||
|     components: { CodeDialog }, | ||||
|     methods: {}, | ||||
|   } | ||||
| </script> | ||||
| @@ -1,79 +0,0 @@ | ||||
| <template> | ||||
|   <div> | ||||
|     <CodeDialog @code-verified="(verified) => showComponent = verified"/> | ||||
|   </div> | ||||
|   <v-container class="fill-height d-flex align-center justify-center"> | ||||
|     <v-card class="pa-6" max-width="600" elevation="4"> | ||||
|       <v-card-title class="text-h5 font-weight-bold text-center"> | ||||
|         🔄 Sincronización de Clientes | ||||
|       </v-card-title> | ||||
|  | ||||
|       <v-card-text> | ||||
|         <p> | ||||
|           Esta acción sincronizará los <strong>clientes</strong> desde el sistema | ||||
|           <strong>Tryton</strong> hacia la plataforma. | ||||
|         </p> | ||||
|         <v-alert type="warning" dense border="start" border-color="warning"> | ||||
|           <strong>Advertencia:</strong> Este proceso podría tardar varios minutos | ||||
|           y reemplazar datos existentes en la plataforma.   | ||||
|           Asegúrese de que la información en Tryton esté actualizada antes de | ||||
|           continuar. | ||||
|         </v-alert> | ||||
|         <p class="mt-4"> | ||||
|           Durante la sincronización, no se podrán modificar productos en la | ||||
|           plataforma para evitar conflictos. | ||||
|         </p> | ||||
|       </v-card-text> | ||||
|  | ||||
|       <v-card-actions class="justify-center"> | ||||
|         <v-btn color="primary" @click="startSync"> | ||||
|           Iniciar Sincronización | ||||
|         </v-btn> | ||||
|         <v-btn text @click="$router.push('/')"> | ||||
|           Cancelar | ||||
|         </v-btn> | ||||
|       </v-card-actions> | ||||
|     </v-card> | ||||
|  | ||||
|  | ||||
|     <v-data-table :items="checked_tryton_parties"></v-data-table> | ||||
|     <v-data-table :items="created_customers"></v-data-table> | ||||
|     <v-data-table :items="failed_parties"></v-data-table> | ||||
|     <v-data-table :items="untouched_customers"></v-data-table> | ||||
|   </v-container> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
|   import CodeDialog from '../components/CodeDialog.vue' | ||||
|   import { inject } from 'vue'; | ||||
|  | ||||
|   export default { | ||||
|     name: 'CustomersFromTryton', | ||||
|     data() { | ||||
|       return { | ||||
|         api: inject('api'), | ||||
|         checked_tryton_parties: [], | ||||
|         created_customers: [], | ||||
|         failed_parties: [], | ||||
|         untouched_customers: [], | ||||
|         updated_customers: [], | ||||
|       } | ||||
|     }, | ||||
|     methods: { | ||||
|       startSync() { | ||||
|         this.api.getCustomersFromTryton() | ||||
|           .then(response => { | ||||
|             // Manejar la respuesta exitosa | ||||
|             this.checked_tryton_parties = response.checked_tryton_parties.map(id => ({ id })); | ||||
|             this.created_customers = response.created_customers.map(id => ({ id })); | ||||
|             this.failed_parties = response.failed_parties.map(id => ({ id })); | ||||
|             this.untouched_customers = response.untouched_customers.map(id => ({ id })); | ||||
|           }) | ||||
|           .catch(error => { | ||||
|             // Manejar el error | ||||
|             console.error("Error al sincronizar clientes:", error); | ||||
|           }); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  </script> | ||||
| @@ -1,60 +0,0 @@ | ||||
| <template> | ||||
|   <div> | ||||
|     <CodeDialog @code-verified="(verified) => showComponent = verified"/> | ||||
|   </div> | ||||
|   <v-container class="fill-height d-flex align-center justify-center"> | ||||
|     <v-card class="pa-6" max-width="600" elevation="4"> | ||||
|       <v-card-title class="text-h5 font-weight-bold text-center"> | ||||
|         🔄 Sincronización de Productos | ||||
|       </v-card-title> | ||||
|  | ||||
|       <v-card-text> | ||||
|         <p> | ||||
|           Esta acción sincronizará los <strong>productos</strong> desde el sistema | ||||
|           <strong>Tryton</strong> hacia la plataforma. | ||||
|         </p> | ||||
|         <v-alert type="warning" dense border="start" border-color="warning"> | ||||
|           <strong>Advertencia:</strong> Este proceso podría tardar varios minutos | ||||
|           y reemplazar datos existentes en la plataforma.   | ||||
|           Asegúrese de que la información en Tryton esté actualizada antes de | ||||
|           continuar. | ||||
|         </v-alert> | ||||
|         <p class="mt-4"> | ||||
|           Durante la sincronización, no se podrán modificar productos en la | ||||
|           plataforma para evitar conflictos. | ||||
|         </p> | ||||
|       </v-card-text> | ||||
|  | ||||
|       <v-card-actions class="justify-center"> | ||||
|         <v-btn color="primary" @click="startSync"> | ||||
|           Iniciar Sincronización | ||||
|         </v-btn> | ||||
|         <v-btn text @click="$router.push('/')"> | ||||
|           Cancelar | ||||
|         </v-btn> | ||||
|       </v-card-actions> | ||||
|     </v-card> | ||||
|     <v-data-table :items="productos_tryton"></v-data-table> | ||||
|   </v-container> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
|   import CodeDialog from '../components/CodeDialog.vue' | ||||
|   import { inject } from 'vue'; | ||||
|  | ||||
|   export default { | ||||
|     name: 'ProductsFromTryton', | ||||
|     data() { | ||||
|       return { | ||||
|         api: inject('api'), | ||||
|         productos_tryton: [{}], | ||||
|         showComponent: false, | ||||
|       } | ||||
|     }, | ||||
|     methods: { | ||||
|       startSync() { | ||||
|         this.productos_tryton = this.api.getProductsFromTryton() | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  </script> | ||||
| @@ -1,63 +0,0 @@ | ||||
| <template> | ||||
|   <div> | ||||
|     <CodeDialog @code-verified="(verified) => showComponent = verified"/> | ||||
|   </div> | ||||
|   <v-container class="fill-height d-flex align-center justify-center"> | ||||
|     <v-card class="pa-6" max-width="600" elevation="4"> | ||||
|       <v-card-title class="text-h5 font-weight-bold text-center"> | ||||
|         🔄 Sincronización de Ventas | ||||
|       </v-card-title> | ||||
|  | ||||
|       <v-card-text> | ||||
|         <p> | ||||
|           Esta acción sincronizará las <strong>ventas</strong> desde el sistema | ||||
|           <strong>Tryton</strong> hacia la plataforma. | ||||
|         </p> | ||||
|         <v-alert type="warning" dense border="start" border-color="warning"> | ||||
|           <strong>Advertencia:</strong> Este proceso podría tardar varios minutos | ||||
|           y reemplazar datos existentes en la plataforma.   | ||||
|           Asegúrese de que la información en Tryton esté actualizada antes de | ||||
|           continuar. | ||||
|         </v-alert> | ||||
|       </v-card-text> | ||||
|  | ||||
|       <v-card-actions class="justify-center"> | ||||
|         <v-btn color="primary" @click="startSync"> | ||||
|           Iniciar Sincronización | ||||
|         </v-btn> | ||||
|         <v-btn text @click="$router.push('/')"> | ||||
|           Cancelar | ||||
|         </v-btn> | ||||
|       </v-card-actions> | ||||
|     </v-card> | ||||
|     <v-data-table :items="ventas_tryton_failed"></v-data-table> | ||||
|     <v-data-table :items="ventas_tryton_successful"></v-data-table> | ||||
|   </v-container> | ||||
| </template> | ||||
| <script> | ||||
|   import CodeDialog from '../components/CodeDialog.vue'; | ||||
|   import { inject } from 'vue'; | ||||
|  | ||||
|   export default { | ||||
|     name: 'SalesToTryton', | ||||
|     data() { | ||||
|       return { | ||||
|         api: inject('api'), | ||||
|         ventas_tryton: [], | ||||
|         showComponent: false, | ||||
|       } | ||||
|     }, | ||||
|     methods: { | ||||
|       startSync() { | ||||
|         this.api.sendSalesToTryton() | ||||
|           .then(response => { | ||||
|             this.ventas_tryton_failed = response.failed.map(id => ({ id })); | ||||
|             this.ventas_tryton_successful = response.successful.map(id => ({ id })); | ||||
|           }) | ||||
|           .catch(error => { | ||||
|             console.error("Error al sincronizar las ventas", error); | ||||
|           }); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| </script> | ||||
| @@ -1,19 +0,0 @@ | ||||
| <template> | ||||
|   <div> | ||||
|     <CodeDialog @code-verified="(verified) => showComponent = verified"/> | ||||
|   </div> | ||||
|   <ExportPurchasesForTryton v-if="showComponent" /> | ||||
| </template> | ||||
| <script> | ||||
|   import CodeDialog from '../components/CodeDialog.vue' | ||||
|  | ||||
|   export default { | ||||
|     data() { | ||||
|       return { | ||||
|         showComponent: false, | ||||
|       } | ||||
|     }, | ||||
|     components: { CodeDialog }, | ||||
|     methods: {}, | ||||
|   } | ||||
| </script> | ||||
| @@ -1,12 +1,20 @@ | ||||
| import DjangoApi from './django-api'; | ||||
| import TrytonApiClient from './tryton-api'; | ||||
| import Api from './api'; | ||||
|  | ||||
| class ApiImplementation { | ||||
|   constructor() { | ||||
|     const implementation = import.meta.env.VITE_API_IMPLEMENTATION; | ||||
|     const implementation = process.env.API_IMPLEMENTATION; | ||||
|     let apiImplementation; | ||||
|     if (implementation === 'django') { | ||||
|       apiImplementation = new DjangoApi(); | ||||
|     } else if (implementation === 'tryton'){ | ||||
|       const url = 'http://192.168.85.45:18030'; | ||||
|       const key = '9a9ffc430146447d81e6698240199a4be2b0e774cb18474999d0f60e33b5b1eb1cfff9d9141346a98844879b5a9e787489c891ddc8fb45cc903b7244cab64fb1'; | ||||
|       const db = 'tryton'; | ||||
|       const applicationName = 'sale_don_confiao'; | ||||
|       apiImplementation = new TrytonApiClient( | ||||
|         url, key, db, applicationName); | ||||
|     } else { | ||||
|       throw new Error("API implementation don't configured"); | ||||
|     } | ||||
|   | ||||
| @@ -46,22 +46,6 @@ class Api { | ||||
|   createCustomer(customer) { | ||||
|     return this.apiImplementation.createCustomer(customer); | ||||
|   } | ||||
|  | ||||
|   getCSVForTryton() { | ||||
|     return this.apiImplementation.getCSVForTryton(); | ||||
|   } | ||||
|  | ||||
|   getProductsFromTryton() { | ||||
|     return this.apiImplementation.getProductsFromTryton(); | ||||
|   } | ||||
|  | ||||
|   getCustomersFromTryton() { | ||||
|     return this.apiImplementation.getCustomersFromTryton(); | ||||
|   } | ||||
|  | ||||
|   sendSalesToTryton(){ | ||||
|     return this.apiImplementation.sendSalesToTryton(); | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default Api; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| class DjangoApi { | ||||
|   constructor() { | ||||
|     this.base = import.meta.env.VITE_DJANGO_BASE_URL; | ||||
|     this.base = 'http://localhost:7000'; | ||||
|   } | ||||
|  | ||||
|   getCustomers() { | ||||
| @@ -58,26 +58,6 @@ class DjangoApi { | ||||
|     return this.postRequest(url, customer); | ||||
|   } | ||||
|  | ||||
|   getCSVForTryton() { | ||||
|     const url = this.base + '/don_confiao/api/sales/for_tryton'; | ||||
|     return this.getRequest(url); | ||||
|   } | ||||
|  | ||||
|   getProductsFromTryton(){ | ||||
|     const url = this.base + '/don_confiao/api/importar_productos_de_tryton'; | ||||
|     return this.postRequest(url, {}); | ||||
|   } | ||||
|  | ||||
|   getCustomersFromTryton(){ | ||||
|     const url = this.base + '/don_confiao/api/importar_clientes_de_tryton'; | ||||
|     return this.postRequest(url, {}); | ||||
|   } | ||||
|  | ||||
|   sendSalesToTryton(){ | ||||
|     const url = this.base + '/don_confiao/api/enviar_ventas_a_tryton'; | ||||
|     return this.postRequest(url, {}); | ||||
|   } | ||||
|  | ||||
|   getRequest(url) { | ||||
|     return new Promise ((resolve, reject) => { | ||||
|       fetch(url) | ||||
|   | ||||
| @@ -46,8 +46,7 @@ export default defineConfig({ | ||||
|       vueTemplate: true, | ||||
|     }), | ||||
|   ], | ||||
|   define: { 'process.env': { | ||||
|   } }, | ||||
|   define: { 'process.env': {} }, | ||||
|   resolve: { | ||||
|     alias: { | ||||
|       '@': fileURLToPath(new URL('./src', import.meta.url)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user