#367 addressesPropagateRe desmarcar campo hasToInvoiceByAddress cr JOAN
This commit is contained in:
parent
9982b9df11
commit
f417dba3ba
|
@ -17,6 +17,7 @@ describe('Client', () => {
|
|||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
$scope = $rootScope.$new();
|
||||
controller = $componentController('vnClientFiscalData', {$scope: $scope});
|
||||
controller.card = {reload: () => {}};
|
||||
}));
|
||||
|
||||
describe('returnDialogEt()', () => {
|
||||
|
|
|
@ -42,8 +42,10 @@ export default class Controller {
|
|||
if (response === 'ACCEPT') {
|
||||
this.$http.patch(`/client/api/Clients/${this.client.id}/addressesPropagateRe`, {isEqualizated: this.client.isEqualizated}).then(
|
||||
res => {
|
||||
if (res.data)
|
||||
if (res.data) {
|
||||
this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded'));
|
||||
this.card.reload();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -54,6 +56,7 @@ Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
|
|||
ngModule.component('vnClientFiscalData', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
require: {card: '^vnClientCard'},
|
||||
bindings: {
|
||||
client: '<'
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Yes, notify: Sí, notificar
|
||||
You changed the equalization tax: Has cambiado el recargo de equivalencia
|
||||
Do you want to spread the change: ¿Deseas propagar el cambio a sus consignatarios?
|
||||
Do you want to spread the change?: ¿Deseas propagar el cambio a sus consignatarios?
|
||||
Frozen: Congelado
|
|
@ -29,15 +29,12 @@ module.exports = function(Client) {
|
|||
}
|
||||
});
|
||||
|
||||
Client.addressesPropagateRe = (id, data, callback) => {
|
||||
Client.addressesPropagateRe = async (id, data) => {
|
||||
if (data.hasOwnProperty('isEqualizated')) {
|
||||
Client.app.models.Address.updateAll({clientFk: id}, data, (err, info) => {
|
||||
if (err)
|
||||
return callback(err, null);
|
||||
callback(null, true);
|
||||
});
|
||||
} else {
|
||||
callback(null, false);
|
||||
await Client.app.models.Address.updateAll({clientFk: id}, data);
|
||||
await Client.update({id: id}, {hasToInvoiceByAddress: false});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
const app = require('../../../../../client/server/server');
|
||||
const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors;
|
||||
const restoreFixtures = require('../../../../../../services/db/testing_fixtures');
|
||||
|
||||
describe('Client addressesPropagateRe', () => {
|
||||
let sqlStatements = {deletes: ``, inserts: ``, updates:
|
||||
`UPDATE vn.address SET isEqualizated = 0 WHERE clientFk = 101;`
|
||||
`UPDATE vn.address SET isEqualizated = FALSE WHERE clientFk = 101;
|
||||
UPDATE vn.client SET hasToInvoiceByAddress = TRUE WHERE id = 101;`
|
||||
};
|
||||
beforeEach(() => {
|
||||
restoreFixtures(sqlStatements);
|
||||
|
@ -14,31 +14,26 @@ describe('Client addressesPropagateRe', () => {
|
|||
restoreFixtures(sqlStatements);
|
||||
});
|
||||
|
||||
it('should propagate the isEqualizated on both addresses of Mr Wayne', done => {
|
||||
it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async () => {
|
||||
let id = 101;
|
||||
let data = {
|
||||
isEqualizated: true
|
||||
};
|
||||
|
||||
let callback = (error, result) => {
|
||||
if (error) return catchErrors(done)(error);
|
||||
let resultAddress = await app.models.Address.find({where: {clientFk: id}});
|
||||
let resultClient = await app.models.Client.find({where: {id: id}});
|
||||
|
||||
expect(result).toBe(true);
|
||||
app.models.Address.find({where: {clientFk: id}})
|
||||
.then(result => {
|
||||
expect(result[0].isEqualizated).toBeTruthy();
|
||||
expect(result[1].isEqualizated).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
};
|
||||
app.models.Address.find({where: {clientFk: id}})
|
||||
.then(result => {
|
||||
expect(result[0].isEqualizated).toBeFalsy();
|
||||
expect(result[1].isEqualizated).toBeFalsy();
|
||||
})
|
||||
.then(() => {
|
||||
app.models.Client.addressesPropagateRe(id, data, callback);
|
||||
})
|
||||
.catch(catchErrors(done));
|
||||
expect(resultAddress[0].isEqualizated).toBeFalsy();
|
||||
expect(resultAddress[1].isEqualizated).toBeFalsy();
|
||||
expect(resultClient[0].hasToInvoiceByAddress).toBeTruthy();
|
||||
|
||||
await app.models.Client.addressesPropagateRe(id, data);
|
||||
|
||||
resultAddress = await app.models.Address.find({where: {clientFk: id}});
|
||||
resultClient = await app.models.Client.find({where: {id: id}});
|
||||
|
||||
expect(resultAddress[0].isEqualizated).toBeTruthy();
|
||||
expect(resultAddress[1].isEqualizated).toBeTruthy();
|
||||
expect(resultClient[0].hasToInvoiceByAddress).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue