From 52765ad025d70fad2540cd0ed09dc33d199a62c6 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Wed, 17 Apr 2024 21:45:27 +0530 Subject: [PATCH 1/2] fix: validate uom is integer for PR item --- .../purchase_receipt/purchase_receipt.py | 7 ++-- erpnext/utilities/transaction_base.py | 35 +++---------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index b6b3b1e776..2701276b27 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -239,8 +239,7 @@ class PurchaseReceipt(BuyingController): self.po_required() self.validate_items_quality_inspection() self.validate_with_previous_doc() - self.validate_uom_is_integer("uom", ["qty", "received_qty"]) - self.validate_uom_is_integer("stock_uom", "stock_qty") + self.validate_uom_is_integer() self.validate_cwip_accounts() self.validate_provisional_expense_account() @@ -254,6 +253,10 @@ class PurchaseReceipt(BuyingController): self.reset_default_field_value("rejected_warehouse", "items", "rejected_warehouse") self.reset_default_field_value("set_from_warehouse", "items", "from_warehouse") + def validate_uom_is_integer(self): + super().validate_uom_is_integer("uom", ["qty", "received_qty"], "Purchase Receipt Item") + super().validate_uom_is_integer("stock_uom", "stock_qty", "Purchase Receipt Item") + def validate_cwip_accounts(self): for item in self.get("items"): if item.is_fixed_asset and is_cwip_accounting_enabled(item.asset_category): diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index e2f8e5d3c7..b84b775a0b 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -31,34 +31,8 @@ class TransactionBase(StatusUpdater): except ValueError: frappe.throw(_("Invalid Posting Time")) - def validate_posting_datetime_chronology(self): - if not frappe.flags.in_import and cint( - frappe.get_cached_value( - "Accounts Settings", "Accounts Settings", "validate_posting_date_chronology_in_sales_invoices" - ) - ): - previous_invoice = frappe.get_all( - "Sales Invoice", - filters={"naming_series": self.naming_series}, - fields=["name", "posting_date", "posting_time"], - order_by="name desc", - limit=1, - ) - - if previous_invoice: - previous_posting_datetime = datetime.datetime.combine( - previous_invoice[0].posting_date, get_time(previous_invoice[0].posting_time) - ) - current_invoice_datetime = get_datetime(self.posting_date + " " + self.posting_time) - if previous_posting_datetime >= current_invoice_datetime: - frappe.throw( - _("Please select a posting date and time after {0}").format( - format_datetime(previous_posting_datetime) - ) - ) - - def validate_uom_is_integer(self, uom_field, qty_fields): - validate_uom_is_integer(self, uom_field, qty_fields) + def validate_uom_is_integer(self, uom_field, qty_fields, child_dt=None): + validate_uom_is_integer(self, uom_field, qty_fields, child_dt) def validate_with_previous_doc(self, ref): self.exclude_fields = ["conversion_factor", "uom"] if self.get("is_return") else [] @@ -253,12 +227,13 @@ def validate_uom_is_integer(doc, uom_field, qty_fields, child_dt=None): for f in qty_fields: qty = d.get(f) if qty: - if abs(cint(qty) - flt(qty, d.precision(f))) > 0.0000001: + precision = d.precision(f) + if abs(cint(qty) - flt(qty, precision)) > 0.0000001: frappe.throw( _( "Row {1}: Quantity ({0}) cannot be a fraction. To allow this, disable '{2}' in UOM {3}." ).format( - flt(qty, d.precision(f)), + flt(qty, precision), d.idx, frappe.bold(_("Must be Whole Number")), frappe.bold(d.get(uom_field)), -- GitLab From 6a1a354637b04caa58efb30b048a0461b4e9d747 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Wed, 17 Apr 2024 19:12:04 +0000 Subject: [PATCH 2/2] fix: merge conflict --- erpnext/utilities/transaction_base.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index b84b775a0b..d63929ca79 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -31,6 +31,32 @@ class TransactionBase(StatusUpdater): except ValueError: frappe.throw(_("Invalid Posting Time")) + def validate_posting_datetime_chronology(self): + if not frappe.flags.in_import and cint( + frappe.get_cached_value( + "Accounts Settings", "Accounts Settings", "validate_posting_date_chronology_in_sales_invoices" + ) + ): + previous_invoice = frappe.get_all( + "Sales Invoice", + filters={"naming_series": self.naming_series}, + fields=["name", "posting_date", "posting_time"], + order_by="name desc", + limit=1, + ) + + if previous_invoice: + previous_posting_datetime = datetime.datetime.combine( + previous_invoice[0].posting_date, get_time(previous_invoice[0].posting_time) + ) + current_invoice_datetime = get_datetime(self.posting_date + " " + self.posting_time) + if previous_posting_datetime >= current_invoice_datetime: + frappe.throw( + _("Please select a posting date and time after {0}").format( + format_datetime(previous_posting_datetime) + ) + ) + def validate_uom_is_integer(self, uom_field, qty_fields, child_dt=None): validate_uom_is_integer(self, uom_field, qty_fields, child_dt) -- GitLab