Worker calendar rework #645

Merged
carlosjr merged 15 commits from 2567-calendar_rework into dev 2021-06-14 10:04:45 +00:00
6 changed files with 104 additions and 39 deletions
Showing only changes of commit 17a6dfc81b - Show all commits

View File

@ -2348,4 +2348,25 @@ INSERT INTO `vn`.`zoneAgencyMode`(`id`, `agencyModeFk`, `zoneFk`)
(1, 1, 1),
(2, 1, 2),
(3, 6, 5),
(4, 7, 1);
(4, 7, 1);
INSERT INTO `vn`.`expeditionTruck` (`id`, `ETD`, `description`)
VALUES
(1, CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL +3 YEAR))), 'Best truck in fleet');
INSERT INTO `vn`.`expeditionPallet` (`id`, `truckFk`, `built`, `position`, `isPrint`)
VALUES
(1, 1, CURDATE(), 1, 1);
INSERT INTO `vn`.`expeditionScan` (`id`, `expeditionFk`, `scanned`, `palletFk`)
VALUES
(1, 1, CURDATE(), 1),
(2, 2, CURDATE(), 1),
(3, 3, CURDATE(), 1),
(4, 4, CURDATE(), 1),
(5, 5, CURDATE(), 1),
(6, 6, CURDATE(), 1),
(7, 7, CURDATE(), 1),
(8, 8, CURDATE(), 1),
(9, 9, CURDATE(), 1),
(10, 10, CURDATE(), 1);

View File

@ -3,6 +3,7 @@ const LoopBackContext = require('loopback-context');
describe('route updateVolume()', () => {
const routeId = 1;
const ticketId = 14;
const userId = 50;
const activeCtx = {
accessToken: {userId: userId},
@ -13,31 +14,39 @@ describe('route updateVolume()', () => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
const route = await app.models.Route.findById(routeId);
expect(route.m3).toEqual(1.8);
const tx = await app.models.Ticket.beginTransaction({});
const ticket = await app.models.Ticket.findById(14);
await ticket.updateAttributes({routeFk: routeId});
await app.models.Route.updateVolume(ctx, routeId);
try {
const options = {transaction: tx};
const updatedRoute = await app.models.Route.findById(routeId);
const route = await app.models.Route.findById(routeId, null, options);
expect(updatedRoute.m3).not.toEqual(route.m3);
expect(route.m3).toEqual(1.8);
const logs = await app.models.RouteLog.find({fields: ['id', 'newInstance']});
const ticket = await app.models.Ticket.findById(ticketId, null, options);
await ticket.updateAttributes({routeFk: routeId}, options);
await app.models.Route.updateVolume(ctx, routeId, options);
const m3Log = logs.filter(log => {
if (log.newInstance)
return log.newInstance.m3 === updatedRoute.m3;
});
const logIdToDestroy = m3Log[0].id;
const updatedRoute = await app.models.Route.findById(routeId, null, options);
expect(m3Log.length).toEqual(1);
expect(updatedRoute.m3).not.toEqual(route.m3);
// restores
await ticket.updateAttributes({routeFk: null});
await route.updateAttributes({m3: 1.8});
await app.models.RouteLog.destroyById(logIdToDestroy);
const logs = await app.models.RouteLog.find({
fields: ['id', 'newInstance']
}, options);
const m3Log = logs.filter(log => {
if (log.newInstance)
return log.newInstance.m3 === updatedRoute.m3;
});
expect(m3Log.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -19,24 +19,44 @@ module.exports = Self => {
}
});
Self.updateVolume = async(ctx, id) => {
let query = `CALL vn.routeUpdateM3(?)`;
let userId = ctx.req.accessToken.userId;
let originalRoute = await Self.app.models.Route.findById(id);
Self.updateVolume = async(ctx, id, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
await Self.rawSql(query, [id]);
let updatedRoute = await Self.app.models.Route.findById(id);
let tx;
let myOptions = {};
let logRecord = {
originFk: id,
userFk: userId,
action: 'update',
changedModel: 'Route',
changedModelId: id,
oldInstance: {m3: originalRoute.m3},
newInstance: {m3: updatedRoute.m3}
};
if (typeof options == 'object')
Object.assign(myOptions, options);
return await Self.app.models.RouteLog.create(logRecord);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const originalRoute = await models.Route.findById(id, null, myOptions);
await Self.rawSql(`CALL vn.routeUpdateM3(?)`, [id], myOptions);
const updatedRoute = await models.Route.findById(id, null, myOptions);
await models.RouteLog.create({
originFk: id,
userFk: userId,
action: 'update',
changedModel: 'Route',
changedModelId: id,
oldInstance: {m3: originalRoute.m3},
newInstance: {m3: updatedRoute.m3}
}, myOptions);
if (tx) await tx.commit();
return updatedRoute;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -39,14 +39,19 @@ module.exports = Self => {
e.externalId,
i3.name packagingName,
i3.id packagingItemFk,
e.packagingFk
e.packagingFk,
es.workerFk expeditionScanWorkerFk,
su.nickname scannerUserNickname,
es.scanned
FROM
vn.expedition e
LEFT JOIN vn.item i2 ON i2.id = e.itemFk
LEFT JOIN vn.item i2 ON i2.id = e.itemFk
INNER JOIN vn.item i1 ON i1.id = e.isBox
LEFT JOIN vn.packaging p ON p.id = e.packagingFk
LEFT JOIN vn.item i3 ON i3.id = p.itemFk
LEFT JOIN account.user u ON u.id = e.workerFk
LEFT JOIN vn.expeditionScan es ON es.expeditionFk = e.id
LEFT JOIN account.user su ON su.id = es.workerFk
`);
stmt.merge(Self.buildSuffix(filter, 'e'));

View File

@ -19,8 +19,10 @@
<vn-th field="isBox">Package type</vn-th>
<vn-th field="counter" number>Counter</vn-th>
<vn-th field="externalId" number>externalId</vn-th>
<vn-th field="worker">Worker</vn-th>
<vn-th field="worker">Packager</vn-th>
<vn-th field="created" expand>Created</vn-th>
<vn-th field="scanned" expand>Scanned</vn-th>
<vn-th field="expeditionScanWorkerFk">Palletizer</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
@ -51,6 +53,12 @@
</span>
</vn-td>
<vn-td expand>{{::expedition.created | date:'dd/MM/yyyy HH:mm'}}</vn-td>
<vn-td expand>{{::expedition.scanned | date:'dd/MM/yyyy HH:mm'}}</vn-td>
<vn-td expand>
<span class="link" ng-click="workerDescriptor.show($event, expedition.expeditionScanWorkerFk)">
{{::expedition.scannerUserNickname | dashIfEmpty}}
</span>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>

View File

@ -78,4 +78,6 @@ Sale checked: Control clientes
Components: Componentes
Sale tracking: Líneas preparadas
Pictures: Fotos
Log: Historial
Log: Historial
Packager: Encajador
Palletizer: Palletizador