From 900639734a5591d2fcd60148cec2aa57dbfc6168 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Mon, 28 Feb 2022 12:46:33 +0530 Subject: [PATCH] fix: allow zero rate on items --- models/doctype/Item/Item.js | 6 ++---- .../PurchaseInvoiceItem/PurchaseInvoiceItem.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/models/doctype/Item/Item.js b/models/doctype/Item/Item.js index aabf92fc..35634d43 100644 --- a/models/doctype/Item/Item.js +++ b/models/doctype/Item/Item.js @@ -105,10 +105,8 @@ export default { label: t`Rate`, fieldtype: 'Currency', validate(value) { - if (value.lte(0)) { - throw new frappe.errors.ValidationError( - 'Rate must be greater than 0' - ); + if (value.isNegative()) { + throw new frappe.errors.ValidationError(t`Rate can't be negative.`); } }, }, diff --git a/models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js b/models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js index caef417c..e57026e8 100644 --- a/models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js +++ b/models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js @@ -46,6 +46,18 @@ export default { return baseRate.div(doc.exchangeRate); }, getCurrency: (row, doc) => doc.currency, + validate(value) { + if (value.gte(0)) { + return; + } + + throw new frappe.errors.ValidationError( + frappe.t`Rate (${frappe.format( + value, + 'Currency' + )}) cannot be less zero.` + ); + }, }, { fieldname: 'baseRate',