fix: refs #235425 sale priceFixed update #3146

Merged
guillermo merged 3 commits from hotfix235425-updatePrice into master 2024-10-28 06:06:58 +00:00
3 changed files with 37 additions and 1 deletions

View File

@ -85,6 +85,25 @@ describe('sale updatePrice()', () => {
}
});
it('should check if priceFixed has changed', async() => {
const tx = await models.Sale.beginTransaction({});
try {
const options = {transaction: tx};
const price = 3;
const beforeUpdate = await models.Sale.findById(saleId, null, options);
await models.Sale.updatePrice(ctx, saleId, price, options);
const afterUpdate = await models.Sale.findById(saleId, null, options);
expect(beforeUpdate.priceFixed).not.toEqual(afterUpdate.priceFixed);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should set price as a decimal number and check the sale has the mana component changing the salesPersonMana', async() => {
const tx = await models.Sale.beginTransaction({});

View File

@ -91,7 +91,21 @@ module.exports = Self => {
value: componentValue
}, myOptions);
}
await sale.updateAttributes({price: newPrice}, myOptions);
const [priceFixed] = await Self.rawSql(`
SELECT SUM(value) value
FROM sale s
JOIN saleComponent sc ON sc.saleFk = s.id
JOIN component c ON c.id = sc.componentFk
JOIN componentType ct ON ct.id = c.typeFk
WHERE ct.isBase
AND s.id = ?
`, [id], myOptions);
await sale.updateAttributes({
price: newPrice,
priceFixed: priceFixed.value
guillermo marked this conversation as resolved
Review

perfect, cal canviar el test de back per a que també verifique este canvi, simplement verifica que el valor antes i despues de cridar a la funcio son distints (chatgpt) 392c4dcba3

perfect, cal canviar el test de back per a que també verifique este canvi, simplement verifica que el valor antes i despues de cridar a la funcio son distints (chatgpt) https://gitea.verdnatura.es/verdnatura/salix/commit/392c4dcba3b1907b2ef49ee01bb3d17e8ca45811
}, myOptions);
await Self.rawSql('CALL vn.manaSpellersRequery(?)', [userId], myOptions);
await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions);

View File

@ -28,6 +28,9 @@
"discount": {
"type": "number"
},
"priceFixed": {
"type": "number"
},
"reserved": {
"type": "boolean"
},