[report] Added delay in payment column
This commit is contained in:
parent
9c044eefff
commit
b4a51ec80b
@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from erpnext.accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
|
from erpnext.accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt, getdate
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters = {}
|
if not filters: filters = {}
|
||||||
@ -13,24 +13,26 @@ def execute(filters=None):
|
|||||||
|
|
||||||
columns = get_columns(filters)
|
columns = get_columns(filters)
|
||||||
entries = get_entries(filters)
|
entries = get_entries(filters)
|
||||||
invoice_posting_date_map = get_invoice_posting_date_map(filters)
|
invoice_details = get_invoice_posting_date_map(filters)
|
||||||
against_date = ""
|
against_date = ""
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for d in entries:
|
for d in entries:
|
||||||
against_date = invoice_posting_date_map.get(d.reference_name) or ""
|
invoice = invoice_details.get(d.reference_name) or frappe._dict()
|
||||||
if d.reference_type=="Purchase Invoice":
|
if d.reference_type=="Purchase Invoice":
|
||||||
payment_amount = flt(d.debit) or -1 * flt(d.credit)
|
payment_amount = flt(d.debit) or -1 * flt(d.credit)
|
||||||
else:
|
else:
|
||||||
payment_amount = flt(d.credit) or -1 * flt(d.debit)
|
payment_amount = flt(d.credit) or -1 * flt(d.debit)
|
||||||
|
|
||||||
row = [d.name, d.party_type, d.party, d.posting_date, d.reference_name,
|
row = [d.name, d.party_type, d.party, d.posting_date, d.reference_name, invoice.posting_date,
|
||||||
against_date, d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark]
|
invoice.due_date, d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark]
|
||||||
|
|
||||||
if d.reference_name:
|
if d.reference_name:
|
||||||
row += get_ageing_data(30, 60, 90, d.posting_date, against_date, payment_amount)
|
row += get_ageing_data(30, 60, 90, d.posting_date, against_date, payment_amount)
|
||||||
else:
|
else:
|
||||||
row += ["", "", "", "", ""]
|
row += ["", "", "", "", ""]
|
||||||
|
if invoice.due_date:
|
||||||
|
row.append((getdate(d.posting_date) - getdate(invoice.due_date)).days or 0)
|
||||||
|
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
|
||||||
@ -43,13 +45,25 @@ def validate_filters(filters):
|
|||||||
.format(filters.payment_type, filters.party_type))
|
.format(filters.payment_type, filters.party_type))
|
||||||
|
|
||||||
def get_columns(filters):
|
def get_columns(filters):
|
||||||
return [_("Journal Entry") + ":Link/Journal Entry:140",
|
return [
|
||||||
_("Party Type") + "::100", _("Party") + ":Dynamic Link/Party Type:140",
|
_("Journal Entry") + ":Link/Journal Entry:140",
|
||||||
|
_("Party Type") + "::100",
|
||||||
|
_("Party") + ":Dynamic Link/Party Type:140",
|
||||||
_("Posting Date") + ":Date:100",
|
_("Posting Date") + ":Date:100",
|
||||||
_("Against Invoice") + (":Link/Purchase Invoice:130" if filters.get("payment_type") == "Outgoing" else ":Link/Sales Invoice:130"),
|
_("Invoice") + (":Link/Purchase Invoice:130" if filters.get("payment_type") == "Outgoing" else ":Link/Sales Invoice:130"),
|
||||||
_("Against Invoice Posting Date") + ":Date:130", _("Debit") + ":Currency:120", _("Credit") + ":Currency:120",
|
_("Invoice Posting Date") + ":Date:130",
|
||||||
_("Reference No") + "::100", _("Reference Date") + ":Date:100", _("Remarks") + "::150", _("Age") +":Int:40",
|
_("Payment Due Date") + ":Date:130",
|
||||||
"0-30:Currency:100", "30-60:Currency:100", "60-90:Currency:100", _("90-Above") + ":Currency:100"
|
_("Debit") + ":Currency:120",
|
||||||
|
_("Credit") + ":Currency:120",
|
||||||
|
_("Reference No") + "::100",
|
||||||
|
_("Reference Date") + ":Date:100",
|
||||||
|
_("Remarks") + "::150",
|
||||||
|
_("Age") +":Int:40",
|
||||||
|
"0-30:Currency:100",
|
||||||
|
"30-60:Currency:100",
|
||||||
|
"60-90:Currency:100",
|
||||||
|
_("90-Above") + ":Currency:100",
|
||||||
|
_("Delay in payment (Days)") + "::150"
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_conditions(filters):
|
def get_conditions(filters):
|
||||||
@ -67,6 +81,13 @@ def get_conditions(filters):
|
|||||||
if filters.get("party"):
|
if filters.get("party"):
|
||||||
conditions.append("jvd.party=%(party)s")
|
conditions.append("jvd.party=%(party)s")
|
||||||
|
|
||||||
|
if filters.get("party_type"):
|
||||||
|
conditions.append("jvd.reference_type=%(reference_type)s")
|
||||||
|
if filters.get("party_type") == "Customer":
|
||||||
|
filters["reference_type"] = "Sales Invoice"
|
||||||
|
else:
|
||||||
|
filters["reference_type"] = "Purchase Invoice"
|
||||||
|
|
||||||
if filters.get("company"):
|
if filters.get("company"):
|
||||||
conditions.append("jv.company=%(company)s")
|
conditions.append("jv.company=%(company)s")
|
||||||
|
|
||||||
@ -89,12 +110,9 @@ def get_entries(filters):
|
|||||||
return entries
|
return entries
|
||||||
|
|
||||||
def get_invoice_posting_date_map(filters):
|
def get_invoice_posting_date_map(filters):
|
||||||
invoice_posting_date_map = {}
|
invoice_details = {}
|
||||||
if filters.get("payment_type") == "Incoming":
|
dt = "Sales Invoice" if filters.get("payment_type") == "Incoming" else "Purchase Invoice"
|
||||||
for t in frappe.db.sql("""select name, posting_date from `tabSales Invoice`"""):
|
for t in frappe.db.sql("select name, posting_date, due_date from `tab{0}`".format(dt), as_dict=1):
|
||||||
invoice_posting_date_map[t[0]] = t[1]
|
invoice_details[t.name] = t
|
||||||
else:
|
|
||||||
for t in frappe.db.sql("""select name, posting_date from `tabPurchase Invoice`"""):
|
|
||||||
invoice_posting_date_map[t[0]] = t[1]
|
|
||||||
|
|
||||||
return invoice_posting_date_map
|
return invoice_details
|
||||||
|
Loading…
x
Reference in New Issue
Block a user