Merge pull request '2223 Added pickup checkbox' (#251) from 2223-claim_action_pickup into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-by: Carlos Jimenez <carlosjr@verdnatura.es>
This commit is contained in:
Joan Sanchez 2020-05-14 15:41:30 +00:00
commit 6692ac2e02
15 changed files with 138 additions and 71 deletions

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn`.`claim`
ADD COLUMN `hasToPickUp` TINYINT(1) NOT NULL AFTER `ticketFk`;

View File

@ -613,7 +613,8 @@ export default {
firstLineDestination: 'vn-claim-action vn-tr:nth-child(1) vn-autocomplete[ng-model="saleClaimed.claimDestinationFk"]',
secondLineDestination: 'vn-claim-action vn-tr:nth-child(2) vn-autocomplete[ng-model="saleClaimed.claimDestinationFk"]',
firstDeleteLine: 'vn-claim-action vn-tr:nth-child(1) vn-icon-button[icon="delete"]',
isPaidWithManaCheckbox: 'vn-check[ng-model="$ctrl.claim.isChargedToMana"]'
isPaidWithManaCheckbox: 'vn-claim-action vn-check[ng-model="$ctrl.claim.isChargedToMana"]',
hasToPickUpCheckbox: 'vn-claim-action vn-check[ng-model="$ctrl.claim.hasToPickUp"]'
},
ordersIndex: {
searchResult: 'vn-order-index vn-card > vn-table > div > vn-tbody > a.vn-tr',

View File

@ -66,17 +66,25 @@ describe('Claim action path', () => {
});
it('should check the "is paid with mana" checkbox', async() => {
page.waitFor(3000); // can't use waitForNavigation here and needs more time than a single second to get the section ready...
await page.waitToClick(selectors.claimAction.isPaidWithManaCheckbox);
const message = await page.waitForSnackbar();
expect(message.type).toBe('success');
});
it('should confirm the "is paid with mana" checkbox is checked', async() => {
await page.reloadSection('claim.card.action');
const result = await page.checkboxState(selectors.claimAction.isPaidWithManaCheckbox);
it('should check the "Pick up" checkbox', async() => {
await page.waitToClick(selectors.claimAction.hasToPickUpCheckbox);
const message = await page.waitForSnackbar();
expect(result).toBe('checked');
expect(message.type).toBe('success');
});
it('should confirm the "is paid with mana" and "Pick up" checkbox are checked', async() => {
await page.reloadSection('claim.card.action');
const isPaidWithManaCheckbox = await page.checkboxState(selectors.claimAction.isPaidWithManaCheckbox);
const hasToPickUpCheckbox = await page.checkboxState(selectors.claimAction.hasToPickUpCheckbox);
expect(isPaidWithManaCheckbox).toBe('checked');
expect(hasToPickUpCheckbox).toBe('checked');
});
});

View File

@ -47,7 +47,7 @@ export default class Range extends FormInput {
}
onValueUpdate() {
this.change(this.input.value);
this.change(parseInt(this.input.value));
this.$.$applyAsync();
}
}

View File

@ -62,6 +62,7 @@
"MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} (#{{clientId}})]({{{url}}}) to *{{credit}} €*",
"MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} (#{{clientId}})]({{{url}}})",
"Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"Claim will be picked": "The product from the claim (#{{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked",
"This ticket is not an stowaway anymore": "The ticket id [#{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore",
"Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member",
"Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member",

View File

@ -125,6 +125,7 @@
"MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*",
"MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})",
"Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"Claim will be picked": "Se recogerá el género de la reclamación (#{{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*",
"This ticket is not an stowaway anymore": "El ticket id [#{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón",
"Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}",
"ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto",

View File

@ -3,21 +3,22 @@ module.exports = Self => {
description: 'Imports lines from claimBeginning to a new ticket with specific shipped, landed dates, agency and company',
accessType: 'WRITE',
accepts: [{
arg: 'params',
type: 'object',
http: {source: 'body'}
arg: 'id',
type: 'number',
description: 'The claim id',
http: {source: 'path'}
}],
returns: {
type: ['Object'],
root: true
},
http: {
path: `/regularizeClaim`,
path: `/:id/regularizeClaim`,
verb: 'POST'
}
});
Self.regularizeClaim = async(ctx, params) => {
Self.regularizeClaim = async(ctx, claimFk) => {
const models = Self.app.models;
const $t = ctx.req.__; // $translate
const resolvedState = 3;
@ -31,7 +32,7 @@ module.exports = Self => {
relation: 'claimDestination',
fields: ['addressFk']
},
where: {claimFk: params.claimFk}
where: {claimFk: claimFk}
}, options);
for (let i = 0; i < claimEnds.length; i++) {
@ -87,11 +88,32 @@ module.exports = Self => {
}, options);
}
let claim = await Self.findById(params.claimFk, null, options);
let claim = await Self.findById(claimFk, {
include: {
relation: 'client',
scope: {
include: {
relation: 'salesPerson'
}
}
}
}, options);
claim = await claim.updateAttributes({
claimStateFk: resolvedState
}, options);
// Get sales person from claim client
const salesPerson = claim.client().salesPerson();
if (salesPerson && claim.hasToPickUp) {
const origin = ctx.req.headers.origin;
const message = $t('Claim will be picked', {
claimId: claim.id,
clientName: claim.client().name,
claimUrl: `${origin}/#!/claim/${claim.id}/summary`
});
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
}
await tx.commit();
return claim;

