Skip to content

Commit

Permalink
fix: return from accepted and rejected warehouse at a same time not w…
Browse files Browse the repository at this point in the history
…orking
  • Loading branch information
rohitwaghchaure committed Jun 12, 2024
1 parent 9f3b1ce commit b1cf8b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
18 changes: 16 additions & 2 deletions erpnext/controllers/sales_and_purchase_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,13 +936,17 @@ def get_serial_and_batch_bundle(field, doctype, reference_ids, is_rejected=False
if is_rejected:
fields.extend(["rejected_serial_and_batch_bundle", "return_qty_from_rejected_warehouse"])

del filters["rejected_serial_and_batch_bundle"]
data = frappe.get_all(
doctype,
fields=fields,
filters=filters,
)

for d in data:
if not d.get("serial_and_batch_bundle") and not d.get("rejected_serial_and_batch_bundle"):
continue

if is_rejected:
if d.get("return_qty_from_rejected_warehouse"):
_bundle_ids.append(d.get("serial_and_batch_bundle"))
Expand Down Expand Up @@ -1027,7 +1031,7 @@ def get_available_batch_qty(parent_doc, batch_no, warehouse):
)


def make_serial_batch_bundle_for_return(data, child_doc, parent_doc, warehouse_field=None):
def make_serial_batch_bundle_for_return(data, child_doc, parent_doc, warehouse_field=None, qty_field=None):
from erpnext.stock.serial_batch_bundle import SerialBatchCreation

type_of_transaction = "Outward"
Expand All @@ -1037,11 +1041,21 @@ def make_serial_batch_bundle_for_return(data, child_doc, parent_doc, warehouse_f
if not warehouse_field:
warehouse_field = "warehouse"

if not qty_field:
qty_field = "qty"

warehouse = child_doc.get(warehouse_field)
if parent_doc.get("is_internal_customer"):
warehouse = child_doc.get("target_warehouse")
type_of_transaction = "Outward"

if not child_doc.get(qty_field):
frappe.throw(
_("For the {0}, the quantity is required to make the return entry").format(
frappe.bold(child_doc.item_code)
)
)

cls_obj = SerialBatchCreation(
{
"type_of_transaction": type_of_transaction,
Expand All @@ -1054,7 +1068,7 @@ def make_serial_batch_bundle_for_return(data, child_doc, parent_doc, warehouse_f
"voucher_type": parent_doc.doctype,
"voucher_no": parent_doc.name,
"voucher_detail_no": child_doc.name,
"qty": child_doc.qty,
"qty": child_doc.get(qty_field),
"company": parent_doc.company,
"do_not_submit": True,
}
Expand Down
9 changes: 8 additions & 1 deletion erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,17 @@ def make_bundle_for_rejected_qty(self, table_name=None):
qty_field = "qty"
warehouse_field = "warehouse"

if not data.get("qty"):
frappe.throw(
_("For the {0}, no stock is available for the return in the warehouse {1}.").format(
frappe.bold(row.item_code), row.get(warehouse_field)
)
)

data = filter_serial_batches(
self, data, row, warehouse_field=warehouse_field, qty_field=qty_field
)
bundle = make_serial_batch_bundle_for_return(data, row, self, warehouse_field)
bundle = make_serial_batch_bundle_for_return(data, row, self, warehouse_field, qty_field)
if row.get("return_qty_from_rejected_warehouse"):
row.db_set(
{
Expand Down

0 comments on commit b1cf8b9

Please sign in to comment.