fix: only can exists 'mana' or 'manaClaim' discount. Never both
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
2455a11c26
commit
86b7e9cabe
|
@ -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;
|
||||
if (oldComponent) {
|
||||
const filter = {
|
||||
saleFk: sale.id,
|
||||
componentFk: oldComponent.componentFk
|
||||
};
|
||||
await models.SaleComponent.destroyAll(filter, myOptions);
|
||||
|
||||
newComponent = models.SaleComponent.create({
|
||||
saleFk: sale.id,
|
||||
value: value,
|
||||
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