#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; let UserError = require('../helpers').UserError;
var getFinalState = require('../helpers').getFinalState; let getFinalState = require('../helpers').getFinalState;
var isMultiple = require('../helpers').isMultiple; let isMultiple = require('../helpers').isMultiple;
module.exports = Self => { module.exports = Self => {
Self.validate('isDefaultAddress', isActive, Self.validate('isDefaultAddress', isActive,
{message: 'Unable to default a disabled consignee'} {message: 'Unable to default a disabled consignee'}
); );
function isActive(err) { function isActive(err) {
if (!this.isActive && this.isDefaultAddress) 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) { Self.beforeRemote('findById', function(ctx, modelInstance, next) {
ctx.args.filter = { ctx.args.filter = {
include: [{ include: [{