Skip to content

Commit

Permalink
Merge pull request #526 from ShoppinPal/feature/ritik/regenerateOrder
Browse files Browse the repository at this point in the history
Feature/ritik/regenerate order
  • Loading branch information
ritikatsp authored Feb 14, 2024
2 parents 773f576 + 7f0081b commit a8138be
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
</button>
</span>
</div>
<div class="col-sm-3">
<span class="input-group-btn">
<button class="btn btn-warning btn-block" type="button" (click)="regenerateOrder()">
<i class="fa fa-refresh"></i>
Regenerate Order
</button>
</span>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions common/models/org-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
14 changes: 14 additions & 0 deletions common/models/org-model.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 28 additions & 0 deletions common/models/report-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit a8138be

Please sign in to comment.