fix: purchase inv shows overdue for fraction of outstanding
This commit is contained in:
@@ -981,6 +981,40 @@ class PurchaseInvoice(BuyingController):
|
|||||||
|
|
||||||
# calculate totals again after applying TDS
|
# calculate totals again after applying TDS
|
||||||
self.calculate_taxes_and_totals()
|
self.calculate_taxes_and_totals()
|
||||||
|
|
||||||
|
def set_status(self, update=False, status=None, update_modified=True):
|
||||||
|
if self.is_new():
|
||||||
|
if self.get('amended_from'):
|
||||||
|
self.status = 'Draft'
|
||||||
|
return
|
||||||
|
|
||||||
|
precision = self.precision("outstanding_amount")
|
||||||
|
outstanding_amount = flt(self.outstanding_amount, precision)
|
||||||
|
due_date = getdate(self.due_date)
|
||||||
|
nowdate = getdate()
|
||||||
|
|
||||||
|
if not status:
|
||||||
|
if self.docstatus == 2:
|
||||||
|
status = "Cancelled"
|
||||||
|
elif self.docstatus == 1:
|
||||||
|
elif outstanding_amount > 0 and due_date < nowdate:
|
||||||
|
self.status = "Overdue"
|
||||||
|
elif outstanding_amount > 0 and due_date >= nowdate:
|
||||||
|
self.status = "Unpaid"
|
||||||
|
#Check if outstanding amount is 0 due to debit note issued against invoice
|
||||||
|
elif outstanding_amount <= 0 and self.is_return == 0 and frappe.db.get_value('Sales Invoice', {'is_return': 1, 'return_against': self.name, 'docstatus': 1}):
|
||||||
|
self.status = "Debit Note Issued"
|
||||||
|
elif self.is_return == 1:
|
||||||
|
self.status = "Return"
|
||||||
|
elif outstanding_amount<=0:
|
||||||
|
self.status = "Paid"
|
||||||
|
else:
|
||||||
|
self.status = "Submitted"
|
||||||
|
else:
|
||||||
|
self.status = "Draft"
|
||||||
|
|
||||||
|
if update:
|
||||||
|
self.db_set('status', self.status, update_modified = update_modified)
|
||||||
|
|
||||||
def get_list_context(context=None):
|
def get_list_context(context=None):
|
||||||
from erpnext.controllers.website_list_for_contact import get_list_context
|
from erpnext.controllers.website_list_for_contact import get_list_context
|
||||||
|
|||||||
@@ -69,17 +69,6 @@ status_map = {
|
|||||||
["Cancelled", "eval:self.docstatus==2"],
|
["Cancelled", "eval:self.docstatus==2"],
|
||||||
["Closed", "eval:self.status=='Closed'"],
|
["Closed", "eval:self.status=='Closed'"],
|
||||||
],
|
],
|
||||||
"Purchase Invoice": [
|
|
||||||
["Draft", None],
|
|
||||||
["Submitted", "eval:self.docstatus==1"],
|
|
||||||
["Paid", "eval:self.outstanding_amount==0 and self.docstatus==1"],
|
|
||||||
["Return", "eval:self.is_return==1 and self.docstatus==1"],
|
|
||||||
["Debit Note Issued",
|
|
||||||
"eval:self.outstanding_amount <= 0 and self.docstatus==1 and self.is_return==0 and get_value('Purchase Invoice', {'is_return': 1, 'return_against': self.name, 'docstatus': 1})"],
|
|
||||||
["Unpaid", "eval:self.outstanding_amount > 0 and getdate(self.due_date) >= getdate(nowdate()) and self.docstatus==1"],
|
|
||||||
["Overdue", "eval:self.outstanding_amount > 0 and getdate(self.due_date) < getdate(nowdate()) and self.docstatus==1"],
|
|
||||||
["Cancelled", "eval:self.docstatus==2"],
|
|
||||||
],
|
|
||||||
"Material Request": [
|
"Material Request": [
|
||||||
["Draft", None],
|
["Draft", None],
|
||||||
["Stopped", "eval:self.status == 'Stopped'"],
|
["Stopped", "eval:self.status == 'Stopped'"],
|
||||||
|
|||||||
Reference in New Issue
Block a user