Skip to content

Commit

Permalink
fix: Accepted and Rejected warehouse cannot be same (#43568)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Oct 8, 2024
1 parent 3e5ecb4 commit 5130f7d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions erpnext/public/js/controllers/buying.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ erpnext.buying = {
item[field] = r.message[field];
});

item.type_of_transaction = item.rejected_qty > 0 ? "Inward" : "Outward";
item.type_of_transaction = !doc.is_return > 0 ? "Inward" : "Outward";
item.is_rejected = true;

new erpnext.SerialBatchPackageSelector(
Expand All @@ -404,7 +404,7 @@ erpnext.buying = {
}

let update_values = {
"serial_and_batch_bundle": r.name,
"rejected_serial_and_batch_bundle": r.name,
"use_serial_batch_fields": 0,
"rejected_qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item))
}
Expand Down
25 changes: 19 additions & 6 deletions erpnext/public/js/utils/serial_no_batch_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
options: "Warehouse",
default: this.get_warehouse(),
onchange: () => {
this.item.warehouse = this.dialog.get_value("warehouse");
if (this.item?.is_rejected) {
this.item.rejected_warehouse = this.dialog.get_value("warehouse");
} else {
this.item.warehouse = this.dialog.get_value("warehouse");
}

this.get_auto_data();
},
get_query: () => {
Expand Down Expand Up @@ -282,10 +287,6 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
return fields;
}

set_serial_nos_from_series() {}

set_batch_nos_from_series() {}

set_serial_nos_from_range() {
const serial_no_range = this.dialog.get_value("serial_no_range");

Expand Down Expand Up @@ -508,12 +509,17 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
based_on = "FIFO";
}

let warehouse = this.item.warehouse || this.item.s_warehouse;
if (this.item?.is_rejected) {
warehouse = this.item.rejected_warehouse;
}

if (qty) {
frappe.call({
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 || this.item.s_warehouse,
warehouse: warehouse,
has_serial_no: this.item.has_serial_no,
has_batch_no: this.item.has_batch_no,
qty: qty,
Expand Down Expand Up @@ -627,6 +633,10 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
frappe.throw(__("Please select a Warehouse"));
}

if (this.item?.is_rejected && this.item.rejected_warehouse === this.item.warehouse) {
frappe.throw(__("Rejected Warehouse and Accepted Warehouse cannot be same."));
}

frappe
.call({
method: "erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle.add_serial_batch_ledgers",
Expand Down Expand Up @@ -701,5 +711,8 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
});

this.dialog.fields_dict.entries.grid.refresh();
if (this.dialog.fields_dict.entries.df.data?.length) {
this.dialog.set_value("enter_manually", 0);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -1308,8 +1308,12 @@ def add_serial_batch_ledgers(entries, child_row, doc, warehouse, do_not_save=Fal
if parent_doc and isinstance(parent_doc, str):
parent_doc = parse_json(parent_doc)

if frappe.db.exists("Serial and Batch Bundle", child_row.serial_and_batch_bundle):
sb_doc = update_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse)
bundle = child_row.serial_and_batch_bundle
if child_row.get("is_rejected"):
bundle = child_row.rejected_serial_and_batch_bundle

if frappe.db.exists("Serial and Batch Bundle", bundle):
sb_doc = update_serial_batch_no_ledgers(bundle, entries, child_row, parent_doc, warehouse)
else:
sb_doc = create_serial_batch_no_ledgers(
entries, child_row, parent_doc, warehouse, do_not_save=do_not_save
Expand Down Expand Up @@ -1412,8 +1416,8 @@ def get_type_of_transaction(parent_doc, child_row):
return type_of_transaction


def update_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse=None) -> object:
doc = frappe.get_doc("Serial and Batch Bundle", child_row.serial_and_batch_bundle)
def update_serial_batch_no_ledgers(bundle, entries, child_row, parent_doc, warehouse=None) -> object:
doc = frappe.get_doc("Serial and Batch Bundle", bundle)
doc.voucher_detail_no = child_row.name
doc.posting_date = parent_doc.posting_date
doc.posting_time = parent_doc.posting_time
Expand Down

0 comments on commit 5130f7d

Please sign in to comment.