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

View File

@@ -31,7 +31,7 @@
"unplugin-fonts": "^1.1.1", "unplugin-fonts": "^1.1.1",
"unplugin-vue-components": "^0.27.2", "unplugin-vue-components": "^0.27.2",
"unplugin-vue-router": "^0.10.0", "unplugin-vue-router": "^0.10.0",
"vite": "^5.4.14", "vite": "^5.3.3",
"vite-plugin-vue-layouts": "^0.11.0", "vite-plugin-vue-layouts": "^0.11.0",
"vite-plugin-vuetify": "^2.0.3", "vite-plugin-vuetify": "^2.0.3",
"vue-router": "^4.4.0" "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: 'Comprar', route:'/comprar'},
{ title: 'Cuadrar tarro', route: '/cuadrar_tarro'}, { title: 'Cuadrar tarro', route: '/cuadrar_tarro'},
{ title: 'Cuadres de tarro', route: '/cuadres_de_tarro'}, { title: 'Cuadres de tarro', route: '/cuadres_de_tarro'},
{ title: 'CSV Tryton', route: '/ventas_para_tryton'},
], ],
}), }),
watch: { watch: {

View File

@@ -256,10 +256,10 @@
}, },
onProductChange(index) { onProductChange(index) {
const selectedProductId = this.purchase.saleline_set[index].product; const selectedProductId = this.purchase.saleline_set[index].product;
const selectedProduct = this.products.find(p => p.id == selectedProductId); const selectedProduct = this.products.find(p => p.id == selectedProductId);
this.purchase.saleline_set[index].unit_price = selectedProduct.price; this.purchase.saleline_set[index].unit_price = selectedProduct.price;
this.purchase.saleline_set[index].measuring_unit = selectedProduct.measuring_unit; this.purchase.saleline_set[index].measuring_unit = selectedProduct.measuring_unit;
}, },
fetchClients() { fetchClients() {
this.api.getCustomers() this.api.getCustomers()
.then(data => { .then(data => {
@@ -276,14 +276,7 @@
fetchProducts() { fetchProducts() {
this.api.getProducts() this.api.getProducts()
.then(data => { .then(data => {
const transformed_products = data.map(item => ({ this.products = data;
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 => { .catch(error => {
console.error(error); console.error(error);
@@ -292,7 +285,7 @@
fetchPaymentMethods() { fetchPaymentMethods() {
this.api.getPaymentMethods() this.api.getPaymentMethods()
.then(data => { .then(data => {
this.payment_methods = data[0]?.payment_methods; this.payment_methods = data;
}) })
.catch(error => { .catch(error => {
console.error(error); console.error(error);
@@ -316,21 +309,8 @@
}, },
async submit() { async submit() {
this.$refs.purchase.validate(); 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) { if (this.valid) {
this.api.createPurchase(tryton_sale) this.api.createPurchase(this.purchase)
.then(data => { .then(data => {
console.log('Compra enviada:', data); console.log('Compra enviada:', data);
this.$router.push({ this.$router.push({

View File

@@ -14,7 +14,6 @@ import ApiImplementation from './services/api-implementation';
// Composables // Composables
import { createApp } from 'vue' import { createApp } from 'vue'
process.env.API_IMPLEMENTATION = 'tryton';
let apiImplementation = new ApiImplementation(); let apiImplementation = new ApiImplementation();
const api = apiImplementation.getApi(); 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 DjangoApi from './django-api';
import TrytonApiClient from './tryton-api';
import Api from './api'; import Api from './api';
class ApiImplementation { class ApiImplementation {
@@ -8,13 +7,6 @@ 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.85.45: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");
} }

View File

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

View File

@@ -1,6 +1,6 @@
class DjangoApi { class DjangoApi {
constructor() { constructor() {
this.base = 'http://localhost:7000'; this.base = process.env.DJANGO_BASE_URL;
} }
getCustomers() { getCustomers() {
@@ -58,6 +58,11 @@ class DjangoApi {
return this.postRequest(url, customer); return this.postRequest(url, customer);
} }
getCSVForTryton() {
const url = this.base + '/don_confiao/api/sales/for_tryton';
return this.getRequest(url);
}
getRequest(url) { getRequest(url) {
return new Promise ((resolve, reject) => { return new Promise ((resolve, reject) => {
fetch(url) fetch(url)

View File

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