4616-ticket.sale_mana #1088
|
@ -115,10 +115,43 @@ module.exports = Self => {
|
|||
for (let sale of sales) {
|
||||
const oldDiscount = sale.discount;
|
||||
const value = ((-sale.price * newDiscount) / 100);
|
||||
const newComponent = models.SaleComponent.upsert({
|
||||
saleFk: sale.id,
|
||||
value: value,
|
||||
componentFk: componentId}, myOptions);
|
||||
|
||||
const manaComponent = await models.Component.findOne({
|
||||
where: {code: 'mana'}
|
||||
}, myOptions);
|
||||
|
||||
const manaClaimComponent = await models.Component.findOne({
|
||||
where: {code: 'manaClaim'}
|
||||
}, myOptions);
|
||||
|
||||
const oldComponent = await models.SaleComponent.find({
|
||||
where: {
|
||||
and: [
|
||||
{saleFk: sale.id},
|
||||
{componentFk: {inq: [manaComponent.id, manaClaimComponent.id]}}
|
||||
]
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
let newComponent;
|
||||
vicent marked this conversation as resolved
Outdated
|
||||
if (oldComponent) {
|
||||
const filter = {
|
||||
saleFk: sale.id,
|
||||
componentFk: oldComponent.componentFk
|
||||
};
|
||||
await models.SaleComponent.destroyAll(filter, myOptions);
|
||||
vicent marked this conversation as resolved
Outdated
joan
commented
Asignar el resultado de esta función (Promesa) a una variable, y hacer el push al array. Asignar el resultado de esta función (Promesa) a una variable, y hacer el push al array.
|
||||
|
||||
newComponent = models.SaleComponent.create({
|
||||
saleFk: sale.id,
|
||||
value: value,
|
||||
vicent marked this conversation as resolved
Outdated
joan
commented
Esta linea está repetida en ambos casos, se puede extraer fuera del condicional Esta linea está repetida en ambos casos, se puede extraer fuera del condicional
|
||||
componentFk: componentId
|
||||
}, myOptions);
|
||||
} else {
|
||||
newComponent = models.SaleComponent.create({
|
||||
saleFk: sale.id,
|
||||
value: value,
|
||||
componentFk: componentId}, myOptions);
|
||||
}
|
||||
|
||||
const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
No utilizar variables globales, es más dificil de hacer seguimiento