Compare commits
6 Commits
dev
...
#2570-entr
Author | SHA1 | Date |
---|---|---|
Javi Gallego | 399612c9db | |
Javi Gallego | da7d9b48ea | |
Javi Gallego | 96808d0dcf | |
Javi Gallego | 640b0d5cca | |
Javi Gallego | f6646d5793 | |
Javi Gallego | a446e0650f |
|
@ -0,0 +1,2 @@
|
|||
INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Entry','recalcPrices','WRITE','ALLOW','ROLE','buyer');
|
|
@ -232,5 +232,6 @@
|
|||
"Fichadas impares": "Fichadas impares",
|
||||
"Descanso diario 12h.": "Descanso diario 12h.",
|
||||
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
|
||||
"Dirección incorrecta": "Dirección incorrecta"
|
||||
"Dirección incorrecta": "Dirección incorrecta",
|
||||
"Prices recalculated": "Precios recalculados"
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
const loggable = require('vn-loopback/util/log');
|
||||
|
||||
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 = {};
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const $t = ctx.req.__;
|
||||
|
||||
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);
|
||||
*/
|
||||
const entryLog = await models.EntryLog.create({
|
||||
originFk: id,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'Entry',
|
||||
changedModelId: id,
|
||||
description: $t('Prices recalculated')
|
||||
}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return entryLog;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Entry recalcPrices()', () => {
|
||||
const entryId = 3;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 35},
|
||||
};
|
||||
|
||||
const ctx = {
|
||||
req: activeCtx
|
||||
};
|
||||
|
||||
it('should recalc the prices and log it', async() => {
|
||||
const tx = await models.Entry.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
|
||||
const result = await models.Entry.recalcPrices(ctx, entryId, options);
|
||||
expect(result.originFk).toBe(entryId);
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
|
@ -6,4 +6,5 @@ module.exports = Self => {
|
|||
require('../methods/entry/importBuys')(Self);
|
||||
require('../methods/entry/importBuysPreview')(Self);
|
||||
require('../methods/entry/lastItemBuys')(Self);
|
||||
require('../methods/entry/recalcPrices')(Self);
|
||||
};
|
||||
|
|
|
@ -8,6 +8,13 @@
|
|||
translate>
|
||||
Show entry report
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="$ctrl.recalcPrices()"
|
||||
translate
|
||||
vn-acl="buyer"
|
||||
vn-acl-action="remove">
|
||||
Recalc prices
|
||||
</vn-item>
|
||||
</slot-menu>
|
||||
<slot-body>
|
||||
<div class="attributes">
|
||||
|
|
|
@ -90,6 +90,12 @@ class Controller extends Descriptor {
|
|||
entryId: this.entry.id
|
||||
});
|
||||
}
|
||||
|
||||
recalcPrices() {
|
||||
this.$http.post(`Entries/${this.id}/recalcPrices`).then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Prices recalculated'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnEntryDescriptor', {
|
||||
|
|
|
@ -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
|
||||
Show entry report: Ver informe del pedido
|
||||
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
|
Loading…
Reference in New Issue