Skip to content

Commit

Permalink
fix: serial no status (#38391)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Nov 28, 2023
1 parent c232acb commit 592fc81
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
19 changes: 19 additions & 0 deletions erpnext/stock/doctype/delivery_note/test_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,25 @@ def test_non_internal_transfer_delivery_note(self):
dn.reload()
self.assertFalse(dn.items[0].target_warehouse)

def test_serial_no_status(self):
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt

item = make_item(
"Test Serial Item For Status",
{"has_serial_no": 1, "is_stock_item": 1, "serial_no_series": "TESTSERIAL.#####"},
)

item_code = item.name
pi = make_purchase_receipt(qty=1, item_code=item.name)
pi.reload()
serial_no = get_serial_nos_from_bundle(pi.items[0].serial_and_batch_bundle)

self.assertEqual(frappe.db.get_value("Serial No", serial_no, "status"), "Active")

dn = create_delivery_note(qty=1, item_code=item_code, serial_no=serial_no)
dn.reload()
self.assertEqual(frappe.db.get_value("Serial No", serial_no, "status"), "Delivered")


def create_delivery_note(**args):
dn = frappe.new_doc("Delivery Note")
Expand Down
19 changes: 19 additions & 0 deletions erpnext/stock/doctype/serial_no/serial_no.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,22 @@ cur_frm.cscript.onload = function() {
frappe.ui.form.on("Serial No", "refresh", function(frm) {
frm.toggle_enable("item_code", frm.doc.__islocal);
});


frappe.ui.form.on("Serial No", {
refresh(frm) {
frm.trigger("view_ledgers")
},

view_ledgers(frm) {
frm.add_custom_button(__("View Ledgers"), () => {
frappe.route_options = {
"item_code": frm.doc.item_code,
"serial_no": frm.doc.name,
"posting_date": frappe.datetime.now_date(),
"posting_time": frappe.datetime.now_time()
};
frappe.set_route("query-report", "Serial No Ledger");
}).addClass('btn-primary');
}
})
4 changes: 2 additions & 2 deletions erpnext/stock/doctype/serial_no/serial_no.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Status",
"options": "\nActive\nInactive\nExpired",
"options": "\nActive\nInactive\nDelivered\nExpired",
"read_only": 1
},
{
Expand All @@ -280,7 +280,7 @@
"icon": "fa fa-barcode",
"idx": 1,
"links": [],
"modified": "2023-04-16 15:58:46.139887",
"modified": "2023-11-28 15:37:59.489945",
"modified_by": "Administrator",
"module": "Stock",
"name": "Serial No",
Expand Down
24 changes: 20 additions & 4 deletions erpnext/stock/report/serial_no_ledger/serial_no_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,40 @@ def get_columns(filters):
"fieldtype": "Link",
"fieldname": "company",
"options": "Company",
"width": 150,
"width": 120,
},
{
"label": _("Warehouse"),
"fieldtype": "Link",
"fieldname": "warehouse",
"options": "Warehouse",
"width": 150,
"width": 120,
},
{
"label": _("Status"),
"fieldtype": "Data",
"fieldname": "status",
"width": 120,
},
{
"label": _("Serial No"),
"fieldtype": "Link",
"fieldname": "serial_no",
"options": "Serial No",
"width": 150,
"width": 130,
},
{
"label": _("Valuation Rate"),
"fieldtype": "Float",
"fieldname": "valuation_rate",
"width": 150,
},
{
"label": _("Qty"),
"fieldtype": "Float",
"fieldname": "qty",
"width": 150,
},
]

return columns
Expand All @@ -83,12 +95,16 @@ def get_data(filters):
"posting_time": row.posting_time,
"voucher_type": row.voucher_type,
"voucher_no": row.voucher_no,
"status": "Active" if row.actual_qty > 0 else "Delivered",
"company": row.company,
"warehouse": row.warehouse,
"qty": 1 if row.actual_qty > 0 else -1,
}
)

serial_nos = bundle_wise_serial_nos.get(row.serial_and_batch_bundle, [])
serial_nos = [{"serial_no": row.serial_no, "valuation_rate": row.valuation_rate}]
if row.serial_and_batch_bundle:
serial_nos = bundle_wise_serial_nos.get(row.serial_and_batch_bundle, [])

for index, bundle_data in enumerate(serial_nos):
if index == 0:
Expand Down
6 changes: 5 additions & 1 deletion erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,15 @@ def set_warehouse_and_status_in_serial_nos(self):
if not serial_nos:
return

status = "Inactive"
if self.sle.actual_qty < 0:
status = "Delivered"

sn_table = frappe.qb.DocType("Serial No")
(
frappe.qb.update(sn_table)
.set(sn_table.warehouse, warehouse)
.set(sn_table.status, "Active" if warehouse else "Inactive")
.set(sn_table.status, "Active" if warehouse else status)
.where(sn_table.name.isin(serial_nos))
).run()

Expand Down

0 comments on commit 592fc81

Please sign in to comment.