diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 72034d8d297..c675bd2e22b 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -11,7 +11,7 @@ import frappe.defaults from erpnext.controllers.buying_controller import BuyingController from erpnext.accounts.party import get_party_account, get_due_date from erpnext.accounts.utils import get_account_currency -from erpnext.stock.doctype.purchase_receipt.purchase_receipt import update_billing_amount_based_on_po +from erpnext.stock.doctype.purchase_receipt.purchase_receipt import update_billed_amount_based_on_po form_grid_templates = { "items": "templates/form_grid/item_grid.html" @@ -438,11 +438,14 @@ class PurchaseInvoice(BuyingController): def update_billing_status_in_pr(self, set_modified=True): updated_pr = [] for d in self.get("items"): - if d.pr_detail and not d.po_detail: - frappe.db.set_value("Purchase Receipt Item", d.pr_detail, "billed_amt", d.amount) + if d.pr_detail: + billed_amt = frappe.db.sql("""select sum(amount) from `tabPurchase Invoice Item` + where pr_detail=%s and docstatus=1""", d.pr_detail) + billed_amt = billed_amt and billed_amt[0][0] or 0 + frappe.db.set_value("Purchase Receipt Item", d.pr_detail, "billed_amt", billed_amt) updated_pr.append(d.purchase_receipt) elif d.po_detail: - updated_pr += update_billing_amount_based_on_po(d.po_detail) + updated_pr += update_billed_amount_based_on_po(d.po_detail) for pr in set(updated_pr): frappe.get_doc("Purchase Receipt", pr).update_billing_percentage(set_modified=set_modified) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 1a80f7b7d85..241d9b7c73e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -12,7 +12,7 @@ from frappe.model.mapper import get_mapped_doc from erpnext.controllers.selling_controller import SellingController from erpnext.accounts.utils import get_account_currency -from erpnext.stock.doctype.delivery_note.delivery_note import update_billing_amount_based_on_so +from erpnext.stock.doctype.delivery_note.delivery_note import update_billed_amount_based_on_so form_grid_templates = { "items": "templates/form_grid/item_grid.html" @@ -637,11 +637,14 @@ class SalesInvoice(SellingController): def update_billing_status_in_dn(self, set_modified=True): updated_delivery_notes = [] for d in self.get("items"): - if d.dn_detail and not d.so_detail: - frappe.db.set_value("Delivery Note Item", d.dn_detail, "billed_amt", d.amount) + if d.dn_detail: + billed_amt = frappe.db.sql("""select sum(amount) from `tabSales Invoice Item` + where dn_detail=%s and docstatus=1""", d.dn_detail) + billed_amt = billed_amt and billed_amt[0][0] or 0 + frappe.db.set_value("Delivery Note Item", d.dn_detail, "billed_amt", billed_amt) updated_delivery_notes.append(d.delivery_note) elif d.so_detail: - updated_delivery_notes += update_billing_amount_based_on_so(d.so_detail) + updated_delivery_notes += update_billed_amount_based_on_so(d.so_detail) for dn in set(updated_delivery_notes): frappe.get_doc("Delivery Note", dn).update_billing_percentage(set_modified=set_modified) diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 872d5fd7c7d..73722188aa2 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -249,7 +249,7 @@ class StatusUpdater(Document): 'Fully %(keyword)s', 'Partly %(keyword)s')) where name='%(name)s'""" % args) - if args.get("set_modified"): + if change_modified: target = frappe.get_doc(args["target_parent_dt"], args["name"]) target.set_status(update=True) target.notify_update() diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 612a44732ac..e919e922629 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -240,3 +240,4 @@ erpnext.patches.v6_10.fix_billed_amount_in_drop_ship_po erpnext.patches.v6_10.fix_delivery_status_of_drop_ship_item #2015-12-08 erpnext.patches.v5_8.tax_rule #2015-12-08 erpnext.patches.v6_12.set_overdue_tasks +erpnext.patches.v6_16.update_billing_status_in_dn_and_pr \ No newline at end of file diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index c6faacdb891..2a2575a2cb2 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -275,7 +275,7 @@ class DeliveryNote(SellingController): if d.si_detail and not d.so_detail: frappe.db.set(d, 'billed_amt', d.amount) elif d.so_detail: - updated_delivery_notes += update_billing_amount_based_on_so(d.so_detail) + updated_delivery_notes += update_billed_amount_based_on_so(d.so_detail) for dn in set(updated_delivery_notes): dn_doc = self if (dn == self.name) else frappe.get_doc("Delivery Note", dn) @@ -283,7 +283,7 @@ class DeliveryNote(SellingController): self.load_from_db() -def update_billing_amount_based_on_so(so_detail): +def update_billed_amount_based_on_so(so_detail): # Billed against Sales Order directly billed_against_so = frappe.db.sql("""select sum(amount) from `tabSales Invoice Item` where so_detail=%s and (dn_detail is null or dn_detail = '') and docstatus=1""", so_detail) diff --git a/erpnext/stock/doctype/delivery_note/delivery_note_list.js b/erpnext/stock/doctype/delivery_note/delivery_note_list.js index 70c16d898e0..f1ad92914ba 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note_list.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note_list.js @@ -1,5 +1,5 @@ frappe.listview_settings['Delivery Note'] = { - add_fields: ["customer", "customer_name", "base_grand_total", "per_installed", + add_fields: ["customer", "customer_name", "base_grand_total", "per_installed", "per_billed", "transporter_name", "grand_total", "is_return", "status"], get_indicator: function(doc) { if(cint(doc.is_return)==1) { diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 50545861e9b..25709da57dd 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -444,8 +444,7 @@ class PurchaseReceipt(BuyingController): updated_pr = [self.name] for d in self.get("items"): if d.prevdoc_detail_docname: - updated_pr += update_billing_amount_based_on_po(d.prevdoc_detail_docname) - d.billed_amt = frappe.db.get_value("Purchase Receipt Item", d.name, "billed_amt") + updated_pr += update_billed_amount_based_on_po(d.prevdoc_detail_docname) for pr in set(updated_pr): pr_doc = self if (pr == self.name) else frappe.get_doc("Purchase Receipt", pr) @@ -453,7 +452,7 @@ class PurchaseReceipt(BuyingController): self.load_from_db() -def update_billing_amount_based_on_po(po_detail): +def update_billed_amount_based_on_po(po_detail): # Billed against Sales Order directly billed_against_po = frappe.db.sql("""select sum(amount) from `tabPurchase Invoice Item` where po_detail=%s and (pr_detail is null or pr_detail = '') and docstatus=1""", po_detail) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js index 63148995fac..5c57fb5f010 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js @@ -1,11 +1,15 @@ frappe.listview_settings['Purchase Receipt'] = { add_fields: ["supplier", "supplier_name", "base_grand_total", "is_subcontracted", - "transporter_name", "is_return", "status"], + "transporter_name", "is_return", "status", "per_billed"], get_indicator: function(doc) { if(cint(doc.is_return)==1) { return [__("Return"), "darkgrey", "is_return,=,Yes"]; } else if(doc.status==="Closed") { return [__("Closed"), "green", "status,=,Closed"]; - } + } else if (flt(doc.per_billed, 2) < 100) { + return [__("To Bill"), "orange", "per_billed,<,100"]; + } else if (flt(doc.per_billed, 2) == 100) { + return [__("Completed"), "green", "per_billed,=,100"]; + } } };