View File

@ -33,7 +33,6 @@ describe('regularizeClaim()', () => {
return params.nickname;
};
let params = {claimFk: claimFk};
const chatModel = app.models.Chat;
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
@ -46,9 +45,9 @@ describe('regularizeClaim()', () => {
claimEnd.updateAttributes({claimDestinationFk: trashDestination});
});
let claimBefore = await app.models.Claim.findById(params.claimFk);
await app.models.Claim.regularizeClaim(ctx, params);
let claimAfter = await app.models.Claim.findById(params.claimFk);
let claimBefore = await app.models.Claim.findById(claimFk);
await app.models.Claim.regularizeClaim(ctx, claimFk);
let claimAfter = await app.models.Claim.findById(claimFk);
trashTicket = await app.models.Ticket.findOne({where: {addressFk: 12}});
@ -70,7 +69,6 @@ describe('regularizeClaim()', () => {
return params.nickname;
};
let params = {claimFk: claimFk};
const chatModel = app.models.Chat;
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
@ -78,9 +76,35 @@ describe('regularizeClaim()', () => {
claimEnd.updateAttributes({claimDestinationFk: okDestination});
});
await app.models.Claim.regularizeClaim(ctx, params);
await app.models.Claim.regularizeClaim(ctx, claimFk);
expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno');
expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(4);
});
it('should send a chat message to the salesPerson when claim isPickUp is enabled', async() => {
const ctx = {
req: {
accessToken: {userId: 18},
headers: {origin: 'http://localhost'}
}
};
ctx.req.__ = (value, params) => {
return params.nickname;
};
const chatModel = app.models.Chat;
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
claimEnds.forEach(async claimEnd => {
claimEnd.updateAttributes({claimDestinationFk: okDestination});
});
const claim = await app.models.Claim.findById(claimFk);
await claim.updateAttribute('hasToPickUp', true);
await app.models.Claim.regularizeClaim(ctx, claimFk);
expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno');
expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(5);
});
});

View File

