[patch] Update billing status in Delivery Note and Purchase Receipt

This commit is contained in:
Nabin Hait 2016-01-01 13:58:03 +05:30 committed by Anand Doshi
parent c040075bd4
commit 1eea26fc5c
3 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,4 @@
- Billing Status in Delivery Note (DN) and Purchase Receipt (PR)
- If Invoice made directly against DN/PR, calculate based on actual billed amount
- If Invoice made via Sales Order/Purchase Order, allocate billed amount in DN/PR based on FIFO
- Billing status updated in existing DN/PR

View File

@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@ -0,0 +1,33 @@
# Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for dt in ("Delivery Note", "Purchase Receipt"):
frappe.reload_doctype(dt)
frappe.reload_doctype(dt + " Item")
# Update billed_amt in DN and PR which are not against any order
for d in frappe.db.sql("""select name from `tabDelivery Note Item`
where (so_detail is null or so_detail = '') and docstatus=1""", as_dict=1):
billed_amt = frappe.db.sql("""select sum(amount) from `tabSales Invoice Item`
where dn_detail=%s and docstatus=1""", d.name)
billed_amt = billed_amt and billed_amt[0][0] or 0
frappe.db.set_value("Delivery Note Item", d.name, "billed_amt", billed_amt)
# Update billed_amt in DN and PR which are not against any order
for d in frappe.db.sql("""select name from `tabPurchase Receipt Item`
where (prevdoc_detail_docname is null or prevdoc_detail_docname = '') and docstatus=1""", as_dict=1):
billed_amt = frappe.db.sql("""select sum(amount) from `tabPurchase Invoice Item`
where pr_detail=%s and docstatus=1""", d.name)
billed_amt = billed_amt and billed_amt[0][0] or 0
frappe.db.set_value("Purchase Receipt Item", d.name, "billed_amt", billed_amt)
# Update billed amt which are against order or invoice
# Update billing status for all
for d in frappe.db.sql("select name from `tab{0}` where docstatus=1".format(dt), as_dict=1):
doc = frappe.get_doc(dt, d.name)
doc.update_billing_status(set_modified=False)
doc.set_status(update=True, update_modified=False)