diff --git a/db/changes/10100-allSaints/01-zone_getLanded.sql b/db/changes/10100-allSaints/01-zone_getLanded.sql
index fd3c6b6aa..a2bbe46a5 100644
--- a/db/changes/10100-allSaints/01-zone_getLanded.sql
+++ b/db/changes/10100-allSaints/01-zone_getLanded.sql
@@ -28,7 +28,7 @@ BEGIN
JOIN zone z ON z.id = zo.zoneFk
JOIN zoneWarehouse zw ON zw.zoneFk = z.id
WHERE agencyModeFk = vAgencyModeFk
- AND warehouseFk = vWarehouseFk;
+ AND zw.warehouseFk = vWarehouseFk;
DROP TEMPORARY TABLE
tmp.zone,
diff --git a/db/changes/10110-postCampaign/00-department_doCalc.sql b/db/changes/10110-postCampaign/00-department_doCalc.sql
new file mode 100644
index 000000000..7adeb30f0
--- /dev/null
+++ b/db/changes/10110-postCampaign/00-department_doCalc.sql
@@ -0,0 +1,3 @@
+USE `vn`;
+
+CREATE DEFINER=`root`@`%` EVENT `department_doCalc` ON SCHEDULE EVERY 15 SECOND STARTS '2019-11-15 00:00:00' ON COMPLETION PRESERVE ENABLE DO CALL vn.department_doCalc
\ No newline at end of file
diff --git a/modules/agency/back/methods/agency/getLanded.js b/modules/agency/back/methods/agency/getLanded.js
index cc2d0d8a1..6c5a5d911 100644
--- a/modules/agency/back/methods/agency/getLanded.js
+++ b/modules/agency/back/methods/agency/getLanded.js
@@ -47,6 +47,7 @@ module.exports = Self => {
let rsIndex = stmts.push(
`SELECT * FROM tmp.zoneGetLanded`) - 1;
+ stmts.push(`DROP TEMPORARY TABLE tmp.zoneGetLanded`);
let sql = ParameterizedSQL.join(stmts, ';');
let landed = await Self.rawStmt(sql);
diff --git a/modules/agency/back/methods/agency/specs/getLanded.spec.js b/modules/agency/back/methods/agency/specs/getLanded.spec.js
index 7582751cb..15c0f1ca9 100644
--- a/modules/agency/back/methods/agency/specs/getLanded.spec.js
+++ b/modules/agency/back/methods/agency/specs/getLanded.spec.js
@@ -1,8 +1,9 @@
const app = require('vn-loopback/server/server');
-// Petición #1848
-xdescribe('agency getLanded()', () => {
+
+describe('agency getLanded()', () => {
it('should return a landing date', async() => {
const shipped = new Date();
+ shipped.setDate(shipped.getDate() + 1);
const addressFk = 121;
const agencyModeFk = 7;
const warehouseFk = 1;
diff --git a/modules/agency/back/methods/agency/specs/getShipped.spec.js b/modules/agency/back/methods/agency/specs/getShipped.spec.js
index 44519e181..8f79dab3b 100644
--- a/modules/agency/back/methods/agency/specs/getShipped.spec.js
+++ b/modules/agency/back/methods/agency/specs/getShipped.spec.js
@@ -1,10 +1,9 @@
const app = require('vn-loopback/server/server');
-// Petición #1848
-
-xdescribe('agency getShipped()', () => {
+describe('agency getShipped()', () => {
it('should return a shipment date', async() => {
const landed = new Date();
+ landed.setDate(landed.getDate() + 1);
const addressFk = 121;
const agencyModeFk = 7;
const warehouseFk = 1;
diff --git a/modules/agency/back/methods/agency/specs/landsThatDay.spec.js b/modules/agency/back/methods/agency/specs/landsThatDay.spec.js
index 4c0235118..c6738afc3 100644
--- a/modules/agency/back/methods/agency/specs/landsThatDay.spec.js
+++ b/modules/agency/back/methods/agency/specs/landsThatDay.spec.js
@@ -1,6 +1,6 @@
const app = require('vn-loopback/server/server');
-// Petición #1848
-xdescribe('Agency landsThatDay()', () => {
+
+describe('Agency landsThatDay()', () => {
const today = new Date();
it('should return a list of agencies that can land a shipment on a day for an address', async() => {
let agencies = await app.models.Agency.landsThatDay(101, today);
diff --git a/modules/agency/back/methods/zone-calendar/removeByDate.js b/modules/agency/back/methods/zone-calendar/removeByDate.js
deleted file mode 100644
index f7871502e..000000000
--- a/modules/agency/back/methods/zone-calendar/removeByDate.js
+++ /dev/null
@@ -1,28 +0,0 @@
-module.exports = Self => {
- Self.remoteMethod('removeByDate', {
- description: 'Removes one or more delivery dates for a zone',
- accessType: 'WRITE',
- accepts: [{
- arg: 'zoneFk',
- type: 'Number',
- required: true,
- },
- {
- arg: 'dates',
- type: ['Date'],
- required: true,
- }],
- returns: {
- type: 'object',
- root: true
- },
- http: {
- path: `/removeByDate`,
- verb: 'POST'
- }
- });
-
- Self.removeByDate = (zoneFk, dates) => {
- return Self.destroyAll({zoneFk, delivered: {inq: dates}});
- };
-};
diff --git a/modules/agency/back/methods/zone/clone.js b/modules/agency/back/methods/zone/clone.js
index 3d0008a27..fcae904b5 100644
--- a/modules/agency/back/methods/zone/clone.js
+++ b/modules/agency/back/methods/zone/clone.js
@@ -31,7 +31,6 @@ module.exports = Self => {
fields: [
'name',
'hour',
- 'warehouseFk',
'agencyModeFk',
'travelingDays',
'price',
@@ -47,7 +46,8 @@ module.exports = Self => {
}, options);
// Find all original selected days
- const calendarDays = await models.ZoneCalendar.find({
+ const calendarDays = await models.ZoneEvent.find({
+ fields: {id: false},
where: {zoneFk: id}
}, options);
@@ -62,7 +62,7 @@ module.exports = Self => {
});
await models.ZoneIncluded.create(newIncludedGeo, options);
- await models.ZoneCalendar.create(newCalendayDays, options);
+ await models.ZoneEvent.create(newCalendayDays, options);
await tx.commit();
return newZone;
diff --git a/modules/agency/back/methods/zone/editPrices.js b/modules/agency/back/methods/zone/editPrices.js
deleted file mode 100644
index b0203dc4b..000000000
--- a/modules/agency/back/methods/zone/editPrices.js
+++ /dev/null
@@ -1,81 +0,0 @@
-const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
-
-module.exports = Self => {
- Self.remoteMethod('editPrices', {
- description: 'Changes the price and bonus of a delivery day',
- accessType: 'WRITE',
- accepts: [{
- arg: 'id',
- type: 'Number',
- description: 'The zone id',
- http: {source: 'path'}
- },
- {
- arg: 'delivered',
- type: 'Date',
- required: true,
- },
- {
- arg: 'price',
- type: 'Number',
- required: true,
- },
- {
- arg: 'bonus',
- type: 'Number',
- required: true,
- },
- {
- arg: 'option',
- type: 'String',
- required: true,
- }],
- returns: {
- type: 'object',
- root: true
- },
- http: {
- path: `/:id/editPrices`,
- verb: 'POST'
- }
- });
-
- Self.editPrices = async(id, delivered, price, bonus, option) => {
- const models = Self.app.models;
-
- let filter = {
- where: {
- zoneFk: id
- }
- };
-
- let where;
- let shouldPropagate = true;
-
- if (option == 'Only this day') {
- shouldPropagate = false;
- where = {delivered};
- } else if (option == 'From this day') {
- where = {
- delivered: {
- gte: delivered
- }
- };
- }
-
- filter = mergeFilters(filter, {where});
-
- const days = await models.ZoneCalendar.find(filter);
- const areAllFromSameZone = days.every(day => day.zoneFk === id);
-
- if (!areAllFromSameZone)
- throw new UserError('All delivery days must belong to the same zone');
-
- if (shouldPropagate) {
- const zone = await models.Zone.findById(id);
- zone.updateAttributes({price, bonus});
- }
-
- return models.ZoneCalendar.updateAll(filter.where, {price, bonus});
- };
-};
diff --git a/modules/agency/back/methods/zone/specs/editPrices.spec.js b/modules/agency/back/methods/zone/specs/editPrices.spec.js
deleted file mode 100644
index a9a2457ad..000000000
--- a/modules/agency/back/methods/zone/specs/editPrices.spec.js
+++ /dev/null
@@ -1,81 +0,0 @@
-const app = require('vn-loopback/server/server');
-// Petición #1848
-xdescribe('agency editPrices()', () => {
- const zoneId = 1;
- let originalZone;
-
- beforeAll(async done => {
- originalZone = await app.models.Zone.findById(zoneId);
- done();
- });
-
- afterAll(async done => {
- await await app.models.ZoneCalendar.updateAll({zoneFk: zoneId}, {
- price: originalZone.price,
- bonus: originalZone.bonus
- });
- done();
- });
-
- it('should apply price and bonus for a selected day', async() => {
- const delivered = new Date();
- delivered.setHours(0, 0, 0, 0);
- await app.models.Zone.editPrices(zoneId, delivered, 4.00, 2.00, 'Only this day');
-
- const editedDays = await app.models.ZoneCalendar.find({
- where: {
- zoneFk: zoneId,
- delivered: delivered
- }
- });
- const firstEditedDay = editedDays[0];
-
- expect(editedDays.length).toEqual(1);
- expect(firstEditedDay.price).toEqual(4.00);
- expect(firstEditedDay.bonus).toEqual(2.00);
- });
-
- it('should apply price and bonus for all delivery days starting from selected day', async() => {
- const delivered = new Date();
- delivered.setHours(0, 0, 0, 0);
- await app.models.Zone.editPrices(1, delivered, 5.50, 1.00, 'From this day');
-
- const editedDays = await app.models.ZoneCalendar.find({
- where: {
- zoneFk: zoneId,
- delivered: {
- gte: delivered
- }
- }
- });
- const firstEditedDay = editedDays[0];
- const lastEditedDay = editedDays[editedDays.length - 1];
-
- expect(editedDays.length).toEqual(5);
- expect(firstEditedDay.price).toEqual(5.50);
- expect(firstEditedDay.bonus).toEqual(1.00);
- expect(lastEditedDay.price).toEqual(5.50);
- expect(lastEditedDay.bonus).toEqual(1.00);
- });
-
- it('should apply price and bonus for all delivery days', async() => {
- const delivered = new Date();
- delivered.setHours(0, 0, 0, 0);
- await app.models.Zone.editPrices(1, delivered, 7.00, 0.00, 'All days');
-
- const editedDays = await app.models.ZoneCalendar.find({
- where: {
- zoneFk: zoneId
- }
- });
- const firstEditedDay = editedDays[0];
- const lastEditedDay = editedDays[editedDays.length - 1];
-
- expect(editedDays.length).toEqual(5);
- expect(firstEditedDay.price).toEqual(7.00);
- expect(firstEditedDay.bonus).toEqual(0.00);
- expect(lastEditedDay.price).toEqual(7.00);
- expect(lastEditedDay.bonus).toEqual(0.00);
- });
-});
-
diff --git a/modules/agency/back/model-config.json b/modules/agency/back/model-config.json
index aded3eb5d..cfdbb83d3 100644
--- a/modules/agency/back/model-config.json
+++ b/modules/agency/back/model-config.json
@@ -20,9 +20,6 @@
"ZoneExclusion": {
"dataSource": "vn"
},
- "ZoneCalendar": {
- "dataSource": "vn"
- },
"ZoneIncluded": {
"dataSource": "vn"
},
diff --git a/modules/agency/back/models/zone-calendar.js b/modules/agency/back/models/zone-calendar.js
deleted file mode 100644
index 871852882..000000000
--- a/modules/agency/back/models/zone-calendar.js
+++ /dev/null
@@ -1,3 +0,0 @@
-module.exports = Self => {
- require('../methods/zone-calendar/removeByDate')(Self);
-};
diff --git a/modules/agency/back/models/zone-calendar.json b/modules/agency/back/models/zone-calendar.json
deleted file mode 100644
index bed9a8011..000000000
--- a/modules/agency/back/models/zone-calendar.json
+++ /dev/null
@@ -1,32 +0,0 @@
-{
- "name": "ZoneCalendar",
- "base": "VnModel",
- "options": {
- "mysql": {
- "table": "zoneCalendar"
- }
- },
- "properties": {
- "zoneFk": {
- "id": true,
- "type": "Number"
- },
- "delivered": {
- "id": true,
- "type": "Date"
- },
- "price": {
- "type": "Number"
- },
- "bonus": {
- "type": "Number"
- }
- },
- "relations": {
- "zone": {
- "type": "belongsTo",
- "model": "Zone",
- "foreignKey": "zoneFk"
- }
- }
-}
\ No newline at end of file
diff --git a/modules/agency/back/models/zone.js b/modules/agency/back/models/zone.js
index 1f8b0a675..0c3ac24f6 100644
--- a/modules/agency/back/models/zone.js
+++ b/modules/agency/back/models/zone.js
@@ -1,6 +1,5 @@
module.exports = Self => {
require('../methods/zone/clone')(Self);
- require('../methods/zone/editPrices')(Self);
require('../methods/zone/getLeaves')(Self);
require('../methods/zone/getEvents')(Self);
require('../methods/zone/toggleIsIncluded')(Self);
diff --git a/modules/agency/front/edit/index.html b/modules/agency/front/edit/index.html
deleted file mode 100644
index f66c289ee..000000000
--- a/modules/agency/front/edit/index.html
+++ /dev/null
@@ -1,80 +0,0 @@
-