2449 - Ticket basic show only available zones on autocomplete #382
|
@ -50,7 +50,7 @@ describe('Ticket Edit basic data path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should edit the ticket agency then check there are no zones for it`, async() => {
|
it(`should edit the ticket agency then check there are no zones for it`, async() => {
|
||||||
await page.autocompleteSearch(selectors.ticketBasicData.agency, 'Entanglement');
|
await page.autocompleteSearch(selectors.ticketBasicData.agency, 'inhouse pickup');
|
||||||
await page.waitFor(1000);
|
await page.waitFor(1000);
|
||||||
let emptyZone = await page
|
let emptyZone = await page
|
||||||
.expectPropertyValue(selectors.ticketBasicData.zone, 'value', '');
|
.expectPropertyValue(selectors.ticketBasicData.zone, 'value', '');
|
||||||
|
@ -59,6 +59,7 @@ describe('Ticket Edit basic data path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should edit the ticket zone then check the agency is for the new zone`, async() => {
|
it(`should edit the ticket zone then check the agency is for the new zone`, async() => {
|
||||||
|
await page.clearInput(selectors.ticketBasicData.agency);
|
||||||
await page.autocompleteSearch(selectors.ticketBasicData.zone, 'Zone expensive A');
|
await page.autocompleteSearch(selectors.ticketBasicData.zone, 'Zone expensive A');
|
||||||
let zone = await page
|
let zone = await page
|
||||||
.waitToGetProperty(selectors.ticketBasicData.agency, 'value');
|
.waitToGetProperty(selectors.ticketBasicData.agency, 'value');
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
show-field="name"
|
show-field="name"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
ng-model="$ctrl.agencyModeId"
|
ng-model="$ctrl.agencyModeId"
|
||||||
where="{warehouseFk: $ctrl.warehouseId}">
|
where-function="$ctrl.agencyModeWhere()">
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
|
|
|
@ -58,12 +58,6 @@ class Controller extends Component {
|
||||||
this.ticket.warehouseFk = value;
|
this.ticket.warehouseFk = value;
|
||||||
this.ticket.agencyModeFk = null;
|
this.ticket.agencyModeFk = null;
|
||||||
this.ticket.zoneFk = null;
|
this.ticket.zoneFk = null;
|
||||||
/* this.getShipped({
|
|
||||||
landed: this.ticket.landed,
|
|
||||||
addressFk: this.ticket.addressFk,
|
|
||||||
agencyModeFk: this.ticket.agencyModeFk,
|
|
||||||
warehouseFk: value
|
|
||||||
}); */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +71,7 @@ class Controller extends Component {
|
||||||
shipped: value,
|
shipped: value,
|
||||||
addressFk: this.ticket.addressFk,
|
addressFk: this.ticket.addressFk,
|
||||||
agencyModeFk: this.ticket.agencyModeFk,
|
agencyModeFk: this.ticket.agencyModeFk,
|
||||||
warehouseFk: this.ticket.warehouseFk,
|
warehouseFk: this.ticket.warehouseFk
|
||||||
showExpiredZones: false
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,12 +96,14 @@ class Controller extends Component {
|
||||||
set agencyModeId(value) {
|
set agencyModeId(value) {
|
||||||
if (value != this.ticket.agencyModeFk) {
|
if (value != this.ticket.agencyModeFk) {
|
||||||
this.ticket.agencyModeFk = value;
|
this.ticket.agencyModeFk = value;
|
||||||
|
|
||||||
|
if (!value) return;
|
||||||
|
|
||||||
this.getLanded({
|
this.getLanded({
|
||||||
shipped: this.ticket.shipped,
|
shipped: this.ticket.shipped,
|
||||||
addressFk: this.ticket.addressFk,
|
addressFk: this.ticket.addressFk,
|
||||||
agencyModeFk: value,
|
agencyModeFk: value,
|
||||||
warehouseFk: this.ticket.warehouseFk,
|
warehouseFk: this.ticket.warehouseFk
|
||||||
showExpiredZones: false
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,6 +250,15 @@ class Controller extends Component {
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
agencyModeWhere() {
|
||||||
|
if (this.warehouseId) {
|
||||||
|
return {
|
||||||
|
warehouseFk: this.warehouseId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnTicketBasicDataStepOne', {
|
ngModule.vnComponent('vnTicketBasicDataStepOne', {
|
||||||
|
|
|
@ -94,16 +94,7 @@ describe('Ticket', () => {
|
||||||
jest.spyOn(controller, 'getShipped');
|
jest.spyOn(controller, 'getShipped');
|
||||||
controller.ticket.warehouseId = 1;
|
controller.ticket.warehouseId = 1;
|
||||||
controller.warehouseId = 2;
|
controller.warehouseId = 2;
|
||||||
const landed = new Date();
|
|
||||||
const expectedResult = {
|
|
||||||
landed: landed,
|
|
||||||
addressFk: 121,
|
|
||||||
agencyModeFk: 7,
|
|
||||||
warehouseFk: 2
|
|
||||||
};
|
|
||||||
controller.landed = landed;
|
|
||||||
|
|
||||||
expect(controller.getShipped).toHaveBeenCalledWith(expectedResult);
|
|
||||||
expect(controller.ticket.warehouseFk).toEqual(2);
|
expect(controller.ticket.warehouseFk).toEqual(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -125,7 +116,6 @@ describe('Ticket', () => {
|
||||||
shipped: shipped,
|
shipped: shipped,
|
||||||
addressFk: 121,
|
addressFk: 121,
|
||||||
agencyModeFk: 7,
|
agencyModeFk: 7,
|
||||||
showExpiredZones: false,
|
|
||||||
warehouseFk: 1
|
warehouseFk: 1
|
||||||
};
|
};
|
||||||
controller.shipped = shipped;
|
controller.shipped = shipped;
|
||||||
|
@ -176,8 +166,7 @@ describe('Ticket', () => {
|
||||||
shipped: shipped,
|
shipped: shipped,
|
||||||
addressFk: 121,
|
addressFk: 121,
|
||||||
agencyModeFk: agencyModeId,
|
agencyModeFk: agencyModeId,
|
||||||
warehouseFk: 1,
|
warehouseFk: 1
|
||||||
showExpiredZones: false,
|
|
||||||
};
|
};
|
||||||
controller.ticket.shipped = shipped;
|
controller.ticket.shipped = shipped;
|
||||||
controller.agencyModeId = 8;
|
controller.agencyModeId = 8;
|
||||||
|
@ -363,5 +352,31 @@ describe('Ticket', () => {
|
||||||
expect(controller.landed).toEqual(landed);
|
expect(controller.landed).toEqual(landed);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('zoneWhere() getter', () => {
|
||||||
|
it('should return an object containing filter properties', async() => {
|
||||||
|
const shipped = new Date();
|
||||||
|
controller.ticket.shipped = shipped;
|
||||||
|
|
||||||
|
const expectedResult = {
|
||||||
|
addressFk: 121,
|
||||||
|
agencyModeFk: 7,
|
||||||
|
shipped: shipped,
|
||||||
|
warehouseFk: 1
|
||||||
|
};
|
||||||
|
const result = controller.zoneWhere();
|
||||||
|
|
||||||
|
expect(result).toEqual(expect.objectContaining(expectedResult));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('agencyModeWhere() getter', () => {
|
||||||
|
it('should return an object containing the warehouseFk property', async() => {
|
||||||
|
const expectedResult = {warehouseFk: 1};
|
||||||
|
const result = controller.agencyModeWhere();
|
||||||
|
|
||||||
|
expect(result).toEqual(expect.objectContaining(expectedResult));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('AgencyMode byWarehhouse()', () => {
|
||||||
|
const warehouseId = 1;
|
||||||
|
it('should return all the agencies', async() => {
|
||||||
|
const where = {};
|
||||||
|
const agencies = await app.models.AgencyMode.byWarehouse({where});
|
||||||
|
|
||||||
|
expect(agencies.length).toBeGreaterThan(10);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return only the agencies for a warehouse', async() => {
|
||||||
|
const where = {warehouseFk: warehouseId};
|
||||||
|
const agencies = await app.models.AgencyMode.byWarehouse({where});
|
||||||
|
|
||||||
|
const validWarehouse = agencies.every(agency => agency.warehouseFk = warehouseId);
|
||||||
|
|
||||||
|
expect(agencies.length).toEqual(6);
|
||||||
|
expect(validWarehouse).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,7 +1,7 @@
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('getLanded', {
|
Self.remoteMethodCtx('getLanded', {
|
||||||
description: 'Returns the first shipped and landed possible for params',
|
description: 'Returns the first shipped and landed possible for params',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
|
@ -23,11 +23,6 @@ module.exports = Self => {
|
||||||
arg: 'warehouseFk',
|
arg: 'warehouseFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true
|
required: true
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'showExpiredZones',
|
|
||||||
type: 'boolean',
|
|
||||||
required: true
|
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -39,7 +34,13 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getLanded = async(shipped, addressFk, agencyModeFk, warehouseFk, showExpiredZones) => {
|
Self.getLanded = async(ctx, shipped, addressFk, agencyModeFk, warehouseFk) => {
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const models = Self.app.models;
|
||||||
|
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
|
||||||
|
let showExpired = false;
|
||||||
|
if (isProductionBoss) showExpired = true;
|
||||||
|
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
stmts.push(new ParameterizedSQL(
|
stmts.push(new ParameterizedSQL(
|
||||||
`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
|
`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
|
||||||
|
@ -47,7 +48,7 @@ module.exports = Self => {
|
||||||
addressFk,
|
addressFk,
|
||||||
agencyModeFk,
|
agencyModeFk,
|
||||||
warehouseFk,
|
warehouseFk,
|
||||||
showExpiredZones
|
showExpired
|
||||||
]
|
]
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,13 @@ const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('agency getLanded()', () => {
|
describe('agency getLanded()', () => {
|
||||||
it('should return a landing date', async() => {
|
it('should return a landing date', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}};
|
||||||
const shipped = new Date();
|
const shipped = new Date();
|
||||||
shipped.setDate(shipped.getDate() + 1);
|
shipped.setDate(shipped.getDate() + 1);
|
||||||
const addressFk = 121;
|
const addressFk = 121;
|
||||||
const agencyModeFk = 7;
|
const agencyModeFk = 7;
|
||||||
const warehouseFk = 1;
|
const warehouseFk = 1;
|
||||||
const showExpiredZones = true;
|
let result = await app.models.Agency.getLanded(ctx, shipped, addressFk, agencyModeFk, warehouseFk);
|
||||||
let result = await app.models.Agency.getLanded(shipped, addressFk, agencyModeFk, warehouseFk, showExpiredZones);
|
|
||||||
|
|
||||||
expect(result.landed).toBeDefined();
|
expect(result.landed).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('includingExpired', {
|
Self.remoteMethodCtx('includingExpired', {
|
||||||
description: 'Returns a list of agencies from a warehouse',
|
description: 'Returns a list of agencies from a warehouse',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
|
@ -19,33 +19,44 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.includingExpired = async filter => {
|
Self.includingExpired = async(ctx, filter) => {
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
|
const models = Self.app.models;
|
||||||
const where = filter.where;
|
const where = filter.where;
|
||||||
// filter = mergeFilters(filter, {where});
|
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
console.log(where);
|
const filterByAvailability = where.shipped && where.addressFk
|
||||||
|
&& where.agencyModeFk && where.warehouseFk;
|
||||||
|
|
||||||
|
if (filterByAvailability) {
|
||||||
|
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
|
||||||
|
let showExpired = false;
|
||||||
|
if (isProductionBoss) showExpired = true;
|
||||||
|
|
||||||
if (where.agencyModeFk) {
|
|
||||||
stmt = new ParameterizedSQL(`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
|
stmt = new ParameterizedSQL(`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
|
||||||
where.shipped,
|
where.shipped,
|
||||||
where.addressFk,
|
where.addressFk,
|
||||||
where.agencyModeFk,
|
where.agencyModeFk,
|
||||||
where.warehouseFk,
|
where.warehouseFk,
|
||||||
true]);
|
showExpired]);
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete where.shipped;
|
||||||
|
delete where.addressFk;
|
||||||
|
delete where.warehouseFk;
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(
|
||||||
`SELECT id, name, agencyModeFk
|
`SELECT id, name, agencyModeFk
|
||||||
FROM vn.zone z`);
|
FROM vn.zone z`);
|
||||||
|
|
||||||
if (where.agencyModeFk)
|
if (filterByAvailability)
|
||||||
stmt.merge(`JOIN tmp.zoneGetLanded zgl ON zgl.zoneFk = z.id`);
|
stmt.merge(`JOIN tmp.zoneGetLanded zgl ON zgl.zoneFk = z.id`);
|
||||||
|
|
||||||
stmt.merge(conn.makePagination(filter));
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
|
|
||||||
let index;
|
let index;
|
||||||
if (stmts.length)
|
if (stmts.length)
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('zone includingExpired()', () => {
|
||||||
|
const inhousePickupId = 1;
|
||||||
|
const addressId = 101;
|
||||||
|
const warehouseId = 1;
|
||||||
|
|
||||||
|
it('should return an array containing all zones', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}};
|
||||||
|
const where = {};
|
||||||
|
const result = await app.models.Zone.includingExpired(ctx, {where});
|
||||||
|
|
||||||
|
expect(result.length).toBeGreaterThan(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an array containing zones from the agencyMode "Inhouse pickup"', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}};
|
||||||
|
const where = {agencyModeFk: inhousePickupId};
|
||||||
|
const result = await app.models.Zone.includingExpired(ctx, {where});
|
||||||
|
|
||||||
|
const validAgency = result.every(zone => zone.agencyModeFk = inhousePickupId);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(3);
|
||||||
|
expect(validAgency).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an array containing available zones', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}};
|
||||||
|
const where = {
|
||||||
|
shipped: new Date(),
|
||||||
|
addressFk: addressId,
|
||||||
|
agencyModeFk: inhousePickupId,
|
||||||
|
warehouseFk: warehouseId
|
||||||
|
};
|
||||||
|
const result = await app.models.Zone.includingExpired(ctx, {where});
|
||||||
|
const firstZone = result[0];
|
||||||
|
|
||||||
|
expect(firstZone.name).toEqual('Zone pickup A');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue