test: Independent Manufacture Entry
- Check validations
- Check if FG basic rate is calculated correctly
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index d3295d6..30e0bb8 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -35,6 +35,7 @@
from erpnext.stock.utils import get_bin, get_incoming_rate
+class FinishedGoodError(frappe.ValidationError): pass
class IncorrectValuationRateError(frappe.ValidationError): pass
class DuplicateEntryForWorkOrderError(frappe.ValidationError): pass
class OperationsNotCompleteError(frappe.ValidationError): pass
@@ -755,13 +756,18 @@
finished_items.append(d.item_code)
if len(set(finished_items)) > 1:
- frappe.throw(_("Multiple items cannot be marked as finished item"))
+ frappe.throw(
+ msg=_("Multiple items cannot be marked as finished item"),
+ title=_("Note"),
+ exc=FinishedGoodError
+ )
if self.purpose == "Manufacture":
if not finished_items:
frappe.throw(
msg=_("There must be atleast 1 Finished Good in this Stock Entry").format(self.name),
- title=_("Missing Finished Good")
+ title=_("Missing Finished Good"),
+ exc=FinishedGoodError
)
allowance_percentage = flt(
diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
index 0679467..59cadc4 100644
--- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
@@ -15,7 +15,7 @@
set_item_variant_settings,
)
from erpnext.stock.doctype.serial_no.serial_no import * # noqa
-from erpnext.stock.doctype.stock_entry.stock_entry import move_sample_to_retention_warehouse
+from erpnext.stock.doctype.stock_entry.stock_entry import (move_sample_to_retention_warehouse, FinishedGoodError)
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from erpnext.stock.doctype.stock_ledger_entry.stock_ledger_entry import StockFreezeError
from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import (
@@ -868,6 +868,38 @@
distributed_costs = [d.additional_cost for d in se.items]
self.assertEqual([40.0, 60.0], distributed_costs)
+ def test_independent_manufacture_entry(self):
+ "Test FG items and incoming rate calculation in Maniufacture Entry without WO or BOM linked."
+ se = frappe.get_doc(
+ doctype="Stock Entry",
+ purpose="Manufacture",
+ stock_entry_type="Manufacture",
+ company="_Test Company",
+ items=[
+ frappe._dict(item_code="_Test Item", qty=1, basic_rate=200, s_warehouse="_Test Warehouse - _TC"),
+ frappe._dict(item_code="_Test FG Item", qty=4, t_warehouse="_Test Warehouse 1 - _TC")
+ ]
+ )
+ # SE must have atleast one FG
+ self.assertRaises(FinishedGoodError, se.save)
+
+ se.items[0].is_finished_item = 1
+ se.items[1].is_finished_item = 1
+ # SE cannot have multiple FGs
+ self.assertRaises(FinishedGoodError, se.save)
+
+ se.items[0].is_finished_item = 0
+ se.save()
+
+ # Check if FG cost is calculated based on RM total cost
+ # RM total cost = 200, FG rate = 200/4(FG qty) = 50
+ self.assertEqual(se.items[1].basic_rate, 50)
+ self.assertEqual(se.value_difference, 0.0)
+ self.assertEqual(se.total_incoming_value, se.total_outgoing_value)
+
+ # teardown
+ se.delete()
+
def make_serialized_item(**args):
args = frappe._dict(args)
se = frappe.copy_doc(test_records[0])