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

This commit is contained in:
Nabin Hait 2016-01-01 13:50:47 +05:30 committed by Anand Doshi
parent a2afb16f6b
commit c040075bd4
8 changed files with 27 additions and 17 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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)

View File

@ -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) {

View File

@ -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)

View File

@ -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"];
}
}
};