8 Commits

11 changed files with 85 additions and 43 deletions

8
package-lock.json generated
View File

@@ -31,7 +31,7 @@
"unplugin-fonts": "^1.1.1",
"unplugin-vue-components": "^0.27.2",
"unplugin-vue-router": "^0.10.0",
"vite": "^5.4.14",
"vite": "^5.3.3",
"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.14",
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.14.tgz",
"integrity": "sha512-EK5cY7Q1D8JNhSaPKVK4pwBFvaTmZxEnoKXLG/U9gmdDcihQGNzFlgIvaxezFR4glP1LsuiedwMBqCXH3wZccA==",
"version": "5.4.4",
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.4.tgz",
"integrity": "sha512-RHFCkULitycHVTtelJ6jQLd+KSAAzOgEYorV32R2q++M6COBjKJR6BxqClwp5sf0XaBDjVMuJ9wnNfyAJwjMkA==",
"devOptional": true,
"license": "MIT",
"dependencies": {

View File

@@ -31,7 +31,7 @@
"unplugin-fonts": "^1.1.1",
"unplugin-vue-components": "^0.27.2",
"unplugin-vue-router": "^0.10.0",
"vite": "^5.4.14",
"vite": "^5.3.3",
"vite-plugin-vue-layouts": "^0.11.0",
"vite-plugin-vuetify": "^2.0.3",
"vue-router": "^4.4.0"

View File

@@ -0,0 +1,39 @@
<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>

View File

@@ -31,6 +31,7 @@
{ 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: {

View File

@@ -276,14 +276,7 @@
fetchProducts() {
this.api.getProducts()
.then(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;
this.products = data;
})
.catch(error => {
console.error(error);
@@ -292,7 +285,7 @@
fetchPaymentMethods() {
this.api.getPaymentMethods()
.then(data => {
this.payment_methods = data[0]?.payment_methods;
this.payment_methods = data;
})
.catch(error => {
console.error(error);
@@ -316,21 +309,8 @@
},
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(tryton_sale)
this.api.createPurchase(this.purchase)
.then(data => {
console.log('Compra enviada:', data);
this.$router.push({

View File

@@ -14,7 +14,6 @@ import ApiImplementation from './services/api-implementation';
// Composables
import { createApp } from 'vue'
process.env.API_IMPLEMENTATION = 'tryton';
let apiImplementation = new ApiImplementation();
const api = apiImplementation.getApi();

View File

@@ -0,0 +1,19 @@
<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>

View File

@@ -1,5 +1,4 @@
import DjangoApi from './django-api';
import TrytonApiClient from './tryton-api';
import Api from './api';
class ApiImplementation {
@@ -8,13 +7,6 @@ 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");
}

View File

@@ -46,6 +46,10 @@ class Api {
createCustomer(customer) {
return this.apiImplementation.createCustomer(customer);
}
getCSVForTryton() {
return this.apiImplementation.getCSVForTryton();
}
}
export default Api;

View File

@@ -1,6 +1,6 @@
class DjangoApi {
constructor() {
this.base = 'http://localhost:7000';
this.base = process.env.DJANGO_BASE_URL;
}
getCustomers() {
@@ -58,6 +58,11 @@ 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)

View File

@@ -46,7 +46,10 @@ export default defineConfig({
vueTemplate: true,
}),
],
define: { 'process.env': {} },
define: { 'process.env': {
API_IMPLEMENTATION: 'django',
DJANGO_BASE_URL: 'http://localhost:7000'
} },
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))