From 6de3ed5416c003c0010e90bfb02c4b226244a962 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 26 Jun 2019 21:57:03 +0530 Subject: [PATCH] fix: dn test cases --- .../stock/doctype/delivery_note/delivery_note.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 863a8109f8..1e522b834e 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -419,6 +419,8 @@ def get_returned_qty_map(delivery_note): @frappe.whitelist() def make_sales_invoice(source_name, target_doc=None): doc = frappe.get_doc('Delivery Note', source_name) + + to_make_invoice_qty_map = {} returned_qty_map = get_returned_qty_map(source_name) invoiced_qty_map = get_invoiced_qty_map(source_name) @@ -439,8 +441,7 @@ def make_sales_invoice(source_name, target_doc=None): target.update(get_fetch_values("Sales Invoice", 'company_address', target.company_address)) def update_item(source_doc, target_doc, source_parent): - target_doc.qty, returned_qty = get_pending_qty(source_doc) - returned_qty_map[source_doc.item_code] = returned_qty + target_doc.qty = to_make_invoice_qty_map[source_doc.name] if source_doc.serial_no and source_parent.per_billed > 0: target_doc.serial_no = get_delivery_note_serial_no(source_doc.item_code, @@ -450,7 +451,7 @@ def make_sales_invoice(source_name, target_doc=None): pending_qty = item_row.qty - invoiced_qty_map.get(item_row.name, 0) returned_qty = 0 - if returned_qty_map.get(item_row.item_code) > 0: + if returned_qty_map.get(item_row.item_code, 0) > 0: returned_qty = flt(returned_qty_map.get(item_row.item_code, 0)) returned_qty_map[item_row.item_code] -= pending_qty @@ -462,7 +463,9 @@ def make_sales_invoice(source_name, target_doc=None): pending_qty -= returned_qty returned_qty = 0 - return pending_qty, returned_qty + to_make_invoice_qty_map[item_row.name] = pending_qty + + return pending_qty doc = get_mapped_doc("Delivery Note", source_name, { "Delivery Note": { @@ -482,7 +485,7 @@ def make_sales_invoice(source_name, target_doc=None): "cost_center": "cost_center" }, "postprocess": update_item, - "filter": lambda d: get_pending_qty(d)[0] <= 0 if not doc.get("is_return") else get_pending_qty(d)[0] > 0 + "filter": lambda d: get_pending_qty(d) <= 0 if not doc.get("is_return") else get_pending_qty(d) > 0 }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges",