Compare commits

...

6 Commits

Author SHA1 Message Date
Javi Gallego 399612c9db minor bug
gitea/salix/pipeline/head This commit is unstable Details
2022-08-09 15:04:58 +02:00
Javi Gallego da7d9b48ea test
gitea/salix/pipeline/head This commit looks good Details
2022-08-08 17:27:28 +02:00
Javi Gallego 96808d0dcf permisos
gitea/salix/pipeline/head There was a failure building this commit Details
2022-08-05 16:47:06 +02:00
Javi Gallego 640b0d5cca Merge branch 'dev' into #2570-entry-add-recalc 2022-08-05 12:10:54 +02:00
Javi Gallego f6646d5793 Merge branch 'dev' into #2570-entry-add-recalc 2022-08-05 10:36:07 +02:00
Javi Gallego a446e0650f recalcPrices
gitea/salix/pipeline/head This commit looks good Details
2022-08-04 17:52:25 +02:00
8 changed files with 109 additions and 2 deletions

View File

@ -0,0 +1,2 @@
INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId)
VALUES ('Entry','recalcPrices','WRITE','ALLOW','ROLE','buyer');

View File

@ -232,5 +232,6 @@
"Fichadas impares": "Fichadas impares", "Fichadas impares": "Fichadas impares",
"Descanso diario 12h.": "Descanso diario 12h.", "Descanso diario 12h.": "Descanso diario 12h.",
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.", "Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
"Dirección incorrecta": "Dirección incorrecta" "Dirección incorrecta": "Dirección incorrecta",
"Prices recalculated": "Precios recalculados"
} }

View File

@ -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;
}
};
};

View File

@ -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;
}
});
});

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,13 @@
translate> translate>
Show entry report Show entry report
</vn-item> </vn-item>
<vn-item
ng-click="$ctrl.recalcPrices()"
translate
vn-acl="buyer"
vn-acl-action="remove">
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