1833 Claim action refactor #253

Merged
carlosjr merged 3 commits from 1833-claim_action_refactor into dev 2020-05-18 10:06:02 +00:00
8 changed files with 65 additions and 127 deletions

View File

@ -0,0 +1,17 @@
ALTER TABLE `vn`.`claimState`
DROP FOREIGN KEY `roleFgn`;
ALTER TABLE `vn`.`claimState`
ADD COLUMN `code` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NULL AFTER `id`,
CHANGE COLUMN `roleFk` `roleFk` INT(10) UNSIGNED NOT NULL DEFAULT '1' ;
ALTER TABLE `vn`.`claimState`
ADD CONSTRAINT `roleFgn`
FOREIGN KEY (`roleFk`)
REFERENCES `account`.`role` (`id`)
ON UPDATE CASCADE;
UPDATE `vn`.`claimState` SET `code` = 'pending' WHERE (`id` = '1');
UPDATE `vn`.`claimState` SET `code` = 'canceled' WHERE (`id` = '4');
UPDATE `vn`.`claimState` SET `code` = 'resolved' WHERE (`id` = '3');
UPDATE `vn`.`claimState` SET `code` = 'disputed' WHERE (`id` = '5');
UPDATE `vn`.`claimState` SET `code` = 'mana' WHERE (`id` = '6');
UPDATE `vn`.`claimState` SET `code` = 'managed' WHERE (`id` = '2');

View File

