mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: compute items cost of inventory adjustments transcations.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user