mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-18 08:58:43 +00:00
Merge pull request #57665 from frappe/mergify/bp/version-15-hotfix/pr-57658
fix: respect quantity precision in material transfer validation (backport #57658)
This commit is contained in:
@@ -1222,9 +1222,11 @@ class StockEntry(StockController):
|
||||
first_row_by_item.setdefault(key, item)
|
||||
|
||||
for key, transfer_qty in transfer_by_item.items():
|
||||
pending_qty = max(0.0, pending_by_item[key])
|
||||
item = first_row_by_item[key]
|
||||
precision = item.precision("qty")
|
||||
transfer_qty = flt(transfer_qty, precision)
|
||||
pending_qty = max(0.0, flt(pending_by_item[key], precision))
|
||||
if transfer_qty > pending_qty:
|
||||
item = first_row_by_item[key]
|
||||
frappe.throw(
|
||||
_(
|
||||
"Row #{0}: Cannot transfer {1} {2} of Item {3}. "
|
||||
|
||||
@@ -934,6 +934,38 @@ class TestStockEntry(FrappeTestCase):
|
||||
fg_cost = next(filter(lambda x: x.item_code == "_Test FG Item 2", stock_entry.get("items"))).amount
|
||||
self.assertEqual(fg_cost, flt(rm_cost + bom_operation_cost + work_order.additional_operating_cost, 2))
|
||||
|
||||
@change_settings("System Settings", {"float_precision": 3})
|
||||
@change_settings("Manufacturing Settings", {"backflush_raw_materials_based_on": "BOM"})
|
||||
def test_material_transfer_for_manufacture_qty_precision(self):
|
||||
work_order = frappe.new_doc("Work Order")
|
||||
work_order.append(
|
||||
"required_items",
|
||||
{
|
||||
"item_code": "_Test Item",
|
||||
"required_qty": 33.876,
|
||||
"transferred_qty": 33.875,
|
||||
},
|
||||
)
|
||||
|
||||
stock_entry = frappe.new_doc("Stock Entry")
|
||||
stock_entry.work_order = "Test Work Order"
|
||||
stock_entry.append(
|
||||
"items",
|
||||
{
|
||||
"item_code": "_Test Item",
|
||||
"s_warehouse": "_Test Warehouse - _TC",
|
||||
"qty": 0.001,
|
||||
"uom": "Nos",
|
||||
},
|
||||
)
|
||||
|
||||
stock_entry.pro_doc = work_order
|
||||
stock_entry._validate_no_excess_transfer()
|
||||
|
||||
stock_entry.items[0].qty = 0.002
|
||||
with self.assertRaises(frappe.ValidationError):
|
||||
stock_entry._validate_no_excess_transfer()
|
||||
|
||||
@change_settings("Manufacturing Settings", {"material_consumption": 1})
|
||||
def test_work_order_manufacture_with_material_consumption(self):
|
||||
from erpnext.manufacturing.doctype.work_order.work_order import (
|
||||
|
||||
Reference in New Issue
Block a user