@ -26,16 +26,16 @@ describe('Update Claim', () => {
});
it('should update the claim isChargedToMana attribute', async() => {
const data = {isChargedToMana: false};
const result = await app.models.Claim.updateClaimAction(newInstance.id, data);
const ctx = {args: {isChargedToMana: false}};
const result = await app.models.Claim.updateClaimAction(ctx, newInstance.id);
expect(result.id).toEqual(newInstance.id);
expect(result.isChargedToMana).toBeFalsy();
});
it('should update the claim responsibility attribute', async() => {
const data = {responsibility: 2};
const result = await app.models.Claim.updateClaimAction(newInstance.id, data);
const ctx = {args: {responsibility: 2}};
const result = await app.models.Claim.updateClaimAction(ctx, newInstance.id);
expect(result.id).toEqual(newInstance.id);
expect(result.responsibility).toEqual(2);

View File

@ -1,6 +1,6 @@
module.exports = Self => {
Self.remoteMethod('updateClaimAction', {
Self.remoteMethodCtx('updateClaimAction', {
description: 'Update a claim with privileges',
accessType: 'WRITE',
accepts: [{
@ -10,11 +10,17 @@ module.exports = Self => {
description: 'Claim id',
http: {source: 'path'}
}, {
arg: 'data',
type: 'object',
required: true,
description: 'Data to update on the model',
http: {source: 'body'}
arg: 'responsibility',
type: 'number',
required: false
}, {
arg: 'isChargedToMana',
type: 'boolean',
required: false
}, {
arg: 'hasToPickUp',
type: 'boolean',
required: false
}],
returns: {
type: 'object',
@ -22,22 +28,16 @@ module.exports = Self => {
},
http: {
path: `/:id/updateClaimAction`,
verb: 'post'
verb: 'patch'
}
});
Self.updateClaimAction = async(id, data) => {
let models = Self.app.models;
Self.updateClaimAction = async(ctx, id) => {
const models = Self.app.models;
const claim = await models.Claim.findById(id);
const args = ctx.args;
delete args.ctx;
let claim = await models.Claim.findById(id);
let updatedData = {};
if (data.hasOwnProperty('responsibility'))
updatedData.responsibility = data.responsibility;
if (data.hasOwnProperty('isChargedToMana'))
updatedData.isChargedToMana = data.isChargedToMana;
return await claim.updateAttributes(updatedData);
return await claim.updateAttributes(args);
};
};

View File

@ -13,7 +13,7 @@
"description": "Identifier"
},
"observation": {
"type": "String"
"type": "string"
},
"ticketCreated": {
"type": "date",
@ -26,16 +26,19 @@
"type": "date"
},
"responsibility": {
"type": "Number"
"type": "number"
},
"hasToPickUp": {
"type": "boolean"
},
"ticketFk": {
"type": "Number"
"type": "number"
},
"claimStateFk": {
"type": "Number"
"type": "number"
},
"workerFk": {
"type": "Number"
"type": "number"
}
},
"relations": {

View File

@ -42,15 +42,18 @@
max="$ctrl.maxResponsibility"
min="1"
step="1"
vn-acl="salesAssistant"
on-change="$ctrl.saveResponsibility(value)">
on-change="$ctrl.save({responsibility: value})">
</vn-range>
</vn-tool-bar>
<vn-check vn-one class="vn-mr-md"
label="Pick up"
ng-model="$ctrl.claim.hasToPickUp"
on-change="$ctrl.save({hasToPickUp: value})">
</vn-check>
<vn-check vn-one
label="Is paid with mana"
ng-model="$ctrl.claim.isChargedToMana"
vn-acl="salesAssistant"
on-change="$ctrl.saveMana(value)">
on-change="$ctrl.save({isChargedToMana: value})">
</vn-check>
</section>

View File

@ -116,9 +116,8 @@ export default class Controller extends Section {
}
regularize() {
let data = {claimFk: this.$params.id};
let query = `Claims/regularizeClaim`;
return this.$http.post(query, data).then(() => {
const query = `Claims/${this.$params.id}/regularizeClaim`;
return this.$http.post(query).then(() => {
if (this.claim.responsibility >= Math.ceil(this.maxResponsibility) / 2)
this.$.updateGreuge.show();
else
@ -172,25 +171,15 @@ export default class Controller extends Section {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
}
// Item Descriptor
showDescriptor(event, itemFk) {
this.$.descriptor.itemFk = itemFk;
this.$.descriptor.parent = event.target;
this.$.descriptor.show();
}
saveResponsibility(value) {
let query = `Claims/${this.$params.id}/updateClaimAction`;
this.$http.post(query, {responsibility: value}).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
saveMana(value) {
let query = `Claims/${this.$params.id}/updateClaimAction`;
this.$http.post(query, {isChargedToMana: value}).then(() => {
save(data) {
const query = `Claims/${this.$params.id}/updateClaimAction`;
this.$http.patch(query, data).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}

View File

@ -143,8 +143,7 @@ describe('claim', () => {
jest.spyOn(controller.card, 'reload');
jest.spyOn(controller.vnApp, 'showSuccess');
let data = {claimFk: $state.params.id};
$httpBackend.expect('POST', `Claims/regularizeClaim`, data).respond({});
$httpBackend.expect('POST', `Claims/1/regularizeClaim`).respond({});
controller.regularize();
$httpBackend.flush();
@ -153,6 +152,19 @@ describe('claim', () => {
});
});
describe('save()', () => {
it('should perform a patch query and show a success message', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
const data = {hasToPickUp: true};
$httpBackend.expect('PATCH', `Claims/1/updateClaimAction`, data).respond({});
controller.save(data);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
describe('onUpdateGreugeResponse()', () => {
const greugeTypeId = 7;
const freightPickUpPrice = 11;

View File

@ -10,3 +10,4 @@ Do you want to insert greuges?: Desea insertar greuges?
Insert greuges on client card: Insertar greuges en la ficha del cliente
Greuge inserted: Greuge insertado
ClaimGreugeDescription: Reclamación id {{claimId}}
Pick up: Recoger