feat: compute items cost of inventory adjustments transcations.

This commit is contained in:
a.bouhuolia
2021-01-10 17:41:32 +02:00
parent 097b9fdb3a
commit 8491d44118
20 changed files with 433 additions and 180 deletions

View File

@@ -115,8 +115,8 @@ export default class InventoryAdjustmentsController extends BaseController {
tenantId,
adjustmentId
);
return res.status(200).send({
id: adjustmentId,
message: 'The inventory adjustment has been deleted successfully.',
});
} catch (error) {

View File

@@ -25,14 +25,14 @@ export default class ItemsController extends BaseController {
router.post(
'/',
[...this.validateItemSchema, ...this.validateNewItemSchema],
this.validateItemSchema,
this.validationResult,
asyncMiddleware(this.newItem.bind(this)),
this.handlerServiceErrors
);
router.post(
'/:id/activate',
[...this.validateSpecificItemSchema],
this.validateSpecificItemSchema,
this.validationResult,
asyncMiddleware(this.activateItem.bind(this)),
this.handlerServiceErrors
@@ -83,30 +83,6 @@ export default class ItemsController extends BaseController {
return router;
}
/**
* New item validation schema.
*/
get validateNewItemSchema(): ValidationChain[] {
return [
check('opening_quantity').default(0).isInt({ min: 0 }).toInt(),
check('opening_cost')
.if(body('opening_quantity').exists().isInt({ min: 1 }))
.exists()
.isFloat(),
check('opening_cost')
.optional({ nullable: true })
.isFloat({ min: 0 })
.toFloat(),
check('opening_date')
.if(
body('opening_quantity').exists().isFloat({ min: 1 }) ||
body('opening_cost').exists().isFloat({ min: 1 })
)
.exists(),
check('opening_date').optional({ nullable: true }).isISO8601().toDate(),
];
}
/**
* Validate item schema.
*/
@@ -503,6 +479,11 @@ export default class ItemsController extends BaseController {
errors: [{ type: 'ITEM_HAS_ASSOCIATED_TRANSACTINS', code: 320 }],
});
}
if (error.errorType === 'ITEM_HAS_ASSOCIATED_INVENTORY_ADJUSTMENT') {
return res.status(400).send({
errors: [{ type: 'ITEM_HAS_ASSOCIATED_INVENTORY_ADJUSTMENT', code: 330 }],
});
}
}
next(error);
}