This commit is contained in:
parent
e15d724db5
commit
cf527dd8be
|
@ -0,0 +1,54 @@
|
|||
ALTER TABLE `vn`.`entry` ADD observationEditorFk INT(10) unsigned NULL COMMENT 'Último usuario que ha modificado el campo evaNotes';
|
||||
ALTER TABLE `vn`.`entry` ADD CONSTRAINT entry_observationEditorFk FOREIGN KEY (observationEditorFk) REFERENCES account.user(id) ON UPDATE CASCADE;
|
||||
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
VIEW `vn2008`.`entrySource` AS
|
||||
select
|
||||
`e`.`gestDocFk` AS `gestdoc_id`,
|
||||
`e`.`id` AS `Id_Entrada`,
|
||||
`e`.`invoiceNumber` AS `invoiceNumber`,
|
||||
`e`.`reference` AS `reference`,
|
||||
`e`.`isExcludedFromAvailable` AS `Inventario`,
|
||||
`e`.`notes` AS `observaciones`,
|
||||
`e`.`isConfirmed` AS `Confirmada`,
|
||||
`e`.`isOrdered` AS `Pedida`,
|
||||
`e`.`isRaid` AS `Redada`,
|
||||
`e`.`evaNotes` AS `notas`,
|
||||
`e`.`supplierFk` AS `Id_Proveedor`,
|
||||
`tr`.`shipped` AS `shipment`,
|
||||
`tr`.`landed` AS `landing`,
|
||||
`w2`.`name` AS `wh_in`,
|
||||
`w1`.`name` AS `wh_out`,
|
||||
`am`.`name` AS `Agencia`,
|
||||
`e`.`commission` AS `comision`,
|
||||
`tr`.`warehouseInFk` AS `warehouse_id`,
|
||||
`w1`.`id` AS `warehouse_id_out`,
|
||||
`e`.`isBooked` AS `anotadoencaja`,
|
||||
`e`.`invoiceInFk` AS `invoiceInFk`,
|
||||
`e`.`companyFk` AS `empresa_id`,
|
||||
`e`.`currencyFk` AS `Id_Moneda`,
|
||||
`tr`.`id` AS `TravelFk`,
|
||||
`e`.`sub` AS `sub`,
|
||||
`e`.`kop` AS `kop`,
|
||||
`e`.`pro` AS `pro`,
|
||||
`e`.`invoiceAmount` AS `invoiceAmount`,
|
||||
`w`.`code` AS `buyerCode`,
|
||||
`e`.`typeFk` AS `typeFk`,
|
||||
`w3`.`code` AS `observationWorkerCode`
|
||||
from
|
||||
(((((((`vn`.`entry` `e`
|
||||
left join `vn`.`travel` `tr` on
|
||||
(`e`.`travelFk` = `tr`.`id`))
|
||||
left join `vn`.`agencyMode` `am` on
|
||||
(`am`.`id` = `tr`.`agencyModeFk`))
|
||||
left join `vn`.`warehouse` `w1` on
|
||||
(`tr`.`warehouseOutFk` = `w1`.`id`))
|
||||
left join `vn`.`warehouse` `w2` on
|
||||
(`tr`.`warehouseInFk` = `w2`.`id`))
|
||||
left join `vn`.`supplier` `s` on
|
||||
(`e`.`supplierFk` = `s`.`id`))
|
||||
left join `vn`.`worker` `w` on
|
||||
(`w`.`id` = `e`.`buyerFk`))
|
||||
left join `vn`.`worker` `w3` on
|
||||
(`w3`.`id` = `e`.`observationEditorFk`));
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.rewriteDbError(function(err) {
|
||||
|
@ -6,4 +7,29 @@ module.exports = Self => {
|
|||
return new UserError(`The observation type can't be repeated`);
|
||||
return err;
|
||||
});
|
||||
|
||||
Self.observe('before save', async function(ctx, options) {
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
const userId = loopBackContext.active.accessToken.userId;
|
||||
const entryId = ctx.instance.entryFk;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const entry = await Self.app.models.Entry.findOne({where: {id: entryId}}, myOptions);
|
||||
await entry.updateAttribute('observationEditorFk', userId, myOptions);
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -77,6 +77,9 @@
|
|||
"companyFk": {
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
"observationEditorFk": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
@ -99,6 +102,11 @@
|
|||
"type": "belongsTo",
|
||||
"model": "Currency",
|
||||
"foreignKey": "currencyFk"
|
||||
},
|
||||
"observationEditor": {
|
||||
"type": "belongsTo",
|
||||
"model": "Account",
|
||||
"foreignKey": "observationEditorFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue