Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 3604-route_agencyTerm
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
6b51b7ddd7
|
@ -18,7 +18,7 @@ module.exports = Self => {
|
||||||
}, {
|
}, {
|
||||||
arg: 'search',
|
arg: 'search',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `If it's and integer searchs by id, otherwise it searchs by nickname`
|
description: `The general search by ticket id or nickname`
|
||||||
}, {
|
}, {
|
||||||
arg: 'from',
|
arg: 'from',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
|
@ -36,9 +36,9 @@ module.exports = Self => {
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
description: 'The client id'
|
description: 'The client id'
|
||||||
}, {
|
}, {
|
||||||
arg: 'ticketFk',
|
arg: 'orderFk',
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
description: 'The ticket id'
|
description: 'The order id'
|
||||||
}, {
|
}, {
|
||||||
arg: 'agencyModeFk',
|
arg: 'agencyModeFk',
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
|
@ -103,7 +103,7 @@ module.exports = Self => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'search':
|
case 'search':
|
||||||
return /^\d+$/.test(value)
|
return /^\d+$/.test(value)
|
||||||
? {'o.id': value}
|
? {'t.id': value}
|
||||||
: {or: [
|
: {or: [
|
||||||
{'c.name': {like: `%${value}%`}}
|
{'c.name': {like: `%${value}%`}}
|
||||||
]};
|
]};
|
||||||
|
@ -119,8 +119,8 @@ module.exports = Self => {
|
||||||
return {'o.agency_id': value};
|
return {'o.agency_id': value};
|
||||||
case 'sourceApp':
|
case 'sourceApp':
|
||||||
return {'o.source_app': value};
|
return {'o.source_app': value};
|
||||||
case 'ticketFk':
|
case 'orderFk':
|
||||||
return {'ot.ticketFk': value};
|
return {'o.id': value};
|
||||||
case 'isConfirmed':
|
case 'isConfirmed':
|
||||||
return {'o.confirmed': value ? 1 : 0};
|
return {'o.confirmed': value ? 1 : 0};
|
||||||
case 'myTeam':
|
case 'myTeam':
|
||||||
|
@ -131,7 +131,7 @@ module.exports = Self => {
|
||||||
case 'showEmpty':
|
case 'showEmpty':
|
||||||
return {'o.total': {neq: value}};
|
return {'o.total': {neq: value}};
|
||||||
case 'id':
|
case 'id':
|
||||||
param = `o.${param}`;
|
param = `t.${param}`;
|
||||||
return {[param]: value};
|
return {[param]: value};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<vn-searchbar
|
<vn-searchbar
|
||||||
vn-focus
|
vn-focus
|
||||||
panel="vn-order-search-panel"
|
panel="vn-order-search-panel"
|
||||||
info="Search orders by id"
|
info="Search orders by ticket id"
|
||||||
model="model"
|
model="model"
|
||||||
filter="$ctrl.filter">
|
filter="$ctrl.filter">
|
||||||
</vn-searchbar>
|
</vn-searchbar>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
vn-one
|
vn-one
|
||||||
label="General search"
|
label="General search"
|
||||||
ng-model="filter.search"
|
ng-model="filter.search"
|
||||||
info="Search orders by id"
|
info="Search orders by ticket id"
|
||||||
vn-focus>
|
vn-focus>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
@ -51,8 +51,8 @@
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
label="Ticket id"
|
label="Order id"
|
||||||
ng-model="filter.ticketFk">
|
ng-model="filter.orderFk">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
|
|
|
@ -8,4 +8,4 @@ Application: Aplicación
|
||||||
SalesPerson: Comercial
|
SalesPerson: Comercial
|
||||||
Order confirmed: Pedido confirmado
|
Order confirmed: Pedido confirmado
|
||||||
Show empty: Mostrar vacías
|
Show empty: Mostrar vacías
|
||||||
Search orders by id: Buscar pedido por id
|
Search orders by ticket id: Buscar pedido por id ticket
|
|
@ -1,16 +1,28 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('loopback model Supplier-account', () => {
|
describe('loopback model Supplier-account', () => {
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
const supplierId = 1;
|
const supplierId = 1;
|
||||||
const bankEntityId = 2100;
|
const bankEntityId = 2100;
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 5},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
activeCtx.http.req.__ = value => {
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
it('should throw an error when attempting to set an invalid iban account', async() => {
|
it('should throw an error when attempting to set an invalid iban account', async() => {
|
||||||
let error;
|
let error;
|
||||||
const expectedError = 'The IBAN does not have the correct format';
|
const expectedError = 'The IBAN does not have the correct format';
|
||||||
const iban = 'incorrect format';
|
const iban = 'incorrect format';
|
||||||
try {
|
try {
|
||||||
await app.models.SupplierAccount.create(
|
await models.SupplierAccount.create(
|
||||||
{
|
{
|
||||||
supplierFk: supplierId,
|
supplierFk: supplierId,
|
||||||
bankEntityFk: bankEntityId,
|
bankEntityFk: bankEntityId,
|
||||||
|
@ -26,27 +38,16 @@ describe('loopback model Supplier-account', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a valid supplier account', async() => {
|
it('should create a valid supplier account', async() => {
|
||||||
const tx = await app.models.Claim.beginTransaction({});
|
const tx = await models.SupplierAccount.beginTransaction({});
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const iban = 'ES91 2100 0418 4502 0005 1332';
|
const iban = 'ES91 2100 0418 4502 0005 1332';
|
||||||
|
|
||||||
const activeCtx = {
|
|
||||||
accessToken: {userId: 5},
|
|
||||||
http: {
|
|
||||||
req: {
|
|
||||||
headers: {origin: 'http://localhost'}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
activeCtx.http.req.__ = value => {
|
|
||||||
return value;
|
|
||||||
};
|
|
||||||
|
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
active: activeCtx
|
active: activeCtx
|
||||||
});
|
});
|
||||||
const createdSupplierAccount = await app.models.SupplierAccount.create({
|
|
||||||
|
const createdSupplierAccount = await models.SupplierAccount.create({
|
||||||
supplierFk: supplierId,
|
supplierFk: supplierId,
|
||||||
bankEntityFk: bankEntityId,
|
bankEntityFk: bankEntityId,
|
||||||
iban: iban
|
iban: iban
|
||||||
|
@ -60,5 +61,35 @@ describe('loopback model Supplier-account', () => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should change isPayMethodChecked to false', async() => {
|
||||||
|
const tx = await models.SupplierAccount.beginTransaction({});
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const iban = 'ES91 2100 0418 4502 0005 1332';
|
||||||
|
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
|
||||||
|
const supplierBefore = await models.Supplier.findById(supplierId, null, options);
|
||||||
|
|
||||||
|
await models.SupplierAccount.create({
|
||||||
|
supplierFk: supplierId,
|
||||||
|
bankEntityFk: bankEntityId,
|
||||||
|
iban: iban
|
||||||
|
},
|
||||||
|
options);
|
||||||
|
|
||||||
|
const supplierAfter = await models.Supplier.findById(supplierId, null, options);
|
||||||
|
|
||||||
|
expect(supplierBefore.isPayMethodChecked).toBeTruthy();
|
||||||
|
expect(supplierAfter.isPayMethodChecked).toBeFalsy();
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,4 +34,15 @@ module.exports = Self => {
|
||||||
ctx.instance.iban + ', entidad: ' + bankEntity.name + ', bic: ' + bankEntity.bic
|
ctx.instance.iban + ', entidad: ' + bankEntity.name + ', bic: ' + bankEntity.bic
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Self.observe('after save', async ctx => {
|
||||||
|
const options = {};
|
||||||
|
|
||||||
|
if (ctx.options && ctx.options.transaction)
|
||||||
|
options.transaction = ctx.options.transaction;
|
||||||
|
const supplier = await Self.app.models.Supplier.findById(ctx.instance.supplierFk, null, options);
|
||||||
|
|
||||||
|
if (supplier.isPayMethodChecked)
|
||||||
|
await supplier.updateAttribute('isPayMethodChecked', false, options);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,6 +45,16 @@ class Controller extends Section {
|
||||||
this.$.payMethodToTransfer.show();
|
this.$.payMethodToTransfer.show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setWireTransfer() {
|
||||||
|
const params = {
|
||||||
|
id: this.$params.id,
|
||||||
|
payMethodFk: this.wireTransferFk
|
||||||
|
};
|
||||||
|
const query = `Suppliers/${this.$params.id}`;
|
||||||
|
return this.$http.patch(query, params)
|
||||||
|
.then(() => this.$.watcher.notifySaved());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnSupplierAccount', {
|
ngModule.vnComponent('vnSupplierAccount', {
|
||||||
|
|
|
@ -5,9 +5,12 @@ import crudModel from 'core/mocks/crud-model';
|
||||||
describe('Supplier Component vnSupplierAccount', () => {
|
describe('Supplier Component vnSupplierAccount', () => {
|
||||||
let $scope;
|
let $scope;
|
||||||
let controller;
|
let controller;
|
||||||
|
let $httpBackend;
|
||||||
|
|
||||||
beforeEach(ngModule('supplier'));
|
beforeEach(ngModule('supplier'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$scope.model = crudModel;
|
$scope.model = crudModel;
|
||||||
$scope.watcher = watcher;
|
$scope.watcher = watcher;
|
||||||
|
@ -66,5 +69,30 @@ describe('Supplier Component vnSupplierAccount', () => {
|
||||||
}).catch(done.fail);
|
}).catch(done.fail);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('setWireTransfer()', () => {
|
||||||
|
it(`should make HTTP PATCH request to set wire transfer and call notifySaved`, () => {
|
||||||
|
const supplierId = 1;
|
||||||
|
const params = {
|
||||||
|
id: supplierId,
|
||||||
|
payMethodFk: 2
|
||||||
|
};
|
||||||
|
const response = {
|
||||||
|
data: {id: 2}
|
||||||
|
};
|
||||||
|
const uri = 'payMethods/findOne?filter=%7B%22where%22:%7B%22code%22:%22wireTransfer%22%7D%7D';
|
||||||
|
jest.spyOn($scope.watcher, 'notifySaved');
|
||||||
|
|
||||||
|
controller.$params.id = supplierId;
|
||||||
|
controller.wireTransferFk = 2;
|
||||||
|
controller.supplier = {payMethodFk: 1};
|
||||||
|
$httpBackend.expectGET(uri).respond(response);
|
||||||
|
$httpBackend.expectPATCH(`Suppliers/${supplierId}`, params).respond();
|
||||||
|
controller.setWireTransfer();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect($scope.watcher.notifySaved).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ module.exports = Self => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const salesIds = [];
|
const salesIds = [];
|
||||||
const params = [];
|
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager');
|
const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager');
|
||||||
|
@ -50,23 +49,19 @@ module.exports = Self => {
|
||||||
if (!hasValidRole)
|
if (!hasValidRole)
|
||||||
throw new UserError(`You don't have privileges to create pay back`);
|
throw new UserError(`You don't have privileges to create pay back`);
|
||||||
|
|
||||||
sales.forEach(sale => {
|
for (let sale of sales)
|
||||||
salesIds.push(sale.id);
|
salesIds.push(sale.id);
|
||||||
params.push('?');
|
|
||||||
});
|
|
||||||
|
|
||||||
const paramsString = params.join();
|
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||||
CREATE TEMPORARY TABLE tmp.sale
|
CREATE TEMPORARY TABLE tmp.sale
|
||||||
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
||||||
FROM sale s
|
FROM sale s
|
||||||
WHERE s.id IN (${paramsString});
|
WHERE s.id IN (?);
|
||||||
CALL vn.ticket_doRefund(${ticketId}, @newTicket);
|
CALL vn.ticket_doRefund(?, @newTicket);
|
||||||
DROP TEMPORARY TABLE tmp.sale;`;
|
DROP TEMPORARY TABLE tmp.sale;`;
|
||||||
|
|
||||||
await Self.rawSql(query, salesIds, myOptions);
|
await Self.rawSql(query, [salesIds, ticketId], myOptions);
|
||||||
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
||||||
ticketId = newTicket.id;
|
ticketId = newTicket.id;
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const salesIds = [];
|
const salesIds = [];
|
||||||
const params = [];
|
for (let sale of sales)
|
||||||
sales.forEach(sale => {
|
|
||||||
salesIds.push(sale.id);
|
salesIds.push(sale.id);
|
||||||
params.push('?');
|
|
||||||
});
|
|
||||||
|
|
||||||
const isEditable = await models.Ticket.isEditable(ctx, sales[0].ticketFk, myOptions);
|
const isEditable = await models.Ticket.isEditable(ctx, sales[0].ticketFk, myOptions);
|
||||||
if (!isEditable)
|
if (!isEditable)
|
||||||
|
@ -49,14 +46,12 @@ module.exports = Self => {
|
||||||
if (!canEditSale)
|
if (!canEditSale)
|
||||||
throw new UserError(`Sale(s) blocked, please contact production`);
|
throw new UserError(`Sale(s) blocked, please contact production`);
|
||||||
|
|
||||||
const paramsString = params.join();
|
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales;
|
DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales;
|
||||||
CREATE TEMPORARY TABLE tmp.recalculateSales
|
CREATE TEMPORARY TABLE tmp.recalculateSales
|
||||||
SELECT s.id
|
SELECT s.id
|
||||||
FROM sale s
|
FROM sale s
|
||||||
WHERE s.id IN (${paramsString});
|
WHERE s.id IN (?);
|
||||||
CALL vn.sale_recalcComponent(null);
|
CALL vn.sale_recalcComponent(null);
|
||||||
DROP TEMPORARY TABLE tmp.recalculateSales;`;
|
DROP TEMPORARY TABLE tmp.recalculateSales;`;
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,12 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'started',
|
arg: 'started',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: 'The date calendar start',
|
description: 'The calendar date start',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'ended',
|
arg: 'ended',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: 'The date calendar end',
|
description: 'The calendar date end',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('getZoneClosing', {
|
||||||
|
description: 'Get zone events filtered for date and prioritized by type',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'zoneIds',
|
||||||
|
type: ['number'],
|
||||||
|
description: 'The zone ids',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'date',
|
||||||
|
type: 'date',
|
||||||
|
description: 'The calendar date',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/getZoneClosing`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getZoneClosing = async(zoneIds, date, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
query = `
|
||||||
|
SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
DISTINCT z.id,
|
||||||
|
z.name,
|
||||||
|
am.name agencyModeName,
|
||||||
|
IFNULL(ze.hour, z.hour) as hour,
|
||||||
|
IFNULL(ze.price, z.price) as price
|
||||||
|
FROM vn.zone z
|
||||||
|
JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||||
|
LEFT JOIN zoneEvent ze ON ze.zoneFk = z.id
|
||||||
|
WHERE
|
||||||
|
(
|
||||||
|
dated = ?
|
||||||
|
OR ? BETWEEN started AND ended
|
||||||
|
OR INSTR(weekDays, SUBSTRING(DAYNAME(?), 1, 3) ) > 0
|
||||||
|
)
|
||||||
|
AND z.id IN (?)
|
||||||
|
ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z
|
||||||
|
GROUP BY z.id`;
|
||||||
|
|
||||||
|
return Self.rawSql(query, [date, date, date, zoneIds], myOptions);
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,23 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('zone getZoneClosing()', () => {
|
||||||
|
it('should return closing time of zones', async() => {
|
||||||
|
const tx = await models.Zone.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const date = new Date();
|
||||||
|
const today = date.toISOString().split('T')[0];
|
||||||
|
|
||||||
|
const result = await models.Zone.getZoneClosing([1, 2, 3], today, options);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(3);
|
||||||
|
expect(result[0].hour).toBeDefined();
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -7,6 +7,7 @@ module.exports = Self => {
|
||||||
require('../methods/zone/getUpcomingDeliveries')(Self);
|
require('../methods/zone/getUpcomingDeliveries')(Self);
|
||||||
require('../methods/zone/deleteZone')(Self);
|
require('../methods/zone/deleteZone')(Self);
|
||||||
require('../methods/zone/includingExpired')(Self);
|
require('../methods/zone/includingExpired')(Self);
|
||||||
|
require('../methods/zone/getZoneClosing')(Self);
|
||||||
|
|
||||||
Self.validatesPresenceOf('agencyModeFk', {
|
Self.validatesPresenceOf('agencyModeFk', {
|
||||||
message: `Agency cannot be blank`
|
message: `Agency cannot be blank`
|
||||||
|
|
|
@ -52,23 +52,15 @@
|
||||||
</form>
|
</form>
|
||||||
</vn-side-menu>
|
</vn-side-menu>
|
||||||
|
|
||||||
<vn-crud-model vn-id="zoneModel"
|
|
||||||
url="Zones"
|
|
||||||
filter="::$ctrl.filter"
|
|
||||||
limit="20"
|
|
||||||
data="zones"
|
|
||||||
auto-load="false">
|
|
||||||
</vn-crud-model>
|
|
||||||
|
|
||||||
<!-- Zone Popover -->
|
<!-- Zone Popover -->
|
||||||
<vn-popover vn-id="zoneEvents">
|
<vn-popover vn-id="zoneEvents">
|
||||||
<div class="zoneEvents">
|
<div class="zoneEvents">
|
||||||
<div class="header vn-pa-sm" translate>Zones</div>
|
<div class="header vn-pa-sm" translate>Zones</div>
|
||||||
<vn-data-viewer
|
<vn-data-viewer
|
||||||
model="zoneModel"
|
data="::$ctrl.zoneClosing"
|
||||||
class="vn-w-md vn-mb-xl">
|
class="vn-w-md vn-mb-xl">
|
||||||
<vn-card>
|
<vn-card>
|
||||||
<vn-table model="zoneModel">
|
<vn-table>
|
||||||
<vn-thead>
|
<vn-thead>
|
||||||
<vn-tr>
|
<vn-tr>
|
||||||
<vn-th field="id" number>Id</vn-th>
|
<vn-th field="id" number>Id</vn-th>
|
||||||
|
@ -81,7 +73,7 @@
|
||||||
</vn-thead>
|
</vn-thead>
|
||||||
<vn-tbody>
|
<vn-tbody>
|
||||||
<vn-tr
|
<vn-tr
|
||||||
ng-repeat="zone in zoneModel.data"
|
ng-repeat="zone in $ctrl.zoneClosing"
|
||||||
ui-sref="zone.card.summary({id: zone.id})"
|
ui-sref="zone.card.summary({id: zone.id})"
|
||||||
class="clickable search-result">
|
class="clickable search-result">
|
||||||
<vn-td number>{{::zone.id}}</vn-td>
|
<vn-td number>{{::zone.id}}</vn-td>
|
||||||
|
|
|
@ -74,33 +74,14 @@ class Controller extends Section {
|
||||||
zonesIds.push(event.zoneFk);
|
zonesIds.push(event.zoneFk);
|
||||||
|
|
||||||
this.$.zoneEvents.show($event.target);
|
this.$.zoneEvents.show($event.target);
|
||||||
const zoneModel = this.$.zoneModel;
|
|
||||||
zoneModel.applyFilter({
|
const params = {
|
||||||
include: [
|
zonesId: zonesIds,
|
||||||
{
|
date: day
|
||||||
relation: 'agencyMode',
|
};
|
||||||
scope: {fields: ['name']}
|
|
||||||
},
|
this.$http.post(`Zones/getZoneClosing`, params)
|
||||||
{
|
.then(res => this.zoneClosing = res.data);
|
||||||
relation: 'events',
|
|
||||||
scope: {
|
|
||||||
where: {dated: day}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
where: {
|
|
||||||
id: {inq: zonesIds}
|
|
||||||
}
|
|
||||||
}).then(() => {
|
|
||||||
const data = zoneModel.data;
|
|
||||||
for (let row of data) {
|
|
||||||
const [event] = row.events;
|
|
||||||
if (event && event.hour)
|
|
||||||
row.hour = event.hour;
|
|
||||||
if (event && event.price)
|
|
||||||
row.price = event.price;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
preview(zone) {
|
preview(zone) {
|
||||||
|
|
|
@ -96,46 +96,31 @@ describe('Zone Component vnZoneDeliveryDays', () => {
|
||||||
expect(controller.$.zoneEvents.show).not.toHaveBeenCalled();
|
expect(controller.$.zoneEvents.show).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the show() method and then call the applyFilter() method with the expected ids', () => {
|
it('should call the show() method and call getZoneClosing() with the expected ids', () => {
|
||||||
const zoneModel = controller.$.zoneModel;
|
|
||||||
jest.spyOn(controller.$.zoneEvents, 'show');
|
jest.spyOn(controller.$.zoneEvents, 'show');
|
||||||
jest.spyOn(zoneModel, 'applyFilter').mockReturnValue(new Promise(resolve => {
|
|
||||||
zoneModel.data = [
|
|
||||||
{id: 1, events: [{price: 25}]}
|
|
||||||
];
|
|
||||||
}));
|
|
||||||
|
|
||||||
const event = new Event('click');
|
const event = new Event('click');
|
||||||
const target = document.createElement('div');
|
const target = document.createElement('div');
|
||||||
target.dispatchEvent(event);
|
target.dispatchEvent(event);
|
||||||
|
|
||||||
|
const day = new Date();
|
||||||
const events = [
|
const events = [
|
||||||
{zoneFk: 1},
|
{zoneFk: 1},
|
||||||
{zoneFk: 2},
|
{zoneFk: 2},
|
||||||
{zoneFk: 8}
|
{zoneFk: 8}
|
||||||
];
|
];
|
||||||
|
const params = {
|
||||||
const day = new Date();
|
zonesId: [1, 2, 8],
|
||||||
controller.onSelection(event, events, [day]);
|
date: [day][0]
|
||||||
const expectedFilter = {
|
|
||||||
include: [
|
|
||||||
{
|
|
||||||
relation: 'agencyMode',
|
|
||||||
scope: {fields: ['name']}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relation: 'events',
|
|
||||||
scope: {
|
|
||||||
where: {dated: day}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
where: {
|
|
||||||
id: {inq: [1, 2, 8]}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
const response = [{id: 1, hour: ''}];
|
||||||
|
|
||||||
|
$httpBackend.when('POST', 'Zones/getZoneClosing', params).respond({response});
|
||||||
|
controller.onSelection(event, events, [day]);
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target);
|
expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target);
|
||||||
expect(zoneModel.applyFilter).toHaveBeenCalledWith(expectedFilter);
|
expect(controller.zoneClosing.id).toEqual(response.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,6 +15,7 @@ vn-upcoming-deliveries {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
background-color: $color-bg;
|
||||||
}
|
}
|
||||||
|
|
||||||
vn-table vn-th.waste-family,
|
vn-table vn-th.waste-family,
|
||||||
|
|
Loading…
Reference in New Issue