mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 18:59:08 +00:00
[merge]
This commit is contained in:
@@ -1,10 +1,33 @@
|
||||
import webnotes
|
||||
from webnotes.utils import now_datetime
|
||||
|
||||
def execute():
|
||||
dn_list = webnotes.conn.sql("""select name from `tabDelivery Note` where docstatus < 2""")
|
||||
for dn in dn_list:
|
||||
webnotes.bean("Delivery Note", dn[0]).run_method("set_buying_amount")
|
||||
webnotes.reload_doc("stock", "doctype", "delivery_note_item")
|
||||
webnotes.reload_doc("accounts", "doctype", "sales_invoice_item")
|
||||
|
||||
webnotes.conn.auto_commit_on_many_writes = True
|
||||
for company in webnotes.conn.sql("select name from `tabCompany`"):
|
||||
print company[0]
|
||||
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)
|
||||
|
||||
si_list = webnotes.conn.sql("""select name from `tabSales Invoice` where docstatus < 2""")
|
||||
for si in si_list:
|
||||
webnotes.bean("Sales Invoice", si[0]).run_method("set_buying_amount")
|
||||
dn_list = webnotes.conn.sql("""select name from `tabDelivery Note`
|
||||
where docstatus < 2 and company = %s""", company[0])
|
||||
print "Total Delivery Note: ", len(dn_list)
|
||||
|
||||
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])
|
||||
print "Total Sales Invoice: ", len(si_list)
|
||||
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
|
||||
@@ -1,6 +1,8 @@
|
||||
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)
|
||||
@@ -10,4 +12,4 @@ def execute():
|
||||
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))
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import webnotes
|
||||
def execute():
|
||||
webnotes.reload_doc("setup", "doctype", "company")
|
||||
|
||||
add_group_accounts()
|
||||
add_ledger_accounts()
|
||||
add_aii_cost_center()
|
||||
set_default_accounts()
|
||||
|
||||
def set_default_accounts():
|
||||
for company in webnotes.conn.sql_list("select name from `tabCompany`"):
|
||||
webnotes.get_obj("Company", company).set_default_accounts()
|
||||
|
||||
def _check(parent_account, company):
|
||||
def _get_root(is_pl_account, debit_or_credit):
|
||||
@@ -34,7 +42,6 @@ def add_group_accounts():
|
||||
def add_ledger_accounts():
|
||||
accounts_to_add = [
|
||||
["Stock In Hand", "Stock Assets", "Ledger", ""],
|
||||
["Stock Debit But Not Billed", "Stock Assets", "Ledger", ""],
|
||||
["Cost of Goods Sold", "Stock Expenses", "Ledger", "Expense Account"],
|
||||
["Stock Adjustment", "Stock Expenses", "Ledger", "Expense Account"],
|
||||
["Expenses Included In Valuation", "Stock Expenses", "Ledger", "Expense Account"],
|
||||
@@ -45,6 +52,14 @@ def add_ledger_accounts():
|
||||
|
||||
def add_accounts(accounts_to_add, check_fn=None):
|
||||
for company, abbr in webnotes.conn.sql("""select name, abbr from `tabCompany`"""):
|
||||
count = webnotes.conn.sql("""select count(name) from `tabAccount`
|
||||
where company=%s and ifnull(parent_account, '')=''""", company)[0][0]
|
||||
|
||||
if count > 4:
|
||||
print "Company", company, \
|
||||
"has more than 4 root accounts. cannot apply patch to this company."
|
||||
continue
|
||||
|
||||
for account_name, parent_account_name, group_or_ledger, account_type in accounts_to_add:
|
||||
if not webnotes.conn.exists("Account", "%s - %s" % (account_name, abbr)):
|
||||
parent_account = "%s - %s" % (parent_account_name, abbr)
|
||||
@@ -58,4 +73,25 @@ def add_accounts(accounts_to_add, check_fn=None):
|
||||
"account_type": account_type,
|
||||
"company": company
|
||||
})
|
||||
account.insert()
|
||||
account.insert()
|
||||
|
||||
def add_aii_cost_center():
|
||||
for company, abbr in webnotes.conn.sql("""select name, abbr from `tabCompany`"""):
|
||||
if not webnotes.conn.exists("Cost Center", "Auto Inventory Accounting - %s" % abbr):
|
||||
parent_cost_center = webnotes.conn.get_value("Cost Center",
|
||||
{"parent_cost_center['']": '', "company_name": company})
|
||||
|
||||
if not parent_cost_center:
|
||||
print "Company", company, "does not have a root cost center"
|
||||
continue
|
||||
|
||||
cc = webnotes.bean({
|
||||
"doctype": "Cost Center",
|
||||
"cost_center_name": "Auto Inventory Accounting",
|
||||
"parent_cost_center": parent_cost_center,
|
||||
"group_or_ledger": "Ledger",
|
||||
"company_name": company
|
||||
})
|
||||
cc.insert()
|
||||
|
||||
|
||||
@@ -227,5 +227,8 @@ patch_list = [
|
||||
"patches.march_2013.p10_update_against_expense_account",
|
||||
"patches.march_2013.p11_update_attach_files",
|
||||
"patches.march_2013.p12_set_item_tax_rate_in_json",
|
||||
"patches.march_2013.p07_update_valuation_rate",
|
||||
"patches.march_2013.p08_create_aii_accounts",
|
||||
"patches.march_2013.p03_update_buying_amount",
|
||||
"patches.april_2013.p01_update_serial_no_valuation_rate",
|
||||
]
|
||||
Reference in New Issue
Block a user