Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decimal precision issue for quantity #316

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ export default class InventoryAdjustmentsController extends BaseController {
check('quantity')
.if(check('type').exists().isIn(['increment', 'decrement']))
.exists()
.isInt()
.toInt(),
.isDecimal()
.toFloat(),
// TODO: Is the cost supposed to be an integer here if it's a float everywhere else?
check('cost')
.if(check('type').exists().isIn(['increment']))
.exists()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/Purchases/Bills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default class BillsController extends BaseController {
check('entries.*.index').exists().isNumeric().toInt(),
check('entries.*.item_id').exists().isNumeric().toInt(),
check('entries.*.rate').exists().isNumeric().toFloat(),
check('entries.*.quantity').exists().isNumeric().toInt(),
check('entries.*.quantity').exists().isNumeric().toFloat(),
check('entries.*.discount')
.optional({ nullable: true })
.isNumeric()
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/api/controllers/Purchases/VendorCredit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default class VendorCreditController extends BaseController {
check('entries.*.index').exists().isNumeric().toInt(),
check('entries.*.item_id').exists().isNumeric().toInt(),
check('entries.*.rate').exists().isNumeric().toFloat(),
check('entries.*.quantity').exists().isNumeric().toInt(),
check('entries.*.quantity').exists().isNumeric().toFloat(),
check('entries.*.discount')
.optional({ nullable: true })
.isNumeric()
Expand Down Expand Up @@ -215,7 +215,7 @@ export default class VendorCreditController extends BaseController {
check('entries.*.index').exists().isNumeric().toInt(),
check('entries.*.item_id').exists().isNumeric().toInt(),
check('entries.*.rate').exists().isNumeric().toFloat(),
check('entries.*.quantity').exists().isNumeric().toInt(),
check('entries.*.quantity').exists().isNumeric().toFloat(),
check('entries.*.discount')
.optional({ nullable: true })
.isNumeric()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/Sales/CreditNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export default class PaymentReceivesController extends BaseController {
check('entries.*.index').exists().isNumeric().toInt(),
check('entries.*.item_id').exists().isNumeric().toInt(),
check('entries.*.rate').exists().isNumeric().toFloat(),
check('entries.*.quantity').exists().isNumeric().toInt(),
check('entries.*.quantity').exists().isNumeric().toFloat(),
check('entries.*.discount')
.optional({ nullable: true })
.isNumeric()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class SalesEstimatesController extends BaseController {
check('entries').exists().isArray({ min: 1 }),
check('entries.*.index').exists().isNumeric().toInt(),
check('entries.*.item_id').exists().isNumeric().toInt(),
check('entries.*.quantity').exists().isNumeric().toInt(),
check('entries.*.quantity').exists().isNumeric().toFloat(),
check('entries.*.rate').exists().isNumeric().toFloat(),
check('entries.*.description')
.optional({ nullable: true })
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/Sales/SalesReceipts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default class SalesReceiptsController extends BaseController {
check('entries.*.id').optional({ nullable: true }).isNumeric().toInt(),
check('entries.*.index').exists().isNumeric().toInt(),
check('entries.*.item_id').exists().isNumeric().toInt(),
check('entries.*.quantity').exists().isNumeric().toInt(),
check('entries.*.quantity').exists().isNumeric().toFloat(),
check('entries.*.rate').exists().isNumeric().toFloat(),
check('entries.*.discount')
.optional({ nullable: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class WarehousesTransfers extends BaseController {
check('entries.*.index').exists(),
check('entries.*.item_id').exists(),
check('entries.*.description').optional(),
check('entries.*.quantity').exists().isInt().toInt(),
check('entries.*.quantity').exists().isDecimal().toFloat(),
check('entries.*.cost').optional().isDecimal().toFloat(),
],
this.validationResult,
Expand All @@ -66,7 +66,7 @@ export class WarehousesTransfers extends BaseController {
check('entries.*.index').exists(),
check('entries.*.item_id').exists().isInt().toInt(),
check('entries.*.description').optional(),
check('entries.*.quantity').exists().isInt({ min: 1 }).toInt(),
check('entries.*.quantity').exists().isDecimal().toFloat(),
check('entries.*.cost').optional().isDecimal().toFloat(),
],
this.validationResult,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exports.up = function(knex) {
return knex.schema.alterTable('items_entries', (table) => {
table.decimal('quantity', 17, 7).alter();
});
};

exports.down = function(knex) {
return knex.table('items_entries', (table) => { });
};