#612 añadir reclamacion
This commit is contained in:
parent
588308cf1e
commit
c9ec4aee7e
|
@ -47,7 +47,7 @@
|
||||||
<vn-table model="model">
|
<vn-table model="model">
|
||||||
<vn-thead>
|
<vn-thead>
|
||||||
<vn-tr>
|
<vn-tr>
|
||||||
<vn-th number ng-show="$ctrl.isEditable">
|
<vn-th number>
|
||||||
<vn-multi-check
|
<vn-multi-check
|
||||||
data="$ctrl.sales">
|
data="$ctrl.sales">
|
||||||
</vn-multi-check>
|
</vn-multi-check>
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
</vn-thead>
|
</vn-thead>
|
||||||
<vn-tbody>
|
<vn-tbody>
|
||||||
<vn-tr ng-repeat="sale in sales">
|
<vn-tr ng-repeat="sale in sales">
|
||||||
<vn-td number ng-show="$ctrl.isEditable">
|
<vn-td number >
|
||||||
<vn-check
|
<vn-check
|
||||||
field="sale.checked">
|
field="sale.checked">
|
||||||
</vn-check>
|
</vn-check>
|
||||||
|
|
|
@ -16,7 +16,8 @@ class Controller {
|
||||||
{callback: this.showDeleteTicketDialog, name: "Delete ticket", always: true},
|
{callback: this.showDeleteTicketDialog, name: "Delete ticket", always: true},
|
||||||
{callback: this.markAsReserved, name: 'Mark as reserved'},
|
{callback: this.markAsReserved, name: 'Mark as reserved'},
|
||||||
{callback: this.unmarkAsReserved, name: 'Unmark as reserved'},
|
{callback: this.unmarkAsReserved, name: 'Unmark as reserved'},
|
||||||
{callback: this.showEditDialog, name: 'Update discount'}
|
{callback: this.showEditDialog, name: 'Update discount'},
|
||||||
|
{callback: this.createClaim, name: 'Add claim'}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +79,6 @@ class Controller {
|
||||||
for (let i = 0; i < data.length; i++)
|
for (let i = 0; i < data.length; i++)
|
||||||
if (data[i].checked)
|
if (data[i].checked)
|
||||||
lines.push({id: data[i].id, instance: i});
|
lines.push({id: data[i].id, instance: i});
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,6 @@ class Controller {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// In Progress
|
|
||||||
linesToNewTicket() {
|
linesToNewTicket() {
|
||||||
let ticket = {
|
let ticket = {
|
||||||
oldTicketFk: this.ticket.id,
|
oldTicketFk: this.ticket.id,
|
||||||
|
@ -197,6 +196,22 @@ class Controller {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createClaim() {
|
||||||
|
let claim = {
|
||||||
|
ticketFk: this.ticket.id,
|
||||||
|
clientFk: this.ticket.clientFk,
|
||||||
|
ticketCreated: this.ticket.shipped,
|
||||||
|
workerFk: this.ticket.client.salesPersonFk
|
||||||
|
};
|
||||||
|
let sales = this.getCheckedLines();
|
||||||
|
for (let i = 0; i < sales.length; i++)
|
||||||
|
sales[i].quantity = this.sales[sales[i].instance].quantity;
|
||||||
|
this.$http.post(`claim/api/Claims/createFromSales`, {claim: claim, sales: sales}).then(res => {
|
||||||
|
let url = this.$state.href("claim.card.basicData", {id: res.data.id}, {absolute: true});
|
||||||
|
window.open(url, '_blank');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
goToTicket(ticketID) {
|
goToTicket(ticketID) {
|
||||||
this.$state.go("ticket.card.sale", {id: ticketID});
|
this.$state.go("ticket.card.sale", {id: ticketID});
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,28 @@ describe('Ticket', () => {
|
||||||
quantity: 20,
|
quantity: 20,
|
||||||
price: 5.5,
|
price: 5.5,
|
||||||
discount: 0,
|
discount: 0,
|
||||||
checked: true
|
checked: false
|
||||||
}
|
}
|
||||||
]};
|
]};
|
||||||
$scope.addTurn = {show: () => {}};
|
$scope.addTurn = {show: () => {}};
|
||||||
controller = $componentController('vnTicketSale', {$scope: $scope}, {$state: $state});
|
controller = $componentController('vnTicketSale', {$scope: $scope}, {$state: $state});
|
||||||
controller.ticket = {id: 1};
|
controller.ticket = {id: 1, clientFk: 1, shipped: 1, client: {salesPersonFk: 1}};
|
||||||
|
spyOn(window, 'open');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
describe('createClaim()', () => {
|
||||||
|
it('should perfrom a query and call windows open', () => {
|
||||||
|
controller.sales = controller.$scope.model.data;
|
||||||
|
let res = {id: 1};
|
||||||
|
$httpBackend.expectPOST(`claim/api/Claims/createFromSales`).respond(res);
|
||||||
|
controller.createClaim();
|
||||||
|
$httpBackend.flush();
|
||||||
|
let urlMock = null;
|
||||||
|
|
||||||
|
expect(window.open).toHaveBeenCalledWith(urlMock, '_blank');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('getSales()', () => {
|
describe('getSales()', () => {
|
||||||
it('should make a query and call getTaxes()', () => {
|
it('should make a query and call getTaxes()', () => {
|
||||||
let data = [
|
let data = [
|
||||||
|
@ -56,7 +70,7 @@ describe('Ticket', () => {
|
||||||
quantity: 20,
|
quantity: 20,
|
||||||
price: 5.5,
|
price: 5.5,
|
||||||
discount: 0,
|
discount: 0,
|
||||||
checked: true
|
checked: false
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -113,9 +127,10 @@ describe('Ticket', () => {
|
||||||
|
|
||||||
describe('getCheckedLines()', () => {
|
describe('getCheckedLines()', () => {
|
||||||
it('should make an array of the instances with the property checked true()', () => {
|
it('should make an array of the instances with the property checked true()', () => {
|
||||||
controller.sales = [{id: 1, checked: true}, {id: 2, checked: false}, {id: 3, checked: true}];
|
let expectedResult = [{id: 1, instance: 0}];
|
||||||
|
controller.sales = controller.$scope.model.data;
|
||||||
|
|
||||||
expect(controller.getCheckedLines()).toEqual([{id: 1, instance: 0}, {id: 3, instance: 2}]);
|
expect(controller.getCheckedLines()).toEqual(expectedResult);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -22,4 +22,5 @@ Wednesday: Miércoles
|
||||||
Thursday: Jueves
|
Thursday: Jueves
|
||||||
Friday: Viernes
|
Friday: Viernes
|
||||||
Saturday: Sábado
|
Saturday: Sábado
|
||||||
Sunday: Domingo
|
Sunday: Domingo
|
||||||
|
Add claim: Crear reclamación
|
|
@ -0,0 +1,50 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('createFromSales', {
|
||||||
|
description: 'Create a claim',
|
||||||
|
accessType: '',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'claim',
|
||||||
|
type: 'object',
|
||||||
|
required: true,
|
||||||
|
description: ' newTicketFk, clientFk, ticketCreated',
|
||||||
|
http: {source: 'body'}
|
||||||
|
}, {
|
||||||
|
arg: 'sales',
|
||||||
|
type: 'object',
|
||||||
|
required: true,
|
||||||
|
description: '[sales IDs]',
|
||||||
|
http: {source: 'body'}
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/createFromSales`,
|
||||||
|
verb: 'post'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.createFromSales = async params => {
|
||||||
|
let model = Self.app.models;
|
||||||
|
let transaction = await Self.beginTransaction({});
|
||||||
|
try {
|
||||||
|
let newClaim = await Self.create(params.claim, {transaction});
|
||||||
|
let promises = [];
|
||||||
|
for (let i = 0; i < params.sales.length; i++) {
|
||||||
|
promises.push(model.ClaimBeginning.create(
|
||||||
|
{saleFk: params.sales[i].id,
|
||||||
|
claimFk: newClaim.id,
|
||||||
|
quantity: params.sales[i].quantity},
|
||||||
|
{transaction}));
|
||||||
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
|
await transaction.commit();
|
||||||
|
|
||||||
|
return newClaim;
|
||||||
|
} catch (e) {
|
||||||
|
transaction.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,54 @@
|
||||||
|
const app = require(`${servicesDir}/claim/server/server`);
|
||||||
|
|
||||||
|
fdescribe('Claim Create', () => {
|
||||||
|
let newDate = new Date();
|
||||||
|
let createdClaimFk;
|
||||||
|
|
||||||
|
afterAll(async() => {
|
||||||
|
console.log('asdf', createdClaimFk);
|
||||||
|
await app.models.Claim.destroyById(createdClaimFk);
|
||||||
|
});
|
||||||
|
|
||||||
|
let newClaim = {
|
||||||
|
ticketFk: 2,
|
||||||
|
clientFk: 101,
|
||||||
|
ticketCreated: newDate,
|
||||||
|
workerFk: 18
|
||||||
|
};
|
||||||
|
|
||||||
|
let newSale = [{
|
||||||
|
id: 2,
|
||||||
|
instance: 0,
|
||||||
|
quantity: 10
|
||||||
|
}];
|
||||||
|
|
||||||
|
let params = {claim: newClaim, sales: newSale};
|
||||||
|
|
||||||
|
it('should create a new claim', async() => {
|
||||||
|
let claim = await app.models.Claim.createFromSales(params);
|
||||||
|
|
||||||
|
expect(claim.ticketFk).toEqual(newClaim.ticketFk);
|
||||||
|
expect(claim.clientFk).toEqual(newClaim.clientFk);
|
||||||
|
expect(claim.ticketCreated).toEqual(newClaim.ticketCreated);
|
||||||
|
expect(claim.workerFk).toEqual(newClaim.workerFk);
|
||||||
|
|
||||||
|
let claimBeginning = await app.models.ClaimBeginning.findOne({where: {claimFk: claim.id}});
|
||||||
|
|
||||||
|
expect(claimBeginning.saleFk).toEqual(newSale[0].id);
|
||||||
|
expect(claimBeginning.quantity).toEqual(newSale[0].quantity);
|
||||||
|
|
||||||
|
createdClaimFk = claim.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not be able to create a claim if exists that sale', async() => {
|
||||||
|
let error;
|
||||||
|
|
||||||
|
await app.models.Claim.createFromSales(params)
|
||||||
|
|
||||||
|
.catch(e => {
|
||||||
|
error = e;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(error.toString()).toContain(`A claim with that sale already exists`);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,3 +1,4 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/claim/getSummary')(Self);
|
require('../methods/claim/getSummary')(Self);
|
||||||
|
require('../methods/claim/createFromSales')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,16 +21,13 @@
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"isChargedToMana": {
|
"isChargedToMana": {
|
||||||
"type": "boolean",
|
"type": "boolean"
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
"created": {
|
"created": {
|
||||||
"type": "date",
|
"type": "date"
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
"responsibility": {
|
"responsibility": {
|
||||||
"type": "Number",
|
"type": "Number"
|
||||||
"required": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -46,5 +46,6 @@
|
||||||
"Barcode must be unique": "El código de barras debe ser único",
|
"Barcode must be unique": "El código de barras debe ser único",
|
||||||
"The warehouse can't be repeated": "El almacén no puede repetirse",
|
"The warehouse can't be repeated": "El almacén no puede repetirse",
|
||||||
"The tag can't be repeated": "El tag no puede repetirse",
|
"The tag can't be repeated": "El tag no puede repetirse",
|
||||||
"The observation type can't be repeated": "El tipo de observación no puede repetirse"
|
"The observation type can't be repeated": "El tipo de observación no puede repetirse",
|
||||||
|
"A claim with that sale already exists": "Ya existe una reclamación para esta línea"
|
||||||
}
|
}
|
Loading…
Reference in New Issue