Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
0f795102cb
|
@ -16,53 +16,48 @@ describe('Client', () => {
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve());
|
$scope.watcher = {
|
||||||
$scope.watcher = {submit};
|
submit: () => {
|
||||||
|
return {
|
||||||
|
then: callback => {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
$httpBackend.get = jasmine.createSpy('get').and.returnValue(Promise.resolve());
|
$httpBackend.get = jasmine.createSpy('get').and.returnValue(Promise.resolve());
|
||||||
controller = $componentController('vnClientBillingData', {$scope: $scope}, {$http: $httpBackend});
|
controller = $componentController('vnClientBillingData', {$scope: $scope}, {$http: $httpBackend});
|
||||||
|
controller.client = {id: 101, name: 'Client name', payMethodFk: 4};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('copyData()', () => {
|
describe('client()', () => {
|
||||||
it(`should define billData using client's data`, () => {
|
it(`should call setter client`, () => {
|
||||||
controller.client = {
|
expect(controller.orgData).toEqual(controller.client);
|
||||||
dueDay: 0,
|
|
||||||
iban: null,
|
|
||||||
payMethodFk: 1
|
|
||||||
};
|
|
||||||
controller.billData = {};
|
|
||||||
controller.copyData(controller.client);
|
|
||||||
|
|
||||||
expect(controller.billData).toEqual(controller.client);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('submit()', () => {
|
describe('hasPaymethodChanged()', () => {
|
||||||
it(`should call submit() on the watcher then receive a callback`, done => {
|
it(`should call hasPaymethodChanged() and return true if there are changes on payMethod data`, () => {
|
||||||
spyOn(controller, 'checkPaymentChanges');
|
controller.client.payMethodFk = 5;
|
||||||
controller.submit()
|
|
||||||
.then(() => {
|
expect(controller.hasPaymethodChanged()).toBeTruthy();
|
||||||
expect(controller.$.watcher.submit).toHaveBeenCalledWith();
|
|
||||||
expect(controller.checkPaymentChanges).toHaveBeenCalledWith();
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`should call hasPaymethodChanged() and return false if there are no changes on payMethod data`, () => {
|
||||||
|
controller.client.payMethodFk = 4;
|
||||||
|
|
||||||
|
expect(controller.hasPaymethodChanged()).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('checkPaymentChanges()', () => {
|
describe('onSubmit()', () => {
|
||||||
it(`should not call sendMail.show() if there are no changes on billing data`, () => {
|
it(`should call notifyChanges() if there are changes on payMethod data`, () => {
|
||||||
controller.billData = {marvelHero: 'Silver Surfer'};
|
spyOn(controller, 'notifyChanges');
|
||||||
controller.client = {marvelHero: 'Silver Surfer'};
|
controller.client.payMethodFk = 5;
|
||||||
controller.checkPaymentChanges();
|
controller.onSubmit();
|
||||||
|
|
||||||
expect(controller.$http.get).not.toHaveBeenCalled();
|
expect(controller.hasPaymethodChanged()).toBeTruthy();
|
||||||
});
|
expect(controller.notifyChanges).toHaveBeenCalledWith();
|
||||||
|
|
||||||
it(`should call sendMail.show() if there are changes on billing data object`, () => {
|
|
||||||
controller.billData = {id: '123', marvelHero: 'Silver Surfer'};
|
|
||||||
controller.client = {id: '123', marvelHero: 'Spider-Man'};
|
|
||||||
controller.checkPaymentChanges();
|
|
||||||
|
|
||||||
expect(controller.$http.get).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
form="form"
|
form="form"
|
||||||
save="patch">
|
save="patch">
|
||||||
</vn-watcher>
|
</vn-watcher>
|
||||||
<form name="form" ng-submit="$ctrl.submit()">
|
<form name="form" ng-submit="$ctrl.onSubmit()">
|
||||||
<vn-card pad-large>
|
<vn-card pad-large>
|
||||||
<vn-title>Pay method</vn-title>
|
<vn-title>Pay method</vn-title>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
|
@ -36,8 +36,8 @@
|
||||||
<vn-horizontal pad-small-v>
|
<vn-horizontal pad-small-v>
|
||||||
<vn-one>
|
<vn-one>
|
||||||
<vn-check
|
<vn-check
|
||||||
label="Received core VNH"
|
label="Received LCR"
|
||||||
field="$ctrl.client.hasCoreVnh"
|
field="$ctrl.client.hasLcr"
|
||||||
vn-acl="administrative, salesAssistant">
|
vn-acl="administrative, salesAssistant">
|
||||||
</vn-check>
|
</vn-check>
|
||||||
</vn-one>
|
</vn-one>
|
||||||
|
|
|
@ -2,47 +2,42 @@ import ngModule from '../module';
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller {
|
||||||
constructor($scope, $http, vnApp, $translate) {
|
constructor($scope, $http, vnApp, $translate) {
|
||||||
this.$ = $scope;
|
this.$scope = $scope;
|
||||||
this.$http = $http;
|
this.$http = $http;
|
||||||
this.vnApp = vnApp;
|
this.vnApp = vnApp;
|
||||||
this.translate = $translate;
|
this.translate = $translate;
|
||||||
this.billData = {};
|
|
||||||
this.copyData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$onChanges() {
|
set client(value) {
|
||||||
this.copyData();
|
this._client = value;
|
||||||
|
|
||||||
|
if (value)
|
||||||
|
this.orgData = Object.assign({}, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
copyData() {
|
get client() {
|
||||||
if (this.client) {
|
return this._client;
|
||||||
this.billData.payMethodFk = this.client.payMethodFk;
|
|
||||||
this.billData.iban = this.client.iban;
|
|
||||||
this.billData.dueDay = this.client.dueDay;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
onSubmit() {
|
||||||
return this.$.watcher.submit().then(
|
this.$scope.watcher.submit().then(() => {
|
||||||
() => this.checkPaymentChanges());
|
if (this.hasPaymethodChanged())
|
||||||
|
this.notifyChanges();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPaymentChanges() {
|
notifyChanges() {
|
||||||
let equals = true;
|
|
||||||
Object.keys(this.billData).forEach(
|
|
||||||
val => {
|
|
||||||
if (this.billData[val] !== this.client[val]) {
|
|
||||||
this.billData[val] = this.client[val];
|
|
||||||
equals = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!equals) {
|
|
||||||
this.$http.get(`/mailer/notification/payment-update/${this.client.id}`).then(
|
this.$http.get(`/mailer/notification/payment-update/${this.client.id}`).then(
|
||||||
() => this.vnApp.showMessage(this.translate.instant('Notification sent!'))
|
() => this.vnApp.showMessage(this.translate.instant('Notification sent!'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasPaymethodChanged() {
|
||||||
|
let payMethod = this.orgData.payMethodFk != this.client.payMethodFk;
|
||||||
|
let iban = this.orgData.iban != this.client.iban;
|
||||||
|
let dueDay = this.orgData.dueDay != this.client.dueDay;
|
||||||
|
|
||||||
|
return payMethod || iban || dueDay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
|
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
|
||||||
|
|
|
@ -9,7 +9,7 @@ Equivalent tax spreaded: Recargo de equivalencia propagado
|
||||||
Invoice by address: Facturar por consignatario
|
Invoice by address: Facturar por consignatario
|
||||||
Equalization tax: Recargo de equivalencia
|
Equalization tax: Recargo de equivalencia
|
||||||
Due day: Vencimiento
|
Due day: Vencimiento
|
||||||
Received core VNH: Recibido core VNH
|
Received LCR: Recibido LCR
|
||||||
Received core VNL: Recibido core VNL
|
Received core VNL: Recibido core VNL
|
||||||
Received B2B VNL: Recibido B2B VNL
|
Received B2B VNL: Recibido B2B VNL
|
||||||
Save: Guardar
|
Save: Guardar
|
|
@ -153,8 +153,7 @@
|
||||||
"menu": {
|
"menu": {
|
||||||
"description": "Tracking",
|
"description": "Tracking",
|
||||||
"icon": "remove_red_eye"
|
"icon": "remove_red_eye"
|
||||||
},
|
}
|
||||||
"acl": ["production"]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/edit",
|
"url": "/edit",
|
||||||
|
@ -162,15 +161,8 @@
|
||||||
"component": "vn-ticket-tracking-edit",
|
"component": "vn-ticket-tracking-edit",
|
||||||
"params": {
|
"params": {
|
||||||
"ticket": "$ctrl.ticket"
|
"ticket": "$ctrl.ticket"
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
"acl": ["production"]
|
||||||
"url": "/create",
|
|
||||||
"state": "ticket.card.tracking.create",
|
|
||||||
"component": "vn-ticket-tracking-create",
|
|
||||||
"params": {
|
|
||||||
"client": "$ctrl.client"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url" : "/sale-checked",
|
"url" : "/sale-checked",
|
||||||
|
|
|
@ -14,6 +14,7 @@ describe('Ticket', () => {
|
||||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
|
||||||
$componentController = _$componentController_;
|
$componentController = _$componentController_;
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
|
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
controller = $componentController('vnTicketCreateCard', {$scope: $scope});
|
controller = $componentController('vnTicketCreateCard', {$scope: $scope});
|
||||||
controller.item = {id: 3};
|
controller.item = {id: 3};
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
|
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
<a ui-sref="ticket.card.tracking.edit" vn-bind="+" fixed-bottom-right>
|
<a ui-sref="ticket.card.tracking.edit" vn-bind="+" vn-visible-by="production" fixed-bottom-right>
|
||||||
<vn-float-button icon="add"></vn-float-button>
|
<vn-float-button icon="add"></vn-float-button>
|
||||||
</a>
|
</a>
|
|
@ -89,7 +89,9 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx) {
|
||||||
let changes = ctx.data || ctx.instance;
|
let changes = ctx.data || ctx.instance;
|
||||||
|
let orgData = ctx.currentInstance;
|
||||||
let finalState = getFinalState(ctx);
|
let finalState = getFinalState(ctx);
|
||||||
|
let payMethodWithIban = 4;
|
||||||
|
|
||||||
if (changes.salesPerson === null) {
|
if (changes.salesPerson === null) {
|
||||||
changes.credit = 0;
|
changes.credit = 0;
|
||||||
|
@ -97,7 +99,10 @@ module.exports = Self => {
|
||||||
changes.payMethodFk = 5; // Credit card
|
changes.payMethodFk = 5; // Credit card
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes.payMethodFk !== undefined && changes.dueDay === undefined)
|
let payMethodFk = changes.payMethodFk || (orgData && orgData.payMethodFk);
|
||||||
|
let dueDay = changes.dueDay || (orgData && orgData.dueDay);
|
||||||
|
|
||||||
|
if (payMethodFk == payMethodWithIban && dueDay == 0)
|
||||||
changes.dueDay = 5;
|
changes.dueDay = 5;
|
||||||
|
|
||||||
if (isMultiple(ctx)) return;
|
if (isMultiple(ctx)) return;
|
||||||
|
|
Loading…
Reference in New Issue