Skip to content

Commit

Permalink
fix: do not empty serial batch fields (#39948)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Feb 19, 2024
1 parent 9cb83d2 commit a4cbfab
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def make_bundle_using_old_serial_batch_fields(self):
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
from erpnext.stock.serial_batch_bundle import SerialBatchCreation

if self.get("_action") == "update_after_submit":
return

# To handle test cases
if frappe.flags.in_test and frappe.flags.use_serial_and_batch_fields:
return
Expand Down Expand Up @@ -219,16 +222,13 @@ def make_bundle_using_old_serial_batch_fields(self):
row.db_set(
{
"rejected_serial_and_batch_bundle": sn_doc.name,
"rejected_serial_no": "",
}
)
else:
row.serial_and_batch_bundle = sn_doc.name
row.db_set(
{
"serial_and_batch_bundle": sn_doc.name,
"serial_no": "",
"batch_no": "",
}
)

Expand Down
4 changes: 2 additions & 2 deletions erpnext/public/js/controllers/buying.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ erpnext.buying = {

let update_values = {
"serial_and_batch_bundle": r.name,
"qty": qty
"qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item))
}

if (r.warehouse) {
Expand Down Expand Up @@ -408,7 +408,7 @@ erpnext.buying = {

let update_values = {
"serial_and_batch_bundle": r.name,
"rejected_qty": qty
"rejected_qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item))
}

if (r.warehouse) {
Expand Down
2 changes: 1 addition & 1 deletion erpnext/public/js/utils/sales_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ erpnext.sales_common = {

frappe.model.set_value(item.doctype, item.name, {
"serial_and_batch_bundle": r.name,
"qty": qty
"qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item))
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/pick_list/pick_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ frappe.ui.form.on('Pick List Item', {
let qty = Math.abs(r.total_qty);
frappe.model.set_value(item.doctype, item.name, {
"serial_and_batch_bundle": r.name,
"qty": qty
"qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item))
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ def test_use_serial_batch_fields_for_serial_nos(self):
)

self.assertEqual(pr.items[0].use_serial_batch_fields, 1)
self.assertFalse(pr.items[0].serial_no)
self.assertTrue(pr.items[0].serial_no)
self.assertTrue(pr.items[0].serial_and_batch_bundle)

sbb_doc = frappe.get_doc("Serial and Batch Bundle", pr.items[0].serial_and_batch_bundle)
Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/stock_entry/stock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ erpnext.stock.select_batch_and_serial_no = (frm, item) => {
if (r) {
frappe.model.set_value(item.doctype, item.name, {
"serial_and_batch_bundle": r.name,
"qty": Math.abs(r.total_qty)
"qty": Math.abs(r.total_qty) / flt(item.conversion_factor || 1, precision("conversion_factor", item))
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions erpnext/stock/doctype/stock_entry/test_stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ def test_use_serial_and_batch_fields(self):
)

self.assertTrue(se.items[0].use_serial_batch_fields)
self.assertFalse(se.items[0].serial_no)
self.assertTrue(se.items[0].serial_no)
self.assertTrue(se.items[0].serial_and_batch_bundle)

for serial_no in serial_nos:
Expand All @@ -1793,7 +1793,7 @@ def test_use_serial_and_batch_fields(self):
se1.reload()

self.assertTrue(se1.items[0].use_serial_batch_fields)
self.assertFalse(se1.items[0].serial_no)
self.assertTrue(se1.items[0].serial_no)
self.assertTrue(se1.items[0].serial_and_batch_bundle)

for serial_no in serial_nos:
Expand Down

0 comments on commit a4cbfab

Please sign in to comment.