Skip to content

Commit

Permalink
Merge pull request #35618 from s-aga-r/FIX-SBB-SERIAL-NO-QTY
Browse files Browse the repository at this point in the history
fix: reset entries qty to `1` for serial item
  • Loading branch information
s-aga-r authored Jun 9, 2023
2 parents 7bd369c + b5c5a90 commit e3802d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,25 @@ frappe.ui.form.on('Serial and Batch Bundle', {
},

toggle_fields(frm) {
if (frm.doc.has_serial_no) {
frm.doc.entries.forEach(row => {
if (Math.abs(row.qty) !== 1) {
frappe.model.set_value(row.doctype, row.name, "qty", 1);
}
})
}

frm.fields_dict.entries.grid.update_docfield_property(
'serial_no', 'read_only', !frm.doc.has_serial_no
);

frm.fields_dict.entries.grid.update_docfield_property(
'batch_no', 'read_only', !frm.doc.has_batch_no
);

frm.fields_dict.entries.grid.update_docfield_property(
'qty', 'read_only', frm.doc.has_serial_no
);
},

set_queries(frm) {
Expand Down Expand Up @@ -198,9 +210,9 @@ frappe.ui.form.on('Serial and Batch Bundle', {


frappe.ui.form.on("Serial and Batch Entry", {
ledgers_add(frm, cdt, cdn) {
entries_add(frm, cdt, cdn) {
if (frm.doc.warehouse) {
locals[cdt][cdn].warehouse = frm.doc.warehouse;
frappe.model.set_value(cdt, cdn, 'warehouse', frm.doc.warehouse);
}
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def set_incoming_rate(self, row=None, save=False):
def calculate_total_qty(self, save=True):
self.total_qty = 0.0
for d in self.entries:
d.qty = abs(d.qty) if d.qty else 0
d.qty = 1 if self.has_serial_no and abs(d.qty) > 1 else abs(d.qty) if d.qty else 0
d.stock_value_difference = abs(d.stock_value_difference) if d.stock_value_difference else 0
if self.type_of_transaction == "Outward":
d.qty *= -1
Expand Down

0 comments on commit e3802d1

Please sign in to comment.