diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index a9586b6d15..5201e5e80b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -131,7 +131,7 @@ class SalesInvoice(SellingController): 'keyword':'Delivered', 'second_source_dt': 'Delivery Note Item', 'second_source_field': 'qty', - 'second_join_field': 'prevdoc_detail_docname', + 'second_join_field': 'so_detail', 'overflow_type': 'delivery', 'extra_cond': """ and exists(select name from `tabSales Invoice` where name=`tabSales Invoice Item`.parent and ifnull(update_stock, 0) = 1)""" @@ -633,7 +633,7 @@ def make_delivery_note(source_name, target_doc=None): "parent": "against_sales_invoice", "serial_no": "serial_no", "sales_order": "against_sales_order", - "so_detail": "prevdoc_detail_docname" + "so_detail": "so_detail" }, "postprocess": update_item }, diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index d173abeb8e..5d778149df 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -334,8 +334,8 @@ class SellingController(StockController): # But in this case reserved qty should only be reduced by 10 and not 12 already_delivered_qty = self.get_already_delivered_qty(self.name, - d.against_sales_order, d.prevdoc_detail_docname) - so_qty, reserved_warehouse = self.get_so_qty_and_warehouse(d.prevdoc_detail_docname) + d.against_sales_order, d.so_detail) + so_qty, reserved_warehouse = self.get_so_qty_and_warehouse(d.so_detail) if already_delivered_qty + d.qty > so_qty: reserved_qty_for_main_item = -(so_qty - already_delivered_qty) @@ -377,7 +377,7 @@ class SellingController(StockController): def get_already_delivered_qty(self, dn, so, so_detail): qty = frappe.db.sql("""select sum(qty) from `tabDelivery Note Item` - where prevdoc_detail_docname = %s and docstatus = 1 + where so_detail = %s and docstatus = 1 and against_sales_order = %s and parent != %s""", (so_detail, so, dn)) return qty and flt(qty[0][0]) or 0.0 diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 52dd66cf0f..1a45c59442 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -84,3 +84,4 @@ erpnext.patches.v4_2.cost_of_production_cycle erpnext.patches.v4_2.seprate_manufacture_and_repack erpnext.patches.v4_2.party_model erpnext.patches.v5_0.update_frozen_accounts_permission_role +erpnext.patches.v5_0.update_dn_against_doc_fields diff --git a/erpnext/patches/v5_0/update_dn_against_doc_fields.py b/erpnext/patches/v5_0/update_dn_against_doc_fields.py new file mode 100644 index 0000000000..e8780a7394 --- /dev/null +++ b/erpnext/patches/v5_0/update_dn_against_doc_fields.py @@ -0,0 +1,13 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +import frappe + +def execute(): + frappe.reload_doc('stock', 'doctype', 'delivery_note_item') + + frappe.db.sql("""update `tabDelivery Note Item` set so_detail = prevdoc_detail_docname + where ifnull(against_sales_order, '') != ''""") + + frappe.db.sql("""update `tabDelivery Note Item` set si_detail = prevdoc_detail_docname + where ifnull(against_sales_invoice, '') != ''""") diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index b24d297b65..e59d209fd4 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -294,7 +294,7 @@ def make_delivery_note(source_name, target_doc=None): "doctype": "Delivery Note Item", "field_map": { "rate": "rate", - "name": "prevdoc_detail_docname", + "name": "so_detail", "parent": "against_sales_order", }, "postprocess": update_item, diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index c7ec8937d7..8195a1b68b 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -85,7 +85,7 @@ class TestSalesOrder(unittest.TestCase): dn = frappe.get_doc(frappe.copy_doc(dn_test_records[0])) dn.get("delivery_note_details")[0].item_code = so.get("sales_order_details")[0].item_code dn.get("delivery_note_details")[0].against_sales_order = so.name - dn.get("delivery_note_details")[0].prevdoc_detail_docname = so.get("sales_order_details")[0].name + dn.get("delivery_note_details")[0].so_detail = so.get("sales_order_details")[0].name if delivered_qty: dn.get("delivery_note_details")[0].qty = delivered_qty dn.insert() diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 51413c55e0..67a33c9010 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -25,7 +25,7 @@ class DeliveryNote(SellingController): self.status_updater = [{ 'source_dt': 'Delivery Note Item', 'target_dt': 'Sales Order Item', - 'join_field': 'prevdoc_detail_docname', + 'join_field': 'so_detail', 'target_field': 'delivered_qty', 'target_parent_dt': 'Sales Order', 'target_parent_field': 'per_delivered', @@ -129,7 +129,7 @@ class DeliveryNote(SellingController): if cint(frappe.defaults.get_global_default('maintain_same_sales_rate')): super(DeliveryNote, self).validate_with_previous_doc(self.tname, { fn[0] + " Item": { - "ref_dn_field": "prevdoc_detail_docname", + "ref_dn_field": "so_detail", "compare_fields": [["rate", "="]], "is_child_table": True } @@ -328,7 +328,7 @@ def make_sales_invoice(source_name, target_doc=None): "field_map": { "name": "dn_detail", "parent": "delivery_note", - "prevdoc_detail_docname": "so_detail", + "so_detail": "so_detail", "against_sales_order": "sales_order", "serial_no": "serial_no" }, diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index 9fc9aae3fb..57adf3f219 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -373,11 +373,11 @@ "read_only": 1 }, { - "fieldname": "prevdoc_detail_docname", + "fieldname": "so_detail", "fieldtype": "Data", "hidden": 1, "in_filter": 1, - "label": "Against Document Detail No", + "label": "Against Sales Order Item", "no_copy": 1, "oldfieldname": "prevdoc_detail_docname", "oldfieldtype": "Data", @@ -393,7 +393,7 @@ "fieldtype": "Data", "hidden": 1, "in_filter": 1, - "label": "SI Detail", + "label": "Against Sales Invoice Item", "no_copy": 1, "permlevel": 0, "precision": "", @@ -438,7 +438,7 @@ ], "idx": 1, "istable": 1, - "modified": "2014-10-07 18:18:04.375810", + "modified": "2014-10-08 11:11:59.411329", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item",