feat: en vez de consultar si el usuario está en la tabla workerMana, consultar es si el usuario está en un departamento que cuelga de ventas
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
7d502c6f57
commit
29093d7d30
|
@ -79,10 +79,19 @@ describe('sale updatePrice()', () => {
|
|||
const price = 5.4;
|
||||
const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options);
|
||||
const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options);
|
||||
const teamCLopez = 96;
|
||||
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);
|
||||
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(createdSaleComponent.value).toEqual(-2.04);
|
||||
|
|
|
@ -77,7 +77,12 @@ module.exports = Self => {
|
|||
|
||||
const oldPrice = sale.price;
|
||||
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 discount = await models.Component.findOne({where: {code: componentCode}}, myOptions);
|
||||
const componentId = discount.id;
|
||||
|
@ -88,7 +93,6 @@ module.exports = Self => {
|
|||
saleFk: id
|
||||
};
|
||||
const saleComponent = await models.SaleComponent.findOne({where}, myOptions);
|
||||
|
||||
if (saleComponent) {
|
||||
await models.SaleComponent.updateAll(where, {
|
||||
value: saleComponent.value + componentValue
|
||||
|
|
Loading…
Reference in New Issue