brotherton-erpnext/patches/march_2013/p07_update_valuation_rate.py
Anand Doshi 234b8e3de3 Merge branch 'master' into edge
Conflicts:
	patches/march_2013/p07_update_valuation_rate.py
	patches/patch_list.py
2013-04-02 16:06:43 +05:30

15 lines
634 B
Python

import webnotes
def execute():
webnotes.reload_doc("accounts", "doctype", "purchase_invoice_item")
for purchase_invoice in webnotes.conn.sql_list("""select distinct parent
from `tabPurchase Invoice Item` where docstatus = 1 and ifnull(valuation_rate, 0)=0"""):
pi = webnotes.get_obj("Purchase Invoice", purchase_invoice)
pi.calculate_taxes_and_totals()
pi.update_raw_material_cost()
pi.update_valuation_rate("entries")
for item in pi.doclist.get({"parentfield": "entries"}):
webnotes.conn.sql("""update `tabPurchase Invoice Item` set valuation_rate = %s
where name = %s""", (item.valuation_rate, item.name))