@ -1473,14 +1473,14 @@ INSERT INTO `vn`.`clientSample`(`id`, `clientFk`, `typeFk`, `created`, `workerFk
(4, 102, 2, CURDATE(), 18, 18, 567),
(5, 102, 3, CURDATE(), 19, 19, 567);
INSERT INTO `vn`.`claimState`(`id`, `description`, `roleFk`)
INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`)
VALUES
( 1, 'Pendiente', 1),
( 2, 'Gestionado', 1),
( 3, 'Resuelto', 21),
( 4, 'Anulado', 1),
( 5, 'Cuestionado', 21),
( 6, 'Mana', 1);
( 1, 'pending', 'Pendiente', 1),
( 2, 'managed', 'Gestionado', 1),
( 3, 'resolved', 'Resuelto', 21),
( 4, 'canceled', 'Anulado', 1),
( 5, 'disputed', 'Cuestionado', 21),
( 6, 'mana', 'Mana', 1);
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `observation`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created` )
VALUES

View File

@ -1,8 +1,9 @@
describe('Currency filter', () => {
beforeEach(ngModule('vnCore'));
let currencyFilter;
beforeEach(inject(_currencyFilter_ => {
beforeEach(inject((_currencyFilter_, $translate) => {
currencyFilter = _currencyFilter_;
jest.spyOn($translate, 'use').mockReturnValue('en-US');
}));
it('should return a ONE decimal number as per the argument', () => {

View File

@ -12,7 +12,10 @@ describe('regularizeClaim()', () => {
afterAll(async done => {
let claim = await app.models.Claim.findById(claimFk);
await claim.updateAttributes({claimStateFk: pendentState});
await claim.updateAttributes({
claimStateFk: pendentState,
hasToPickUp: false
});
await app.models.Ticket.destroyById(trashTicket.id);
claimEnds.forEach(async line => {

View File

@ -12,6 +12,10 @@
"id": true,
"description": "Identifier"
},
"code": {
"type": "String",
"required": true
},
"description": {
"type": "String",
"required": true

View File

@ -1,6 +1,7 @@
<vn-crud-model vn-id="model"
url="ClaimEnds"
filter="$ctrl.filter"
link="{claimFk: $ctrl.$params.id}"
data="$ctrl.salesClaimed"
auto-load="true"
auto-save="true"
@ -24,13 +25,13 @@
<vn-tool-bar class="vn-mb-md">
<vn-button
label="Import claim"
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedState"
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId"
vn-http-click="$ctrl.importToNewRefundTicket()"p
translate-attr="{title: 'Imports claim details'}">
</vn-button>
<vn-button
label="Import ticket"
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedState"
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId"
ng-click="$ctrl.showLastTickets($event)"
translate-attr="{title: 'Imports ticket lines'}">
</vn-button>
@ -90,7 +91,7 @@
{{::saleClaimed.sale.ticketFk}}
</span>
</vn-td>
<vn-td>
<vn-td expand>
<vn-autocomplete vn-one id="claimDestinationFk"
ng-model="saleClaimed.claimDestinationFk"
data="claimDestinations"
@ -112,7 +113,7 @@
<vn-icon-button
vn-tooltip="Remove line"
icon="delete"
ng-click="$ctrl.deleteClaimedSale(saleClaimed.id)"
ng-click="model.remove($index)"
tabindex="-1">
</vn-icon-button>
</vn-td>
@ -124,47 +125,12 @@
<vn-button-bar>
<vn-button
label="Regularize"
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedState"
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId"
vn-http-click="$ctrl.regularize()">
</vn-button>
</vn-button-bar>
</vn-card>
<!-- Add Lines Dialog -->
<vn-dialog vn-id="addSales">
<tpl-body>
<h3 translate>Claimable sales from ticket</h3><h3> {{$ctrl.claim.ticketFk}}</h3>
<vn-table>
<vn-thead>
<vn-tr>
<vn-th number>Id</vn-th>
<vn-th>Landed</vn-th>
<vn-th number>Quantity</vn-th>
<vn-th>Description</vn-th>
<vn-th number>Price</vn-th>
<vn-th number>Disc.</vn-th>
<vn-th number>Total</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr
ng-repeat="sale in $ctrl.salesToClaim"
class="clickable"
ng-click="$ctrl.addClaimedSale(sale.saleFk)">
<vn-td number>{{sale.saleFk}}</vn-td>
<vn-td>{{sale.landed | date: 'dd/MM/yyyy'}}</vn-td>
<vn-td number>{{sale.quantity}}</vn-td>
<vn-td expand>{{sale.concept}}</vn-td>
<vn-td number>{{sale.price | currency: 'EUR':2}}</vn-td>
<vn-td number>{{sale.discount}} %</vn-td>
<vn-td number>
{{sale.quantity * sale.price * ((100 - sale.discount) * / 100) | currency: 'EUR':2}}
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</tpl-body>
</vn-dialog>
<vn-crud-model
vn-id="lastTicketsModel"
url="Tickets"

View File

@ -6,7 +6,6 @@ export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.filter = {
where: {claimFk: this.$params.id},
include: [
{relation: 'sale',
scope: {
@ -20,39 +19,22 @@ export default class Controller extends Section {
{relation: 'claimDestination'}
]
};
this.resolvedState = 3;
this.getResolvedState();
this.maxResponsibility = 5;
}
openAddSalesDialog() {
this.getClaimedSales();
this.$.addSales.show();
}
getClaimedSales() {
let query = `ClaimBeginnings/${this.claim.id}`;
this.$http.get(query).then(res => {
if (res.data)
this.claimedSales = res.data;
});
}
addClaimedSale(saleFk) {
let saleToAdd = {saleFk: saleFk, claimFk: this.claim.id, workerFk: this.claim.workerFk, claimDestinationFk: 1};
let query = `ClaimEnds/`;
this.$http.post(query, saleToAdd).then(() => {
this.$.model.refresh();
this.$.addSales.hide();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
deleteClaimedSale(id) {
let query = `ClaimEnds/${id}`;
this.$http.delete(query).then(() => {
this.$.model.refresh();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
getResolvedState() {
const query = `ClaimStates/findOne`;
const params = {
filter: {
where: {
code: 'resolved'
}
}
};
this.$http.get(query, params).then(res =>
this.resolvedStateId = res.data.id
);
}
importToNewRefundTicket() {
@ -80,7 +62,9 @@ export default class Controller extends Section {
calculateTotals() {
this.claimedTotal = 0;
this.salesClaimed.forEach(sale => {
this.claimedTotal += (sale.sale.quantity * sale.sale.price) - ((sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100);
const price = sale.sale.quantity * sale.sale.price;
const discount = (sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100;
this.claimedTotal += price - discount;
});
}

View File

@ -32,56 +32,16 @@ describe('claim', () => {
show: () => {}
};
controller.card = {reload: () => {}};
$httpBackend.expectGET(`ClaimStates/findOne`).respond({});
}));
describe('openAddSalesDialog()', () => {
it('should call getClaimableFromTicket and $.addSales.show', () => {
controller.$ = {addSales: {show: () => {}}};
jest.spyOn(controller, 'getClaimedSales');
jest.spyOn(controller.$.addSales, 'show');
controller.openAddSalesDialog();
expect(controller.getClaimedSales).toHaveBeenCalledWith();
expect(controller.$.addSales.show).toHaveBeenCalledWith();
});
});
describe('getClaimedSales()', () => {
it('should make a query and set salesToClaim', () => {
controller.claim.id = 1;
$httpBackend.expectGET(`ClaimBeginnings/1`).respond(200, 1);
controller.getClaimedSales();
describe('getResolvedState()', () => {
it('should return the resolved state id', () => {
$httpBackend.expectGET(`ClaimStates/findOne`).respond({id: 1});
controller.getResolvedState();
$httpBackend.flush();
expect(controller.claimedSales).toEqual(1);
});
});
describe('addClaimedSale(saleFk)', () => {
it('should make a post and call refresh, hide and showSuccess', () => {
jest.spyOn(controller.$.model, 'refresh');
jest.spyOn(controller.$.addSales, 'hide');
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`ClaimEnds/`).respond({});
controller.addClaimedSale(1);
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.$.addSales.hide).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
describe('deleteClaimedSale(id)', () => {
it('should make a delete and call refresh and showSuccess', () => {
jest.spyOn(controller.$.model, 'refresh');
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectDELETE(`ClaimEnds/1`).respond({});
controller.deleteClaimedSale(1);
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.resolvedStateId).toEqual(1);
});
});
@ -102,6 +62,7 @@ describe('claim', () => {
it('should perform a post query and add lines from a new ticket', () => {
jest.spyOn(controller.$.model, 'refresh');
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expect('POST', `ClaimBeginnings/1/importToNewRefundTicket`).respond({});
controller.importToNewRefundTicket();
$httpBackend.flush();
@ -115,6 +76,7 @@ describe('claim', () => {
it('should get a list of tickets and call lastTicketsPopover show() method', () => {
jest.spyOn(controller.$.lastTicketsModel, 'refresh');
jest.spyOn(controller.$.lastTicketsPopover, 'show');
controller.showLastTickets({});
expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalledWith();
@ -127,6 +89,7 @@ describe('claim', () => {
jest.spyOn(controller.$.model, 'refresh');
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$.lastTicketsPopover, 'hide');
let data = {claimFk: 1, ticketFk: 1};
$httpBackend.expect('POST', `ClaimEnds/importTicketSales`, data).respond({});
controller.importTicketLines(1);