Merge pull request '1833 Claim action refactor' (#253) from 1833-claim_action_refactor into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-by: Carlos Jimenez <carlosjr@verdnatura.es>
This commit is contained in:
commit
d960295efa
|
@ -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');
|
|
@ -1473,14 +1473,14 @@ INSERT INTO `vn`.`clientSample`(`id`, `clientFk`, `typeFk`, `created`, `workerFk
|
||||||
(4, 102, 2, CURDATE(), 18, 18, 567),
|
(4, 102, 2, CURDATE(), 18, 18, 567),
|
||||||
(5, 102, 3, CURDATE(), 19, 19, 567);
|
(5, 102, 3, CURDATE(), 19, 19, 567);
|
||||||
|
|
||||||
INSERT INTO `vn`.`claimState`(`id`, `description`, `roleFk`)
|
INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`)
|
||||||
VALUES
|
VALUES
|
||||||
( 1, 'Pendiente', 1),
|
( 1, 'pending', 'Pendiente', 1),
|
||||||
( 2, 'Gestionado', 1),
|
( 2, 'managed', 'Gestionado', 1),
|
||||||
( 3, 'Resuelto', 21),
|
( 3, 'resolved', 'Resuelto', 21),
|
||||||
( 4, 'Anulado', 1),
|
( 4, 'canceled', 'Anulado', 1),
|
||||||
( 5, 'Cuestionado', 21),
|
( 5, 'disputed', 'Cuestionado', 21),
|
||||||
( 6, 'Mana', 1);
|
( 6, 'mana', 'Mana', 1);
|
||||||
|
|
||||||
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `observation`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created` )
|
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `observation`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created` )
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
describe('Currency filter', () => {
|
describe('Currency filter', () => {
|
||||||
beforeEach(ngModule('vnCore'));
|
beforeEach(ngModule('vnCore'));
|
||||||
let currencyFilter;
|
let currencyFilter;
|
||||||
beforeEach(inject(_currencyFilter_ => {
|
beforeEach(inject((_currencyFilter_, $translate) => {
|
||||||
currencyFilter = _currencyFilter_;
|
currencyFilter = _currencyFilter_;
|
||||||
|
jest.spyOn($translate, 'use').mockReturnValue('en-US');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return a ONE decimal number as per the argument', () => {
|
it('should return a ONE decimal number as per the argument', () => {
|
||||||
|
|
|
@ -12,7 +12,10 @@ describe('regularizeClaim()', () => {
|
||||||
|
|
||||||
afterAll(async done => {
|
afterAll(async done => {
|
||||||
let claim = await app.models.Claim.findById(claimFk);
|
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);
|
await app.models.Ticket.destroyById(trashTicket.id);
|
||||||
|
|
||||||
claimEnds.forEach(async line => {
|
claimEnds.forEach(async line => {
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"description": "Identifier"
|
"description": "Identifier"
|
||||||
},
|
},
|
||||||
|
"code": {
|
||||||
|
"type": "String",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "String",
|
"type": "String",
|
||||||
"required": true
|
"required": true
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<vn-crud-model vn-id="model"
|
<vn-crud-model vn-id="model"
|
||||||
url="ClaimEnds"
|
url="ClaimEnds"
|
||||||
filter="$ctrl.filter"
|
filter="$ctrl.filter"
|
||||||
|
link="{claimFk: $ctrl.$params.id}"
|
||||||
data="$ctrl.salesClaimed"
|
data="$ctrl.salesClaimed"
|
||||||
auto-load="true"
|
auto-load="true"
|
||||||
auto-save="true"
|
auto-save="true"
|
||||||
|
@ -24,13 +25,13 @@
|
||||||
<vn-tool-bar class="vn-mb-md">
|
<vn-tool-bar class="vn-mb-md">
|
||||||
<vn-button
|
<vn-button
|
||||||
label="Import claim"
|
label="Import claim"
|
||||||
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedState"
|
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId"
|
||||||
vn-http-click="$ctrl.importToNewRefundTicket()"p
|
vn-http-click="$ctrl.importToNewRefundTicket()"p
|
||||||
translate-attr="{title: 'Imports claim details'}">
|
translate-attr="{title: 'Imports claim details'}">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
<vn-button
|
<vn-button
|
||||||
label="Import ticket"
|
label="Import ticket"
|
||||||
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedState"
|
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId"
|
||||||
ng-click="$ctrl.showLastTickets($event)"
|
ng-click="$ctrl.showLastTickets($event)"
|
||||||
translate-attr="{title: 'Imports ticket lines'}">
|
translate-attr="{title: 'Imports ticket lines'}">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
|
@ -90,7 +91,7 @@
|
||||||
{{::saleClaimed.sale.ticketFk}}
|
{{::saleClaimed.sale.ticketFk}}
|
||||||
</span>
|
</span>
|
||||||
</vn-td>
|
</vn-td>
|
||||||
<vn-td>
|
<vn-td expand>
|
||||||
<vn-autocomplete vn-one id="claimDestinationFk"
|
<vn-autocomplete vn-one id="claimDestinationFk"
|
||||||
ng-model="saleClaimed.claimDestinationFk"
|
ng-model="saleClaimed.claimDestinationFk"
|
||||||
data="claimDestinations"
|
data="claimDestinations"
|
||||||
|
@ -112,7 +113,7 @@
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
vn-tooltip="Remove line"
|
vn-tooltip="Remove line"
|
||||||
icon="delete"
|
icon="delete"
|
||||||
ng-click="$ctrl.deleteClaimedSale(saleClaimed.id)"
|
ng-click="model.remove($index)"
|
||||||
tabindex="-1">
|
tabindex="-1">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
</vn-td>
|
</vn-td>
|
||||||
|
@ -124,47 +125,12 @@
|
||||||
<vn-button-bar>
|
<vn-button-bar>
|
||||||
<vn-button
|
<vn-button
|
||||||
label="Regularize"
|
label="Regularize"
|
||||||
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedState"
|
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId"
|
||||||
vn-http-click="$ctrl.regularize()">
|
vn-http-click="$ctrl.regularize()">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</vn-card>
|
</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-crud-model
|
||||||
vn-id="lastTicketsModel"
|
vn-id="lastTicketsModel"
|
||||||
url="Tickets"
|
url="Tickets"
|
||||||
|
|
|
@ -6,7 +6,6 @@ export default class Controller extends Section {
|
||||||
constructor($element, $) {
|
constructor($element, $) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
this.filter = {
|
this.filter = {
|
||||||
where: {claimFk: this.$params.id},
|
|
||||||
include: [
|
include: [
|
||||||
{relation: 'sale',
|
{relation: 'sale',
|
||||||
scope: {
|
scope: {
|
||||||
|
@ -20,39 +19,22 @@ export default class Controller extends Section {
|
||||||
{relation: 'claimDestination'}
|
{relation: 'claimDestination'}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
this.resolvedState = 3;
|
this.getResolvedState();
|
||||||
this.maxResponsibility = 5;
|
this.maxResponsibility = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
openAddSalesDialog() {
|
getResolvedState() {
|
||||||
this.getClaimedSales();
|
const query = `ClaimStates/findOne`;
|
||||||
this.$.addSales.show();
|
const params = {
|
||||||
}
|
filter: {
|
||||||
|
where: {
|
||||||
getClaimedSales() {
|
code: 'resolved'
|
||||||
let query = `ClaimBeginnings/${this.claim.id}`;
|
}
|
||||||
this.$http.get(query).then(res => {
|
}
|
||||||
if (res.data)
|
};
|
||||||
this.claimedSales = res.data;
|
this.$http.get(query, params).then(res =>
|
||||||
});
|
this.resolvedStateId = res.data.id
|
||||||
}
|
);
|
||||||
|
|
||||||
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!'));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
importToNewRefundTicket() {
|
importToNewRefundTicket() {
|
||||||
|
@ -80,7 +62,9 @@ export default class Controller extends Section {
|
||||||
calculateTotals() {
|
calculateTotals() {
|
||||||
this.claimedTotal = 0;
|
this.claimedTotal = 0;
|
||||||
this.salesClaimed.forEach(sale => {
|
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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,56 +32,16 @@ describe('claim', () => {
|
||||||
show: () => {}
|
show: () => {}
|
||||||
};
|
};
|
||||||
controller.card = {reload: () => {}};
|
controller.card = {reload: () => {}};
|
||||||
|
$httpBackend.expectGET(`ClaimStates/findOne`).respond({});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('openAddSalesDialog()', () => {
|
describe('getResolvedState()', () => {
|
||||||
it('should call getClaimableFromTicket and $.addSales.show', () => {
|
it('should return the resolved state id', () => {
|
||||||
controller.$ = {addSales: {show: () => {}}};
|
$httpBackend.expectGET(`ClaimStates/findOne`).respond({id: 1});
|
||||||
jest.spyOn(controller, 'getClaimedSales');
|
controller.getResolvedState();
|
||||||
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();
|
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.claimedSales).toEqual(1);
|
expect(controller.resolvedStateId).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!');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -102,6 +62,7 @@ describe('claim', () => {
|
||||||
it('should perform a post query and add lines from a new ticket', () => {
|
it('should perform a post query and add lines from a new ticket', () => {
|
||||||
jest.spyOn(controller.$.model, 'refresh');
|
jest.spyOn(controller.$.model, 'refresh');
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
||||||
$httpBackend.expect('POST', `ClaimBeginnings/1/importToNewRefundTicket`).respond({});
|
$httpBackend.expect('POST', `ClaimBeginnings/1/importToNewRefundTicket`).respond({});
|
||||||
controller.importToNewRefundTicket();
|
controller.importToNewRefundTicket();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
@ -115,6 +76,7 @@ describe('claim', () => {
|
||||||
it('should get a list of tickets and call lastTicketsPopover show() method', () => {
|
it('should get a list of tickets and call lastTicketsPopover show() method', () => {
|
||||||
jest.spyOn(controller.$.lastTicketsModel, 'refresh');
|
jest.spyOn(controller.$.lastTicketsModel, 'refresh');
|
||||||
jest.spyOn(controller.$.lastTicketsPopover, 'show');
|
jest.spyOn(controller.$.lastTicketsPopover, 'show');
|
||||||
|
|
||||||
controller.showLastTickets({});
|
controller.showLastTickets({});
|
||||||
|
|
||||||
expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalledWith();
|
expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalledWith();
|
||||||
|
@ -127,6 +89,7 @@ describe('claim', () => {
|
||||||
jest.spyOn(controller.$.model, 'refresh');
|
jest.spyOn(controller.$.model, 'refresh');
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
jest.spyOn(controller.$.lastTicketsPopover, 'hide');
|
jest.spyOn(controller.$.lastTicketsPopover, 'hide');
|
||||||
|
|
||||||
let data = {claimFk: 1, ticketFk: 1};
|
let data = {claimFk: 1, ticketFk: 1};
|
||||||
$httpBackend.expect('POST', `ClaimEnds/importTicketSales`, data).respond({});
|
$httpBackend.expect('POST', `ClaimEnds/importTicketSales`, data).respond({});
|
||||||
controller.importTicketLines(1);
|
controller.importTicketLines(1);
|
||||||
|
|
Loading…
Reference in New Issue