refactor: added new file serial batch bundle
diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js
index e37a9b7..2a81651 100644
--- a/erpnext/public/js/controllers/buying.js
+++ b/erpnext/public/js/controllers/buying.js
@@ -346,7 +346,7 @@
}
}
- update_serial_batch_bundle(doc, cdt, cdn) {
+ add_serial_batch_bundle(doc, cdt, cdn) {
let item = locals[cdt][cdn];
let me = this;
let path = "assets/erpnext/js/utils/serial_no_batch_selector.js";
@@ -356,6 +356,8 @@
if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
item.has_serial_no = r.message.has_serial_no;
item.has_batch_no = r.message.has_batch_no;
+ item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward";
+ item.is_rejected = false;
frappe.require(path, function() {
new erpnext.SerialNoBatchBundleUpdate(
@@ -371,6 +373,34 @@
}
});
}
+
+ add_serial_batch_for_rejected_qty(doc, cdt, cdn) {
+ let item = locals[cdt][cdn];
+ let me = this;
+ let path = "assets/erpnext/js/utils/serial_no_batch_selector.js";
+
+ frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"])
+ .then((r) => {
+ if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
+ item.has_serial_no = r.message.has_serial_no;
+ item.has_batch_no = r.message.has_batch_no;
+ item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward";
+ item.is_rejected = true;
+
+ frappe.require(path, function() {
+ new erpnext.SerialNoBatchBundleUpdate(
+ me.frm, item, (r) => {
+ if (r) {
+ me.frm.refresh_fields();
+ frappe.model.set_value(cdt, cdn,
+ "rejected_serial_and_batch_bundle", r.name);
+ }
+ }
+ );
+ });
+ }
+ });
+ }
};
cur_frm.add_fetch('project', 'cost_center', 'cost_center');
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 52abbc0..e706ab9 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -682,6 +682,10 @@
}
}
+ on_submit() {
+ refresh_field("items");
+ }
+
update_qty(cdt, cdn) {
var valid_serial_nos = [];
var serialnos = [];
diff --git a/erpnext/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js
index fcaaaf0..bdfc2f0 100644
--- a/erpnext/public/js/utils/serial_no_batch_selector.js
+++ b/erpnext/public/js/utils/serial_no_batch_selector.js
@@ -624,13 +624,16 @@
this.item = item;
this.qty = item.qty;
this.callback = callback;
+ this.bundle = this.item?.is_rejected ?
+ this.item.rejected_serial_and_batch_bundle : this.item.serial_and_batch_bundle;
+
this.make();
this.render_data();
}
make() {
let label = this.item?.has_serial_no ? __('Serial No') : __('Batch No');
- let primary_label = this.item?.serial_and_batch_bundle
+ let primary_label = this.bundle
? __('Update') : __('Add');
if (this.item?.has_serial_no && this.item?.batch_no) {
@@ -655,7 +658,7 @@
get_serial_no_filters() {
let warehouse = this.item?.outward ?
- this.item.warehouse : "";
+ (this.item.warehouse || this.item.s_warehouse) : "";
return {
'item_code': this.item.item_code,
@@ -684,7 +687,6 @@
if (this.item.has_batch_no && this.item.has_serial_no) {
fields.push({
fieldtype: 'Column Break',
- label: __('Batch No')
});
}
@@ -698,6 +700,22 @@
});
}
+ if (this.frm.doc.doctype === 'Stock Entry'
+ && this.frm.doc.purpose === 'Manufacture') {
+ fields.push({
+ fieldtype: 'Column Break',
+ });
+
+ fields.push({
+ fieldtype: 'Link',
+ fieldname: 'work_order',
+ label: __('For Work Order'),
+ options: 'Work Order',
+ read_only: 1,
+ default: this.frm.doc.work_order,
+ });
+ }
+
if (this.item?.outward) {
fields = [...fields, ...this.get_filter_fields()];
}
@@ -770,30 +788,36 @@
})
}
+ let batch_fields = []
if (this.item.has_batch_no) {
- fields = [
+ batch_fields = [
{
fieldtype: 'Link',
options: 'Batch',
fieldname: 'batch_no',
label: __('Batch No'),
in_list_view: 1,
- },
- {
+ }
+ ]
+
+ if (!this.item.has_serial_no) {
+ batch_fields.push({
fieldtype: 'Float',
fieldname: 'qty',
label: __('Quantity'),
in_list_view: 1,
- }
- ]
+ })
+ }
}
+ fields = [...fields, ...batch_fields];
+
fields.push({
fieldtype: 'Data',
fieldname: 'name',
label: __('Name'),
hidden: 1,
- })
+ });
return fields;
}
@@ -815,13 +839,14 @@
method: 'erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle.get_auto_data',
args: {
item_code: this.item.item_code,
- warehouse: this.item.warehouse,
+ warehouse: this.item.warehouse || this.item.s_warehouse,
has_serial_no: this.item.has_serial_no,
has_batch_no: this.item.has_batch_no,
qty: qty,
based_on: based_on
},
callback: (r) => {
+ debugger
if (r.message) {
this.dialog.fields_dict.ledgers.df.data = r.message;
this.dialog.fields_dict.ledgers.grid.refresh();
@@ -854,7 +879,7 @@
if (!this.frm.is_new()) {
let ledgers = this.dialog.get_values().ledgers;
- if (ledgers && !ledgers.length) {
+ if (ledgers && !ledgers.length || !ledgers) {
frappe.throw(__('Please add atleast one Serial No / Batch No'));
}
@@ -862,9 +887,11 @@
method: 'erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle.add_serial_batch_ledgers',
args: {
ledgers: ledgers,
- child_row: this.item
+ child_row: this.item,
+ doc: this.frm.doc,
}
}).then(r => {
+ debugger
this.callback && this.callback(r.message);
this.dialog.hide();
})
@@ -872,12 +899,12 @@
}
render_data() {
- if (!this.frm.is_new() && this.item.serial_and_batch_bundle) {
+ if (!this.frm.is_new() && this.bundle) {
frappe.call({
method: 'erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle.get_serial_batch_ledgers',
args: {
item_code: this.item.item_code,
- name: this.item.serial_and_batch_bundle,
+ name: this.bundle,
voucher_no: this.item.parent,
}
}).then(r => {