feat: refs #6897 add recalcEntryPrices method and enhance ACL permissions for entry operations
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
ef5c2ab3a2
commit
e7dd1f6a58
|
@ -168,6 +168,7 @@
|
|||
"emailVerified",
|
||||
"twoFactor"
|
||||
]
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Entry','getBuyList','READ','ALLOW','ROLE','buyer'),
|
||||
('Entry','getBuyUltimate','READ','ALLOW','ROLE','buyer'),
|
||||
('Entry','create','WRITE','ALLOW','ROLE','buyer'),
|
||||
('Entry','cloneEntry','WRITE','ALLOW','ROLE','buyer'),
|
||||
('Entry','deleteEntry','WRITE','ALLOW','ROLE','buyer'),
|
||||
('Entry','recalcEntryPrices','WRITE','ALLOW','ROLE','buyer'),
|
||||
('EntryType','find','READ','ALLOW','ROLE','buyer'),
|
||||
('EntryConfig','findOne','READ','ALLOW','ROLE','buyer');
|
||||
|
||||
|
|
|
@ -136,6 +136,18 @@ module.exports = Self => {
|
|||
description: 'company name',
|
||||
http: {source: 'query'}
|
||||
},
|
||||
{
|
||||
arg: 'workerFk',
|
||||
type: 'number',
|
||||
description: 'buyer id',
|
||||
http: {source: 'query'}
|
||||
},
|
||||
{
|
||||
arg: 'itemTypeFk',
|
||||
type: 'number',
|
||||
description: 'item family id',
|
||||
http: {source: 'query'}
|
||||
},
|
||||
{
|
||||
arg: 'groupBy',
|
||||
type: 'string',
|
||||
|
@ -182,6 +194,8 @@ module.exports = Self => {
|
|||
case 'price3':
|
||||
case 'packingOut':
|
||||
case 'minPrice':
|
||||
case 'workerFk':
|
||||
case 'itemTypeFk':
|
||||
return {[param]: value};
|
||||
}
|
||||
});
|
||||
|
@ -227,7 +241,10 @@ module.exports = Self => {
|
|||
i.tag10,
|
||||
i.value10,
|
||||
s.company_name,
|
||||
ik.hexJson`;
|
||||
ik.hexJson,
|
||||
it.workerFk,
|
||||
it.id itemTypeFk
|
||||
`;
|
||||
|
||||
const groupByFields = `SUM(b.printedStickers) printedStickers,
|
||||
SUM(b.packing) packing,
|
||||
|
@ -249,6 +266,7 @@ module.exports = Self => {
|
|||
LEFT JOIN buy b ON b.itemFk = i.id
|
||||
LEFT JOIN edi.ekt e ON e.id = b.ektFk
|
||||
LEFT JOIN edi.supplier s ON e.pro = s.supplier_id
|
||||
LEFT JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE b.entryFk = ?
|
||||
${groupBy ?? ''}
|
||||
) sub`,
|
||||
|
@ -266,7 +284,6 @@ module.exports = Self => {
|
|||
const buysChecked = buys.filter(buy => buy?.isChecked);
|
||||
result[0].isChecked = buysChecked.length === buys.length;
|
||||
}
|
||||
console.log('id:', entryFk);
|
||||
return itemsIndex === 0 ? result : result[itemsIndex];
|
||||
};
|
||||
};
|
||||
|
|
|
@ -32,6 +32,15 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
return Self.rawSql('CALL vn.buy_getUltimate(?, ?, ?)', [itemFk, warehouseFk, date], myOptions);
|
||||
await Self.rawSql('CALL vn.buy_getUltimate(?, ?, ?)', [itemFk, warehouseFk, date], myOptions);
|
||||
return Self.rawSql(
|
||||
`SELECT b.*
|
||||
FROM cache.last_buy lb
|
||||
JOIN buy b ON b.id = lb.buy_id
|
||||
WHERE lb.item_id = ?
|
||||
ORDER BY (lb.warehouse_id = ?) desc
|
||||
LIMIT 1`,
|
||||
[itemFk, warehouseFk], myOptions
|
||||
);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -35,7 +35,6 @@ module.exports = Self => {
|
|||
|
||||
try {
|
||||
result = await Self.rawSql('CALL entry_clone(?)', [id], myOptions);
|
||||
console.log('result: ', result);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return result[0];
|
||||
|
|
|
@ -30,7 +30,6 @@ module.exports = Self => {
|
|||
|
||||
try {
|
||||
const entry = await Self.findById(id, null, myOptions);
|
||||
console.log('entry: ', entry);
|
||||
await entry.updateAttribute('travelFk', null, myOptions);
|
||||
await Self.rawSql('DELETE FROM vn.duaEntry WHERE entryFk = ?;', [id], myOptions);
|
||||
await Self.rawSql(`
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('recalcEntryPrices', {
|
||||
description: 'Clones an entry',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'entryFk',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The entry id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:entryFk/recalcEntryPrices`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.recalcEntryPrices = async(ctx, entryFk, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {userId};
|
||||
let tx;
|
||||
let result;
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
const entry = await Self.findById(entryFk, myOptions);
|
||||
const entryConfig = await Self.app.models.EntryConfig.findOne(myOptions);
|
||||
|
||||
if (entry.supplierFk === entryConfig.inventorySupplierFk) return;
|
||||
|
||||
try {
|
||||
result = await Self.rawSql('CALL vn.buy_recalcPricesByEntry(?)', [entryFk], myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return result[0];
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -18,6 +18,7 @@ module.exports = Self => {
|
|||
require('../methods/entry-buys/getBuyUltimate')(Self);
|
||||
require('../methods/entry/cloneEntry')(Self);
|
||||
require('../methods/entry/deleteEntry')(Self);
|
||||
require('../methods/entry/recalcEntryPrices')(Self);
|
||||
|
||||
Self.observe('before save', async(ctx, options) => {
|
||||
if (ctx.isNewInstance) return;
|
||||
|
|
|
@ -67,6 +67,12 @@
|
|||
},
|
||||
"invoiceAmount": {
|
||||
"type": "number"
|
||||
},
|
||||
"lockerUserFk":{
|
||||
"type": "number"
|
||||
},
|
||||
"locked":{
|
||||
"type": "date"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
@ -105,6 +111,11 @@
|
|||
"type": "belongsTo",
|
||||
"model": "InvoiceIn",
|
||||
"foreignKey": "invoiceInFk"
|
||||
}
|
||||
},
|
||||
"user": {
|
||||
"type": "belongsTo",
|
||||
"model": "VnUser",
|
||||
"foreignKey": "lockerUserFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue