Compare commits
1 Commits
0.1.3
...
TrytonApiC
| Author | SHA1 | Date | |
|---|---|---|---|
| efb33ef011 |
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,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>
|
||||
@@ -31,7 +31,6 @@
|
||||
{ title: 'Comprar', route:'/comprar'},
|
||||
{ title: 'Cuadrar tarro', route: '/cuadrar_tarro'},
|
||||
{ title: 'Cuadres de tarro', route: '/cuadres_de_tarro'},
|
||||
{ title: 'CSV Tryton', route: '/ventas_para_tryton'},
|
||||
],
|
||||
}),
|
||||
watch: {
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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,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,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.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,10 +46,6 @@ class Api {
|
||||
createCustomer(customer) {
|
||||
return this.apiImplementation.createCustomer(customer);
|
||||
}
|
||||
|
||||
getCSVForTryton() {
|
||||
return this.apiImplementation.getCSVForTryton();
|
||||
}
|
||||
}
|
||||
|
||||
export default Api;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class DjangoApi {
|
||||
constructor() {
|
||||
this.base = process.env.DJANGO_BASE_URL;
|
||||
this.base = 'http://localhost:7000';
|
||||
}
|
||||
|
||||
getCustomers() {
|
||||
@@ -58,11 +58,6 @@ class DjangoApi {
|
||||
return this.postRequest(url, customer);
|
||||
}
|
||||
|
||||
getCSVForTryton() {
|
||||
const url = this.base + '/don_confiao/api/sales/for_tryton';
|
||||
return this.getRequest(url);
|
||||
}
|
||||
|
||||
getRequest(url) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
fetch(url)
|
||||
|
||||
@@ -46,10 +46,7 @@ export default defineConfig({
|
||||
vueTemplate: true,
|
||||
}),
|
||||
],
|
||||
define: { 'process.env': {
|
||||
API_IMPLEMENTATION: 'django',
|
||||
DJANGO_BASE_URL: 'http://localhost:7000'
|
||||
} },
|
||||
define: { 'process.env': {} },
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
|
||||
Reference in New Issue
Block a user