Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not empty serial batch fields (backport #39948) #39956

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2222,7 +2222,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 @@ -1766,7 +1766,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 @@ -1784,7 +1784,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
Loading