refs #6276 saleTrackingReplace
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
e27bf2ef8b
commit
8acd03f115
|
@ -5,4 +5,5 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
|
|||
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','employee'),
|
||||
('MachineWorker','add','READ','ALLOW','ROLE','employee'),
|
||||
('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','employee'),
|
||||
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee');
|
||||
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee'),
|
||||
('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','employee');
|
|
@ -0,0 +1,100 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateTracking', {
|
||||
description: 'Modify a saleTracking record and, if applicable, add a corresponding record in saleBuy.',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'saleFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'originalQuantity',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'code',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'isChecked',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'buyFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'isScanned',
|
||||
type: 'number',
|
||||
},
|
||||
],
|
||||
http: {
|
||||
path: `/updateTracking`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateTracking = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const state = await models.State.findOne({
|
||||
where: {code},
|
||||
}, myOptions);
|
||||
|
||||
const attributes = {
|
||||
saleFk,
|
||||
isChecked,
|
||||
originalQuantity,
|
||||
workerFk: userId,
|
||||
stateFk: state.id,
|
||||
isScanned,
|
||||
};
|
||||
|
||||
const saleTracking = await models.SaleTracking.findOne({
|
||||
where: attributes,
|
||||
}, myOptions);
|
||||
|
||||
if (!saleTracking)
|
||||
await models.SaleTracking.create(attributes, myOptions);
|
||||
|
||||
else
|
||||
await saleTracking.updateAttributes(attributes, myOptions);
|
||||
|
||||
let isBuy;
|
||||
if (buyFk) {
|
||||
isBuy = await models.Buy.findOne({
|
||||
where: {
|
||||
id: buyFk,
|
||||
itemOriginalFk: {
|
||||
neq: null
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (isBuy)
|
||||
await models.SaleBuy.create({saleFk, buyFk}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -65,6 +65,9 @@
|
|||
"SaleTracking": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"SaleBuy": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"State": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "SaleBuy",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "saleBuy"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"saleFk": {
|
||||
"id": true,
|
||||
"type": "number",
|
||||
"forceId": false
|
||||
},
|
||||
"buyFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"created": {
|
||||
"type": "date"
|
||||
},
|
||||
"isChecked": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"sale": {
|
||||
"type": "belongsTo",
|
||||
"model": "Sale",
|
||||
"foreignKey": "saleFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,4 +3,5 @@ module.exports = Self => {
|
|||
require('../methods/sale-tracking/listSaleTracking')(Self);
|
||||
require('../methods/sale-tracking/new')(Self);
|
||||
require('../methods/sale-tracking/delete')(Self);
|
||||
require('../methods/sale-tracking/updateTracking')(Self);
|
||||
};
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
},
|
||||
"originalQuantity": {
|
||||
"type": "number"
|
||||
},
|
||||
"isScanned": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
Loading…
Reference in New Issue