brotherton-erpnext/patches/march_2013/p03_update_buying_amount.py

30 lines
1.3 KiB
Python
Raw Normal View History

2013-03-11 16:32:33 +05:30
import webnotes
2013-03-29 16:42:33 +05:30
from webnotes.utils import now_datetime
2013-03-11 16:32:33 +05:30
def execute():
2013-03-29 20:40:23 +05:30
webnotes.reload_doc("stock", "doctype", "delivery_note_item")
webnotes.reload_doc("accounts", "doctype", "sales_invoice_item")
2013-03-29 16:42:33 +05:30
webnotes.conn.auto_commit_on_many_writes = True
for company in webnotes.conn.sql("select name from `tabCompany`"):
stock_ledger_entries = webnotes.conn.sql("""select item_code, voucher_type, voucher_no,
voucher_detail_no, posting_date, posting_time, stock_value,
warehouse, actual_qty as qty from `tabStock Ledger Entry`
where ifnull(`is_cancelled`, "No") = "No" and company = %s
order by item_code desc, warehouse desc,
posting_date desc, posting_time desc, name desc""", company[0], as_dict=True)
2013-03-11 16:32:33 +05:30
2013-03-29 16:42:33 +05:30
dn_list = webnotes.conn.sql("""select name from `tabDelivery Note`
where docstatus < 2 and company = %s""", company[0])
for dn in dn_list:
dn = webnotes.get_obj("Delivery Note", dn[0], with_children = 1)
dn.set_buying_amount(stock_ledger_entries)
si_list = webnotes.conn.sql("""select name from `tabSales Invoice`
where docstatus < 2 and company = %s""", company[0])
for si in si_list:
si = webnotes.get_obj("Sales Invoice", si[0], with_children = 1)
si.set_buying_amount(stock_ledger_entries)
webnotes.conn.auto_commit_on_many_writes = False