Skip to content

Commit

Permalink
Merge pull request #45281 from frappe/mergify/bp/version-15-hotfix/pr…
Browse files Browse the repository at this point in the history
…-45278

fix: status of the serial no for the raw materials (backport #45278)
  • Loading branch information
rohitwaghchaure authored Jan 16, 2025
2 parents 2c46be4 + e2d7115 commit b6ff79f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
47 changes: 47 additions & 0 deletions erpnext/manufacturing/doctype/work_order/test_work_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,53 @@ def test_wip_skip(self):
manufacture_entry = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 10))
self.assertEqual(manufacture_entry.items[0].s_warehouse, "Stores - _TC")

def test_serial_no_status_for_stock_entry(self):
items = {
"Finished Good Test Item 1": {"is_stock_item": 1},
"_Test RM Item with Serial No": {
"is_stock_item": 1,
"has_serial_no": 1,
"serial_no_series": "SN-FCG-NO-.####",
},
}
for item, properties in items.items():
make_item(item, properties)

fg_item = "Finished Good Test Item 1"
rec_se = test_stock_entry.make_stock_entry(
item_code="_Test RM Item with Serial No", target="_Test Warehouse - _TC", qty=4, basic_rate=100
)

if not frappe.db.get_value("BOM", {"item": fg_item, "docstatus": 1}):
bom = make_bom(
item=fg_item,
rate=1000,
raw_materials=["_Test RM Item with Serial No"],
do_not_save=True,
)
bom.rm_cost_as_per = "Price List" # non stock item won't have valuation rate
bom.buying_price_list = "_Test Price List India"
bom.currency = "INR"
bom.save()

wo = make_wo_order_test_record(
production_item=fg_item, skip_transfer=1, source_warehouse="_Test Warehouse - _TC"
)

ste = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 4))
ste.items[0].use_serial_batch_fields = 1
ste.items[0].serial_no = "\n".join(
get_serial_nos_from_bundle(rec_se.items[0].serial_and_batch_bundle)
)
ste.insert()
ste.submit()

ste.reload()
serial_nos = get_serial_nos_from_bundle(ste.items[0].serial_and_batch_bundle)
for row in serial_nos:
status = frappe.db.get_value("Serial No", row, "status")
self.assertEqual(status, "Consumed")


def make_operation(**kwargs):
kwargs = frappe._dict(kwargs)
Expand Down
6 changes: 3 additions & 3 deletions erpnext/stock/doctype/serial_no/serial_no.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Status",
"options": "\nActive\nInactive\nDelivered\nExpired",
"options": "\nActive\nInactive\nConsumed\nDelivered\nExpired",
"read_only": 1
},
{
Expand All @@ -272,7 +272,7 @@
"icon": "fa fa-barcode",
"idx": 1,
"links": [],
"modified": "2023-12-17 10:52:55.767839",
"modified": "2025-01-15 16:22:49.873889",
"modified_by": "Administrator",
"module": "Stock",
"name": "Serial No",
Expand Down Expand Up @@ -316,4 +316,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/serial_no/serial_no.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SerialNo(StockController):
purchase_document_no: DF.Data | None
purchase_rate: DF.Float
serial_no: DF.Data
status: DF.Literal["", "Active", "Inactive", "Delivered", "Expired"]
status: DF.Literal["", "Active", "Inactive", "Consumed", "Delivered", "Expired"]
warehouse: DF.Link | None
warranty_expiry_date: DF.Date | None
warranty_period: DF.Int
Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/stock_entry/test_stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ def test_use_serial_and_batch_fields(self):

for serial_no in serial_nos:
self.assertTrue(frappe.db.exists("Serial No", serial_no))
self.assertEqual(frappe.db.get_value("Serial No", serial_no, "status"), "Delivered")
self.assertEqual(frappe.db.get_value("Serial No", serial_no, "status"), "Consumed")

def test_serial_batch_bundle_type_of_transaction(self):
item = make_item(
Expand Down
9 changes: 9 additions & 0 deletions erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ def set_warehouse_and_status_in_serial_nos(self):
status = "Inactive"
if self.sle.actual_qty < 0:
status = "Delivered"
if self.sle.voucher_type == "Stock Entry":
purpose = frappe.get_cached_value("Stock Entry", self.sle.voucher_no, "purpose")
if purpose in [
"Manufacture",
"Material Issue",
"Repack",
"Material Consumption for Manufacture",
]:
status = "Consumed"

sn_table = frappe.qb.DocType("Serial No")

Expand Down
5 changes: 1 addition & 4 deletions erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,12 @@ def build(self):
if sle.dependant_sle_voucher_detail_no:
entries_to_fix = self.get_dependent_entries_to_fix(entries_to_fix, sle)

if self.has_stock_reco_with_serial_batch(sle):
break

if self.exceptions:
self.raise_exceptions()

def has_stock_reco_with_serial_batch(self, sle):
if (
sle.vocher_type == "Stock Reconciliation"
sle.voucher_type == "Stock Reconciliation"
and frappe.db.get_value(sle.voucher_type, sle.voucher_no, "set_posting_time") == 1
):
return not (sle.batch_no or sle.serial_no or sle.serial_and_batch_bundle)
Expand Down

0 comments on commit b6ff79f

Please sign in to comment.