3811-ticket.sale_updatePrice #1099

Merged
vicent merged 14 commits from 3811-ticket.sale_updatePrice into dev 2022-11-02 14:03:53 +00:00
2 changed files with 16 additions and 3 deletions
Showing only changes of commit 29093d7d30 - Show all commits

View File

@ -79,10 +79,19 @@ describe('sale updatePrice()', () => {
const price = 5.4; const price = 5.4;
const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options); const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options);
const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options); const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options);
const teamCLopez = 96;
vicent marked this conversation as resolved Outdated
Outdated
Review

Utilizar datos genéricos

Utilizar datos genéricos
const userId = 18;
await models.Sale.rawSql(`UPDATE vn.business b
JOIN vn.department d ON d.id = b.departmentFk
SET b.departmentFk = ?
WHERE b.id = ?`, [teamCLopez, userId]);
await models.Sale.updatePrice(ctx, saleId, price, options); await models.Sale.updatePrice(ctx, saleId, price, options);
const updatedSale = await models.Sale.findById(saleId, null, options); const updatedSale = await models.Sale.findById(saleId, null, options);
createdSaleComponent = await models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponent.id}}, options); const createdSaleComponent = await models.SaleComponent.findOne({
where: {
saleFk: saleId, componentFk: manaComponent.id
}}, options);
expect(updatedSale.price).toBe(price); expect(updatedSale.price).toBe(price);
expect(createdSaleComponent.value).toEqual(-2.04); expect(createdSaleComponent.value).toEqual(-2.04);

View File

@ -77,7 +77,12 @@ module.exports = Self => {
const oldPrice = sale.price; const oldPrice = sale.price;
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const usesMana = await models.WorkerMana.findOne({where: {workerFk: userId}, fields: 'amount'}, myOptions);
const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions);
const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions);
const workerDepartment = await models.WorkerDepartment.findById(userId);
const usesMana = departments.find(department => department.id == workerDepartment.departmentFk);
const componentCode = usesMana ? 'mana' : 'buyerDiscount'; const componentCode = usesMana ? 'mana' : 'buyerDiscount';
const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions); const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions);
const componentId = discount.id; const componentId = discount.id;
@ -88,7 +93,6 @@ module.exports = Self => {
saleFk: id saleFk: id
}; };
const saleComponent = await models.SaleComponent.findOne({where}, myOptions); const saleComponent = await models.SaleComponent.findOne({where}, myOptions);
if (saleComponent) { if (saleComponent) {
await models.SaleComponent.updateAll(where, { await models.SaleComponent.updateAll(where, {
value: saleComponent.value + componentValue value: saleComponent.value + componentValue