Compare commits
	
		
			3 Commits
		
	
	
		
			main
			...
			TrytonApiC
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 03d38f0b64 | |||
| a097bf7141 | |||
| eb75a13857 | 
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,5 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "don-confiao", |   "name": "don-confiao", | ||||||
|  |   "type": "module", | ||||||
|   "version": "0.0.0", |   "version": "0.0.0", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|     "dev": "vite --host 0.0.0.0", |     "dev": "vite --host 0.0.0.0", | ||||||
| @@ -10,6 +11,7 @@ | |||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "@mdi/font": "7.4.47", |     "@mdi/font": "7.4.47", | ||||||
|     "core-js": "^3.37.1", |     "core-js": "^3.37.1", | ||||||
|  |     "cors": "^2.8.5", | ||||||
|     "roboto-fontface": "*", |     "roboto-fontface": "*", | ||||||
|     "vee-validate": "^4.14.6", |     "vee-validate": "^4.14.6", | ||||||
|     "vue": "^3.4.31", |     "vue": "^3.4.31", | ||||||
|   | |||||||
| @@ -276,7 +276,14 @@ | |||||||
|      fetchProducts() { |      fetchProducts() { | ||||||
|        this.api.getProducts() |        this.api.getProducts() | ||||||
|            .then(data => { |            .then(data => { | ||||||
|              this.products = data; |                console.log(data) | ||||||
|  |                const transformed_products = data.map(item => ({ | ||||||
|  |                    name: item.name, | ||||||
|  |                    price: item["template."]?.list_price?.decimal, | ||||||
|  |                    measuring_unit: item["default_uom"]?.name, | ||||||
|  |                    categories: [] | ||||||
|  |                })); | ||||||
|  |                this.products = transformed_products; | ||||||
|            }) |            }) | ||||||
|            .catch(error => { |            .catch(error => { | ||||||
|              console.error(error); |              console.error(error); | ||||||
|   | |||||||
| @@ -13,12 +13,20 @@ import ApiImplementation from './services/api-implementation'; | |||||||
|  |  | ||||||
| // Composables | // Composables | ||||||
| import { createApp } from 'vue' | import { createApp } from 'vue' | ||||||
|  | import cors from 'cors'; | ||||||
|  |  | ||||||
| process.env.API_IMPLEMENTATION = 'django'; | // const cors = require('cors'); | ||||||
|  |  | ||||||
|  | process.env.API_IMPLEMENTATION = 'tryton'; | ||||||
|  | // process.env.API_IMPLEMENTATION = 'django'; | ||||||
| let apiImplementation = new ApiImplementation(); | let apiImplementation = new ApiImplementation(); | ||||||
| const api = apiImplementation.getApi(); | const api = apiImplementation.getApi(); | ||||||
|  |  | ||||||
| const app = createApp(App); | const app = createApp(App); | ||||||
|  | // app.use(cors({ | ||||||
|  | //   origin: '*', // Permitir todas las solicitudes de origen | ||||||
|  | //   exposedHeaders: ['X-Custom-Header', 'Content-Length'], // Exponer headers específicos | ||||||
|  | // })); | ||||||
| app.provide('api', api); | app.provide('api', api); | ||||||
|  |  | ||||||
| registerPlugins(app) | registerPlugins(app) | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| import DjangoApi from './django-api'; | import DjangoApi from './django-api'; | ||||||
|  | import TrytonApiClient from './tryton-api'; | ||||||
| import Api from './api'; | import Api from './api'; | ||||||
|  |  | ||||||
| class ApiImplementation { | class ApiImplementation { | ||||||
| @@ -7,6 +8,13 @@ class ApiImplementation { | |||||||
|     let apiImplementation; |     let apiImplementation; | ||||||
|     if (implementation === 'django') { |     if (implementation === 'django') { | ||||||
|       apiImplementation = new DjangoApi(); |       apiImplementation = new DjangoApi(); | ||||||
|  |     } else if (implementation === 'tryton'){ | ||||||
|  |       const url = 'http://192.168.0.114:18030'; | ||||||
|  |       const key = '9a9ffc430146447d81e6698240199a4be2b0e774cb18474999d0f60e33b5b1eb1cfff9d9141346a98844879b5a9e787489c891ddc8fb45cc903b7244cab64fb1'; | ||||||
|  |       const db = 'tryton'; | ||||||
|  |       const applicationName = 'sale_don_confiao'; | ||||||
|  |       apiImplementation = new TrytonApiClient( | ||||||
|  |         url, key, db, applicationName); | ||||||
|     } else { |     } else { | ||||||
|       throw new Error("API implementation don't configured"); |       throw new Error("API implementation don't configured"); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -11,6 +11,7 @@ class Api { | |||||||
|     return this.apiImplementation.getProducts(); |     return this.apiImplementation.getProducts(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   getPaymentMethods() { |   getPaymentMethods() { | ||||||
|     return this.apiImplementation.getPaymentMethods(); |     return this.apiImplementation.getPaymentMethods(); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -0,0 +1,98 @@ | |||||||
|  | class TrytonApiClient { | ||||||
|  |   constructor(url, key, db, applicationName) { | ||||||
|  |     this.baseUrl = `${url}/${db}/${applicationName}`; | ||||||
|  |     this.headers = { | ||||||
|  |       'Authorization': `Bearer ${key}`, | ||||||
|  |       'Content-Type': 'application/json', | ||||||
|  |       mode: 'cors' | ||||||
|  |     }; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getCustomers() { | ||||||
|  |     const url = this.baseUrl + '/parties'; | ||||||
|  |     const customers = this.getRequest(url); | ||||||
|  |     return customers; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getProducts() { | ||||||
|  |     const url = this.baseUrl + '/products' | ||||||
|  |     const products = this.getRequest(url); | ||||||
|  |     return products; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getPaymentMethods() { | ||||||
|  |     const url = '/don_confiao/payment_methods/all/select_format'; | ||||||
|  |     return this.getRequest(url); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getSummaryPurchase(purchaseId) { | ||||||
|  |     const url = `/don_confiao/resumen_compra_json/${purchaseId}`; | ||||||
|  |     return this.getRequest(url); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getPurchasesForReconciliation() { | ||||||
|  |     const url = '/don_confiao/purchases/for_reconciliation'; | ||||||
|  |     return this.getRequest(url); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   isValidAdminCode(code) { | ||||||
|  |     const url = `/don_confiao/api/admin_code/validate/${code}` | ||||||
|  |     return this.getRequest(url) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   createPurchase(purchase) { | ||||||
|  |     const url = '/don_confiao/api/sales/'; | ||||||
|  |     return this.postRequest(url, purchase); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   createReconciliationJar(reconciliation) { | ||||||
|  |     const url = '/don_confiao/reconciliate_jar'; | ||||||
|  |     return this.postRequest(url, reconciliation); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   createCustomer(customer) { | ||||||
|  |     const url = '/don_confiao/api/customers/'; | ||||||
|  |     return this.postRequest(url, customer); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getRequest(url) { | ||||||
|  |     return new Promise ((resolve, reject) => { | ||||||
|  |       fetch(url, { | ||||||
|  |         method: 'GET', | ||||||
|  |         headers: this.headers | ||||||
|  |       }).then(response => response.json()) | ||||||
|  |         .then(data => { | ||||||
|  |           resolve(data); | ||||||
|  |         }) | ||||||
|  |         .catch(error => { | ||||||
|  |           reject(error); | ||||||
|  |         }); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   postRequest(url, content) { | ||||||
|  |     return new Promise((resolve, reject) => { | ||||||
|  |       fetch(url, { | ||||||
|  |         method: 'POST', | ||||||
|  |         headers: this.headers, | ||||||
|  |         body: JSON.stringify(content) | ||||||
|  |       }) | ||||||
|  |         .then(response => { | ||||||
|  |           if (!response.ok) { | ||||||
|  |             reject(new Error(`Error ${response.status}: ${response.statusText}`)); | ||||||
|  |           } else { | ||||||
|  |             response.json().then(data => { | ||||||
|  |               if (!data) { | ||||||
|  |                 reject(new Error('La respuesta no es un JSON válido')); | ||||||
|  |               } else { | ||||||
|  |                 resolve(data); | ||||||
|  |               } | ||||||
|  |             }); | ||||||
|  |           } | ||||||
|  |         }) | ||||||
|  |         .catch(error => reject(error)); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export default TrytonApiClient; | ||||||
| @@ -11,6 +11,8 @@ import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify' | |||||||
| import { defineConfig } from 'vite' | import { defineConfig } from 'vite' | ||||||
| import { fileURLToPath, URL } from 'node:url' | import { fileURLToPath, URL } from 'node:url' | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| // https://vitejs.dev/config/ | // https://vitejs.dev/config/ | ||||||
| export default defineConfig({ | export default defineConfig({ | ||||||
|   plugins: [ |   plugins: [ | ||||||
| @@ -63,6 +65,19 @@ export default defineConfig({ | |||||||
|   }, |   }, | ||||||
|   server: { |   server: { | ||||||
|     port: 3000, |     port: 3000, | ||||||
|  |     cors: { | ||||||
|  |       origin: '*', | ||||||
|  |       methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], | ||||||
|  |       allowedHeaders: ['Content-Type', 'Authorization'], | ||||||
|  |     }, | ||||||
|  |     proxy: { | ||||||
|  |       '/sale_don_confiao': { | ||||||
|  |         target: "http://127.0.0.1:8000/tryton/sale_don_confiao", // Cambia esto a la URL de tu API | ||||||
|  |         changeOrigin: true, | ||||||
|  |         rewrite: (path) => path.replace(/^\/sale_don_confiao/, '/tryton/sale_don_confiao'), // Opcional: reescribe la ruta | ||||||
|  |         ws: true | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|   }, |   }, | ||||||
|   build: { |   build: { | ||||||
|     outDir: '../../static/frontend/',  |     outDir: '../../static/frontend/',  | ||||||
|   | |||||||
| @@ -28,6 +28,10 @@ DEBUG = True | |||||||
| ALLOWED_HOSTS = [] | ALLOWED_HOSTS = [] | ||||||
|  |  | ||||||
|  |  | ||||||
|  | CORS_ALLOWED_ORIGINS = [ | ||||||
|  |     "http://localhost:8000", | ||||||
|  | ] | ||||||
|  |  | ||||||
| # Application definition | # Application definition | ||||||
|  |  | ||||||
| INSTALLED_APPS = [ | INSTALLED_APPS = [ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user