brotherton-erpnext/patches/march_2013/p03_update_buying_amount.py

30 lines
1.3 KiB
Python
Raw Normal View History

2013-03-11 11:02:33 +00:00
import webnotes
2013-03-29 11:12:33 +00:00
from webnotes.utils import now_datetime
2013-03-11 11:02:33 +00:00
def execute():
2013-03-29 15:10:23 +00:00
webnotes.reload_doc("stock", "doctype", "delivery_note_item")
webnotes.reload_doc("accounts", "doctype", "sales_invoice_item")
2013-03-29 11:12:33 +00:00
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 11:02:33 +00:00
2013-03-29 11:12:33 +00:00
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