fix: use old serial / batch fields to make serial batch bundle

This commit is contained in:
Rohit Waghchaure
2024-02-04 10:42:31 +05:30
parent d9a72c1e61
commit 9fafc83632
43 changed files with 652 additions and 370 deletions

View File

@@ -7,6 +7,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
super.setup();
let me = this;
this.set_fields_onload_for_line_item();
this.frm.ignore_doctypes_on_cancel_all = ['Serial and Batch Bundle'];
frappe.flags.hide_serial_batch_dialog = true;
@@ -105,6 +106,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
frappe.ui.form.on(this.frm.doctype + " Item", {
items_add: function(frm, cdt, cdn) {
debugger
var item = frappe.get_doc(cdt, cdn);
if (!item.warehouse && frm.doc.set_warehouse) {
item.warehouse = frm.doc.set_warehouse;
@@ -118,6 +120,13 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
item.from_warehouse = frm.doc.set_from_warehouse;
}
if (item.docstatus === 0
&& frappe.meta.has_field(item.doctype, "use_serial_batch_fields")
&& cint(frappe.user_defaults?.use_serial_batch_fields) === 1
) {
frappe.model.set_value(item.doctype, item.name, "use_serial_batch_fields", 1);
}
erpnext.accounts.dimensions.copy_dimension_from_first_row(frm, cdt, cdn, 'items');
}
});
@@ -222,7 +231,19 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
};
});
}
}
set_fields_onload_for_line_item() {
if (this.frm.is_new && this.frm.doc?.items) {
this.frm.doc.items.forEach(item => {
if (item.docstatus === 0
&& frappe.meta.has_field(item.doctype, "use_serial_batch_fields")
&& cint(frappe.user_defaults?.use_serial_batch_fields) === 1
) {
frappe.model.set_value(item.doctype, item.name, "use_serial_batch_fields", 1);
}
})
}
}
toggle_enable_for_stock_uom(field) {
@@ -462,6 +483,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
this.frm.doc.doctype === 'Delivery Note') {
show_batch_dialog = 1;
}
if (show_batch_dialog && item.use_serial_batch_fields === 1) {
show_batch_dialog = 0;
}
item.barcode = null;
@@ -1242,20 +1268,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
}
}
sync_bundle_data() {
let doctypes = ["Sales Invoice", "Purchase Invoice", "Delivery Note", "Purchase Receipt"];
if (this.frm.is_new() && doctypes.includes(this.frm.doc.doctype)) {
const barcode_scanner = new erpnext.utils.BarcodeScanner({frm:this.frm});
barcode_scanner.sync_bundle_data();
barcode_scanner.remove_item_from_localstorage();
}
}
before_save(doc) {
this.sync_bundle_data();
}
service_start_date(frm, cdt, cdn) {
var child = locals[cdt][cdn];