Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into test
This commit is contained in:
commit
75d0c298a1
|
@ -0,0 +1,18 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert`
|
||||
AFTER INSERT ON `itemShelving`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO itemShelvingLog
|
||||
SET itemShelvingFk = NEW.id,
|
||||
workerFk = account.myUser_getId(),
|
||||
accion = 'CREA REGISTRO',
|
||||
itemFk = NEW.itemFk,
|
||||
shelvingFk = NEW.shelvingFk,
|
||||
visible = NEW.visible,
|
||||
`grouping` = NEW.`grouping`,
|
||||
packing = NEW.packing,
|
||||
available = NEW.available;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,32 @@
|
|||
-- Place your SQL code here
|
||||
-- vn.priceDelta definition
|
||||
|
||||
CREATE OR REPLACE TABLE vn.priceDelta (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`itemTypeFk` smallint(5) unsigned NOT NULL,
|
||||
`minSize` int(10) unsigned DEFAULT NULL COMMENT 'Minimum item.size',
|
||||
`maxSize` int(10) unsigned DEFAULT NULL COMMENT 'Maximum item.size',
|
||||
`inkFk` varchar(3) DEFAULT NULL,
|
||||
`originFk` tinyint(2) unsigned DEFAULT NULL,
|
||||
`producerFk` mediumint(3) unsigned DEFAULT NULL,
|
||||
`fromDated` date DEFAULT NULL,
|
||||
`toDated` date DEFAULT NULL,
|
||||
`absIncreasing` decimal(10,3) DEFAULT NULL COMMENT 'Absolute increasing of final price',
|
||||
`ratIncreasing` int(11) DEFAULT NULL COMMENT 'Increasing ratio for the cost price',
|
||||
`warehouseFk` smallint(6) unsigned NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`editorFk` int(10) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `priceDelta_itemType_FK` (`itemTypeFk`),
|
||||
KEY `priceDelta_ink_FK` (`inkFk`),
|
||||
KEY `priceDelta_producer_FK` (`producerFk`),
|
||||
KEY `priceDelta_warehouse_FK` (`warehouseFk`),
|
||||
KEY `priceDelta_worker_FK` (`editorFk`),
|
||||
CONSTRAINT `priceDelta_ink_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_itemType_FK` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_producer_FK` FOREIGN KEY (`producerFk`) REFERENCES `producer` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_warehouse_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_worker_FK` FOREIGN KEY (`editorFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Defines the increasing o decreasing for ranges of items';
|
||||
|
||||
GRANT INSERT, SELECT, UPDATE, DELETE ON TABLE vn.priceDelta TO buyer;
|
|
@ -57,7 +57,7 @@ export default class App {
|
|||
|
||||
getUrl(route, appName = 'lilium') {
|
||||
const index = window.location.hash.indexOf(route.toLowerCase());
|
||||
const newRoute = index < 0 ? route : window.location.hash.substring(index);
|
||||
let newRoute = index < 0 ? route : window.location.hash.substring(index);
|
||||
const env = process.env.NODE_ENV;
|
||||
const filter = {
|
||||
where: {and: [
|
||||
|
@ -66,6 +66,11 @@ export default class App {
|
|||
]}
|
||||
};
|
||||
|
||||
|
||||
if (this.logger.$params.q)
|
||||
newRoute = newRoute.concat(`?table=${this.logger.$params.q}`);
|
||||
|
||||
|
||||
return this.logger.$http.get('Urls/findOne', {filter})
|
||||
.then(res => {
|
||||
if (res && res.data)
|
||||
|
|
|
@ -239,5 +239,6 @@
|
|||
"Original invoice not found": "Original invoice not found",
|
||||
"There is already a tray with the same height": "There is already a tray with the same height",
|
||||
"The height must be greater than 50cm": "The height must be greater than 50cm",
|
||||
"The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm"
|
||||
"The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm",
|
||||
"The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line"
|
||||
}
|
||||
|
|
|
@ -377,5 +377,6 @@
|
|||
"This ticket is not allocated to your department": "Este ticket no está asignado a tu departamento",
|
||||
"There is already a tray with the same height": "Ya existe una bandeja con la misma altura",
|
||||
"The height must be greater than 50cm": "La altura debe ser superior a 50cm",
|
||||
"The maximum height of the wagon is 200cm": "La altura máxima es 200cm"
|
||||
"The maximum height of the wagon is 200cm": "La altura máxima es 200cm",
|
||||
"The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea"
|
||||
}
|
||||
|
|
|
@ -361,6 +361,6 @@
|
|||
"The invoices have been created but the PDFs could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré",
|
||||
"It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré",
|
||||
"Cannot send mail": "Impossible d'envoyer le mail",
|
||||
"Original invoice not found": "Facture originale introuvable"
|
||||
|
||||
"Original invoice not found": "Facture originale introuvable",
|
||||
"The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne"
|
||||
}
|
||||
|
|
|
@ -361,5 +361,6 @@
|
|||
"The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado",
|
||||
"It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso",
|
||||
"Original invoice not found": "Fatura original não encontrada",
|
||||
"Cannot send mail": "Não é possível enviar o email"
|
||||
"Cannot send mail": "Não é possível enviar o email",
|
||||
"The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('ClaimBeginning model()', () => {
|
||||
const claimFk = 1;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 18},
|
||||
headers: {origin: 'localhost:5000'},
|
||||
__: () => {}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
});
|
||||
|
||||
it('should change quantity claimed', async() => {
|
||||
const tx = await models.ClaimBeginning.beginTransaction({});
|
||||
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const claim = await models.ClaimBeginning.findOne({where: {claimFk}}, options);
|
||||
const sale = await models.Sale.findById(claim.saleFk, {}, options);
|
||||
await claim.updateAttribute('quantity', sale.quantity - 1, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should throw error when quantity claimed is greater than quantity of the sale', async() => {
|
||||
const tx = await models.ClaimBeginning.beginTransaction({});
|
||||
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const claim = await models.ClaimBeginning.findOne({where: {claimFk}}, options);
|
||||
const sale = await models.Sale.findById(claim.saleFk, {}, options);
|
||||
await claim.updateAttribute('quantity', sale.quantity + 1, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error.toString()).toContain('The quantity claimed cannot be greater than the quantity of the line');
|
||||
});
|
||||
});
|
|
@ -10,16 +10,21 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.observe('before save', async ctx => {
|
||||
const options = ctx.options;
|
||||
const models = Self.app.models;
|
||||
const saleFk = ctx?.currentInstance?.saleFk || ctx?.instance?.saleFk;
|
||||
const sale = await models.Sale.findById(saleFk, {fields: ['ticketFk', 'quantity']}, options);
|
||||
|
||||
if (ctx.isNewInstance) {
|
||||
const models = Self.app.models;
|
||||
const options = ctx.options;
|
||||
const instance = ctx.instance;
|
||||
const ticket = await models.Sale.findById(instance.saleFk, {fields: ['ticketFk']}, options);
|
||||
const claim = await models.Claim.findById(instance.claimFk, {fields: ['ticketFk']}, options);
|
||||
if (ticket.ticketFk != claim.ticketFk)
|
||||
const claim = await models.Claim.findById(ctx.instance.claimFk, {fields: ['ticketFk']}, options);
|
||||
if (sale.ticketFk != claim.ticketFk)
|
||||
throw new UserError(`Cannot create a new claimBeginning from a different ticket`);
|
||||
}
|
||||
|
||||
await claimIsEditable(ctx);
|
||||
|
||||
if (sale?.quantity && ctx.data?.quantity && ctx.data.quantity > sale?.quantity)
|
||||
throw new UserError('The quantity claimed cannot be greater than the quantity of the line');
|
||||
});
|
||||
|
||||
Self.observe('before delete', async ctx => {
|
||||
|
|
|
@ -38,9 +38,13 @@ module.exports = Self => {
|
|||
|
||||
const itemShelving = itemShelvingSale.itemShelving();
|
||||
const quantity = itemShelving.visible + itemShelvingSale.quantity;
|
||||
const available = itemShelving.available + itemShelvingSale.quantity;
|
||||
|
||||
await itemShelving.updateAttributes(
|
||||
{visible: quantity},
|
||||
{
|
||||
visible: quantity,
|
||||
available: available
|
||||
},
|
||||
myOptions
|
||||
);
|
||||
if (tx) await tx.commit();
|
||||
|
|
|
@ -75,7 +75,11 @@ module.exports = Self => {
|
|||
|
||||
const itemShelving = await models.ItemShelving.findById(itemShelvingFk, null, myOptions);
|
||||
|
||||
await itemShelving.updateAttributes({visible: itemShelving.visible - quantity}, myOptions);
|
||||
await itemShelving.updateAttributes(
|
||||
{
|
||||
visible: itemShelving.visible - quantity,
|
||||
available: itemShelving.available - quantity
|
||||
}, myOptions);
|
||||
|
||||
await Self.updateAll(
|
||||
{saleFk},
|
||||
|
|
Loading…
Reference in New Issue