brotherton-erpnext/erpnext/patches/v7_1/update_invoice_status.py

30 lines
1.0 KiB
Python

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc('accounts', 'doctype', 'sales_invoice')
frappe.reload_doc('accounts', 'doctype', 'purchase_invoice')
frappe.db.sql("""
update
`tabPurchase Invoice`
set
status = (Case When outstanding_amount = 0 and docstatus = 1 then 'Paid'
when due_date < CURDATE() and outstanding_amount > 0 and docstatus =1 then 'Overdue'
when due_date >= CURDATE() and outstanding_amount > 0 and docstatus =1 then 'Unpaid'
when docstatus = 2 then 'Cancelled'
else 'Draft'
End)""")
frappe.db.sql("""
update
`tabSales Invoice`
set status = (Case When outstanding_amount = 0 and docstatus = 1 then 'Paid'
when due_date < CURDATE() and outstanding_amount > 0 and docstatus =1 then 'Overdue'
when due_date >= CURDATE() and outstanding_amount > 0 and docstatus =1 then 'Unpaid'
when docstatus = 2 then 'Cancelled'
else 'Draft'
End)""")