recalcPrices
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2022-08-04 17:52:25 +02:00
parent eed0ac66c6
commit a446e0650f
5 changed files with 62 additions and 1 deletions

View File

@ -0,0 +1,47 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethodCtx('recalcPrices', {
description: 'Recalc all prices in the entry',
accessType: 'WRITE',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The entry id',
http: {source: 'path'}
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/:id/recalcPrices`,
verb: 'POST'
}
});
Self.recalcPrices = async(ctx, id, options) => {
let tx;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
await Self.rawSql('CALL vn.buy_recalcPricesByEntry(?)', [
id
], myOptions);
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -6,4 +6,5 @@ module.exports = Self => {
require('../methods/entry/importBuys')(Self); require('../methods/entry/importBuys')(Self);
require('../methods/entry/importBuysPreview')(Self); require('../methods/entry/importBuysPreview')(Self);
require('../methods/entry/lastItemBuys')(Self); require('../methods/entry/lastItemBuys')(Self);
require('../methods/entry/recalcPrices')(Self);
}; };

View File

@ -8,6 +8,11 @@
translate> translate>
Show entry report Show entry report
</vn-item> </vn-item>
<vn-item
ng-click="$ctrl.recalcPrices()"
translate>
Recalc prices
</vn-item>
</slot-menu> </slot-menu>
<slot-body> <slot-body>
<div class="attributes"> <div class="attributes">

View File

@ -90,6 +90,12 @@ class Controller extends Descriptor {
entryId: this.entry.id entryId: this.entry.id
}); });
} }
recalcPrices() {
this.$http.post(`Entries/${this.id}/recalcPrices`).then(() => {
this.vnApp.showSuccess(this.$t('Prices recalculated!'));
});
}
} }
ngModule.vnComponent('vnEntryDescriptor', { ngModule.vnComponent('vnEntryDescriptor', {

View File

@ -4,4 +4,6 @@ All travels with current agency: Todos los envios con la agencia actual
All entries with current supplier: Todas las entradas con el proveedor actual All entries with current supplier: Todas las entradas con el proveedor actual
Show entry report: Ver informe del pedido Show entry report: Ver informe del pedido
Is inventory entry: Es una entrada de inventario Is inventory entry: Es una entrada de inventario
Is virtual entry: Es una redada Is virtual entry: Es una redada
Recalc prices: Recalcular precios
Prices recalculated: Precios recalculados