diff --git a/admin/src/app/home/orders/stock-orders/receive/receive.component.html b/admin/src/app/home/orders/stock-orders/receive/receive.component.html
index 174b3f51..c75a2b58 100644
--- a/admin/src/app/home/orders/stock-orders/receive/receive.component.html
+++ b/admin/src/app/home/orders/stock-orders/receive/receive.component.html
@@ -55,6 +55,14 @@
+
+
+
+
+
diff --git a/admin/src/app/home/orders/stock-orders/receive/receive.component.ts b/admin/src/app/home/orders/stock-orders/receive/receive.component.ts
index 554d3889..bd6082ad 100644
--- a/admin/src/app/home/orders/stock-orders/receive/receive.component.ts
+++ b/admin/src/app/home/orders/stock-orders/receive/receive.component.ts
@@ -538,6 +538,18 @@ export class ReceiveComponent implements OnInit, OnDestroy {
})
}
+ regenerateOrder(){
+ this.loading = true;
+ this.orgModelApi.regenerateOrder(this.userProfile.orgModelId, this.order.id).subscribe((data)=>{
+ this.loading = false;
+ this.toastr.info('Regenerating Order...');
+ this._router.navigate(['/orders/stock-orders']);
+ }, err=>{
+ this.loading = false;
+ console.log(err);
+ });
+ }
+
ngOnDestroy(): void {
this.subscriptions.forEach(subscription => {
if (subscription) {
diff --git a/common/models/org-model.js b/common/models/org-model.js
index 6350e870..697a06ff 100644
--- a/common/models/org-model.js
+++ b/common/models/org-model.js
@@ -1000,6 +1000,28 @@ module.exports = function (OrgModel) {
});
};
+ OrgModel.remoteMethod('regenerateOrder', {
+ accepts: [
+ {arg: 'id', type: 'string', required: true},
+ {arg: 'reportModelId', type: 'string', required: true},
+ {arg: 'options', type: 'object', http: 'optionsFromRequest'}
+ ],
+ http: { path: '/:id/regenerateOrder', verb: 'put'},
+ returns: { arg: 'regenerateOrderInstance', type: 'object', root: true}
+ });
+
+ OrgModel.regenerateOrder = function (id, reportModelId, options) {
+ return OrgModel.app.models.ReportModel.regenerateOrder(id, reportModelId, options)
+ .catch(function(error){
+ logger.error({
+ error,
+ options,
+ functionName: 'regenerateOrder'
+ });
+ return Promise.reject(error);
+ });
+ }
+
OrgModel.remoteMethod('setReportStatus', {
accepts: [
{arg: 'id', type: 'string', required: true},
diff --git a/common/models/org-model.json b/common/models/org-model.json
index d3448c5d..a1a90228 100644
--- a/common/models/org-model.json
+++ b/common/models/org-model.json
@@ -655,6 +655,20 @@
"permission": "ALLOW",
"property": "setReportStatus"
},
+ {
+ "accessType": "EXECUTE",
+ "principalType": "ROLE",
+ "principalId": "orgAdmin",
+ "permission": "ALLOW",
+ "property": "regenerateOrder"
+ },
+ {
+ "accessType": "EXECUTE",
+ "principalType": "ROLE",
+ "principalId": "storeManager",
+ "permission": "ALLOW",
+ "property": "regenerateOrder"
+ },
{
"accessType": "EXECUTE",
"principalType": "ROLE",
diff --git a/common/models/report-model.js b/common/models/report-model.js
index 9d4fa79f..bae6c7f1 100644
--- a/common/models/report-model.js
+++ b/common/models/report-model.js
@@ -1615,6 +1615,34 @@ module.exports = function (ReportModel) {
});
}
+ ReportModel.regenerateOrder = function (orgModelId, reportModelId, options){
+ logger.debug({
+ message: "will change state to generated",
+ orgModelId,
+ reportModelId,
+ options,
+ functionName: 'regenerateOrder'
+ });
+ var reportModelInstance;
+ return ReportModel.findById(reportModelId)
+ .catch(function (error) {
+ logger.error({
+ message: 'Could not find report model instance',
+ reportModelId,
+ options,
+ error,
+ functionName: 'regenerateOrder'
+ });
+ return Promise.reject('Could not find report model instance');
+ })
+ .then( function(response) {
+ reportModelInstance = response;
+ return reportModelInstance.updateAttributes({
+ state: REPORT_STATES.GENERATED
+ });
+ })
+ }
+
ReportModel.deleteStockOrderVend = function (orgModelId, reportModelId, options) {
logger.debug({
message: 'Looking for stock order',