2013-03-25 05:37:12 +00:00
|
|
|
import webnotes
|
|
|
|
|
|
|
|
def execute():
|
2013-03-29 15:10:23 +00:00
|
|
|
webnotes.reload_doc("accounts", "doctype", "purchase_invoice_item")
|
2013-04-09 09:01:14 +00:00
|
|
|
webnotes.conn.auto_commit_on_many_writes = True
|
2013-03-26 09:19:25 +00:00
|
|
|
for purchase_invoice in webnotes.conn.sql_list("""select distinct parent
|
2013-03-25 05:37:12 +00:00
|
|
|
from `tabPurchase Invoice Item` where docstatus = 1 and ifnull(valuation_rate, 0)=0"""):
|
|
|
|
pi = webnotes.get_obj("Purchase Invoice", purchase_invoice)
|
2013-04-09 09:01:14 +00:00
|
|
|
try:
|
|
|
|
pi.calculate_taxes_and_totals()
|
|
|
|
except:
|
|
|
|
pass
|
2013-03-25 05:37:12 +00:00
|
|
|
pi.update_raw_material_cost()
|
|
|
|
pi.update_valuation_rate("entries")
|
|
|
|
for item in pi.doclist.get({"parentfield": "entries"}):
|
2013-04-01 11:53:43 +00:00
|
|
|
webnotes.conn.sql("""update `tabPurchase Invoice Item` set valuation_rate = %s
|
|
|
|
where name = %s""", (item.valuation_rate, item.name))
|
2013-04-09 09:01:14 +00:00
|
|
|
|
|
|
|
webnotes.conn.auto_commit_on_many_writes = False
|