#612 añadir reclamacion
This commit is contained in:
parent
588308cf1e
commit
c9ec4aee7e
|
@ -47,7 +47,7 @@
|
|||
<vn-table model="model">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th number ng-show="$ctrl.isEditable">
|
||||
<vn-th number>
|
||||
<vn-multi-check
|
||||
data="$ctrl.sales">
|
||||
</vn-multi-check>
|
||||
|
@ -64,7 +64,7 @@
|
|||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="sale in sales">
|
||||
<vn-td number ng-show="$ctrl.isEditable">
|
||||
<vn-td number >
|
||||
<vn-check
|
||||
field="sale.checked">
|
||||
</vn-check>
|
||||
|
|
|
@ -16,7 +16,8 @@ class Controller {
|
|||
{callback: this.showDeleteTicketDialog, name: "Delete ticket", always: true},
|
||||
{callback: this.markAsReserved, name: 'Mark 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++)
|
||||
if (data[i].checked)
|
||||
lines.push({id: data[i].id, instance: i});
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,6 @@ class Controller {
|
|||
});
|
||||
}
|
||||
|
||||
// In Progress
|
||||
linesToNewTicket() {
|
||||
let ticket = {
|
||||
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) {
|
||||
this.$state.go("ticket.card.sale", {id: ticketID});
|
||||
}
|
||||
|
|
|
@ -33,14 +33,28 @@ describe('Ticket', () => {
|
|||
quantity: 20,
|
||||
price: 5.5,
|
||||
discount: 0,
|
||||
checked: true
|
||||
checked: false
|
||||
}
|
||||
]};
|
||||
$scope.addTurn = {show: () => {}};
|
||||
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()', () => {
|
||||
it('should make a query and call getTaxes()', () => {
|
||||
let data = [
|
||||
|
@ -56,7 +70,7 @@ describe('Ticket', () => {
|
|||
quantity: 20,
|
||||
price: 5.5,
|
||||
discount: 0,
|
||||
checked: true
|
||||
checked: false
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -113,9 +127,10 @@ describe('Ticket', () => {
|
|||
|
||||
describe('getCheckedLines()', () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -23,3 +23,4 @@ Thursday: Jueves
|
|||
Friday: Viernes
|
||||
Saturday: Sábado
|
||||
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 => {
|
||||
require('../methods/claim/getSummary')(Self);
|
||||
require('../methods/claim/createFromSales')(Self);
|
||||
};
|
||||
|
|
|
@ -21,16 +21,13 @@
|
|||
"required": true
|
||||
},
|
||||
"isChargedToMana": {
|
||||
"type": "boolean",
|
||||
"required": true
|
||||
"type": "boolean"
|
||||
},
|
||||
"created": {
|
||||
"type": "date",
|
||||
"required": true
|
||||
"type": "date"
|
||||
},
|
||||
"responsibility": {
|
||||
"type": "Number",
|
||||
"required": true
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
|
@ -46,5 +46,6 @@
|
|||
"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 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