Compare commits

...

3 Commits

Author SHA1 Message Date
03d38f0b64 Tryton Api Client Endpoints Tryton 2025-03-08 10:12:28 -05:00
a097bf7141 Fix(WIP): CORS 2025-01-18 20:18:06 -05:00
eb75a13857 Feat: Implementacion consumo de Api Tryton 2025-01-17 23:27:12 -05:00
9 changed files with 1445 additions and 830 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
{
"name": "don-confiao",
"type": "module",
"version": "0.0.0",
"scripts": {
"dev": "vite --host 0.0.0.0",
@ -10,6 +11,7 @@
"dependencies": {
"@mdi/font": "7.4.47",
"core-js": "^3.37.1",
"cors": "^2.8.5",
"roboto-fontface": "*",
"vee-validate": "^4.14.6",
"vue": "^3.4.31",

View File

@ -276,7 +276,14 @@
fetchProducts() {
this.api.getProducts()
.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 => {
console.error(error);

View File

@ -13,12 +13,20 @@ import ApiImplementation from './services/api-implementation';
// Composables
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();
const api = apiImplementation.getApi();
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);
registerPlugins(app)

View File

@ -1,4 +1,5 @@
import DjangoApi from './django-api';
import TrytonApiClient from './tryton-api';
import Api from './api';
class ApiImplementation {
@ -7,6 +8,13 @@ class ApiImplementation {
let apiImplementation;
if (implementation === 'django') {
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 {
throw new Error("API implementation don't configured");
}

View File

@ -11,6 +11,7 @@ class Api {
return this.apiImplementation.getProducts();
}
getPaymentMethods() {
return this.apiImplementation.getPaymentMethods();
}

View File

@ -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;

View File

@ -11,6 +11,8 @@ import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
import { defineConfig } from 'vite'
import { fileURLToPath, URL } from 'node:url'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
@ -63,6 +65,19 @@ export default defineConfig({
},
server: {
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: {
outDir: '../../static/frontend/',

View File

@ -28,6 +28,10 @@ DEBUG = True
ALLOWED_HOSTS = []
CORS_ALLOWED_ORIGINS = [
"http://localhost:8000",
]
# Application definition
INSTALLED_APPS = [