#855 consignatario validacion back recargo

This commit is contained in:
Javi Gallego 2018-11-22 14:12:52 +01:00
parent 80bdc402db
commit a096490d1c
1 changed files with 18 additions and 3 deletions

View File

@ -1,15 +1,30 @@
var UserError = require('../helpers').UserError;
var getFinalState = require('../helpers').getFinalState;
var isMultiple = require('../helpers').isMultiple;
let UserError = require('../helpers').UserError;
let getFinalState = require('../helpers').getFinalState;
let isMultiple = require('../helpers').isMultiple;
module.exports = Self => {
Self.validate('isDefaultAddress', isActive,
{message: 'Unable to default a disabled consignee'}
);
function isActive(err) {
if (!this.isActive && this.isDefaultAddress) err();
}
Self.validateAsync('isEqualizated', cannotHaveET, {
message: 'Cannot check Equalization Tax in this NIF/CIF'
});
async function cannotHaveET(err, done) {
let client = await Self.app.models.Client.findById(this.clientFk);
let tin = client.fi.toUpperCase();
let cannotHaveET = /^[A-B]/.test(tin);
if (cannotHaveET && this.isEqualizated)
err();
done();
}
Self.beforeRemote('findById', function(ctx, modelInstance, next) {
ctx.args.filter = {
include: [{