brotherton-erpnext/erpnext/patches/v6_27/fix_recurring_order_status.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.9 KiB
Python
Raw Normal View History

# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for doc in (
{
"doctype": "Sales Order",
"stock_doctype": "Delivery Note",
"invoice_doctype": "Sales Invoice",
"stock_doctype_ref_field": "against_sales_order",
2016-03-22 05:31:31 +00:00
"invoice_ref_field": "sales_order",
"qty_field": "delivered_qty"
},
{
"doctype": "Purchase Order",
"stock_doctype": "Purchase Receipt",
"invoice_doctype": "Purchase Invoice",
"stock_doctype_ref_field": "prevdoc_docname",
2016-03-22 05:31:31 +00:00
"invoice_ref_field": "purchase_order",
"qty_field": "received_qty"
}):
2016-03-22 05:31:31 +00:00
order_list = frappe.db.sql("""select name from `tab{0}`
where docstatus=1 and is_recurring=1
and ifnull(recurring_id, '') != name and creation >= '2016-01-25'"""
.format(doc["doctype"]), as_dict=1)
2016-03-22 05:31:31 +00:00
for order in order_list:
2016-03-22 05:31:31 +00:00
frappe.db.sql("""update `tab{0} Item`
set {1}=0, billed_amt=0 where parent=%s""".format(doc["doctype"],
doc["qty_field"]), order.name)
# Check against Delivery Note and Purchase Receipt
2016-03-22 05:31:31 +00:00
stock_doc_list = frappe.db.sql("""select distinct parent from `tab{0} Item`
where docstatus=1 and ifnull({1}, '')=%s"""
.format(doc["stock_doctype"], doc["stock_doctype_ref_field"]), order.name)
2016-03-22 05:31:31 +00:00
if stock_doc_list:
for dn in stock_doc_list:
frappe.get_doc(doc["stock_doctype"], dn[0]).update_qty(update_modified=False)
2016-03-22 05:31:31 +00:00
# Check against Invoice
2016-03-22 05:31:31 +00:00
invoice_list = frappe.db.sql("""select distinct parent from `tab{0} Item`
where docstatus=1 and ifnull({1}, '')=%s"""
.format(doc["invoice_doctype"], doc["invoice_ref_field"]), order.name)
2016-03-22 05:31:31 +00:00
if invoice_list:
for dn in invoice_list:
frappe.get_doc(doc["invoice_doctype"], dn[0]).update_qty(update_modified=False)
2016-03-22 05:31:31 +00:00
frappe.get_doc(doc["doctype"], order.name).set_status(update=True, update_modified=False)