[company] [setup] added on_doctype_update to add indexes, renamed make_obj to make_controller

This commit is contained in:
Rushabh Mehta 2013-06-28 12:49:28 +05:30
parent e5dfc6c440
commit 03e9a4ea11
6 changed files with 33 additions and 32 deletions

View File

@ -49,7 +49,7 @@ def execute():
for key in custom_map["Timesheet Detail"]:
tl.doc.fields[key] = tsd.fields.get(key)
tl.make_obj()
tl.make_controller()
tl.controller.set_status()
tl.controller.calculate_total_hours()
tl.doc.insert()

View File

@ -190,29 +190,19 @@ class DocType:
self.doc.letter_head = header
def set_default_accounts(self):
if not self.doc.receivables_group and webnotes.conn.exists('Account',
'Accounts Receivable - ' + self.doc.abbr):
webnotes.conn.set(self.doc, 'receivables_group', 'Accounts Receivable - ' +
self.doc.abbr)
accounts = {
"receivables_group": "Accounts Receivable",
"payables_group": "Accounts Payable",
"stock_received_but_not_billed": "Stock Received But Not Billed",
"stock_in_hand_account": "Stock In Hand",
"stock_adjustment_account": "Stock Adjustment",
"expenses_included_in_valuation": "Expenses Included In Valuation"
}
if not self.doc.payables_group and webnotes.conn.exists('Account',
'Accounts Payable - ' + self.doc.abbr):
webnotes.conn.set(self.doc, 'payables_group', 'Accounts Payable - ' + self.doc.abbr)
if not self.doc.stock_received_but_not_billed and webnotes.conn.exists("Account",
"Stock Received But Not Billed - " + self.doc.abbr):
webnotes.conn.set(self.doc, "stock_received_but_not_billed",
"Stock Received But Not Billed - " + self.doc.abbr)
if not self.doc.stock_adjustment_account and webnotes.conn.exists("Account",
"Stock Adjustment - " + self.doc.abbr):
webnotes.conn.set(self.doc, "stock_adjustment_account", "Stock Adjustment - " +
self.doc.abbr)
if not self.doc.expenses_included_in_valuation and webnotes.conn.exists("Account",
"Expenses Included In Valuation - " + self.doc.abbr):
webnotes.conn.set(self.doc, "expenses_included_in_valuation",
"Expenses Included In Valuation - " + self.doc.abbr)
for a in accounts:
account_name = accounts[a] + " - " + self.doc.abbr
if not self.doc.fields[a] and webnotes.conn.exists("Account", account_name):
webnotes.conn.set(self.doc, account_name)
if not self.doc.stock_adjustment_cost_center:
webnotes.conn.set(self.doc, "stock_adjustment_cost_center", self.doc.cost_center)
@ -249,8 +239,7 @@ class DocType:
where company=%s and docstatus<2 limit 1""", self.doc.name):
self.create_default_accounts()
if not webnotes.conn.sql("""select name from `tabCost Center`
where cost_center_name = 'All Units' and company_name = %s""", self.doc.name):
if not self.doc.cost_center:
self.create_default_cost_center()
self.set_default_accounts()

View File

@ -120,3 +120,12 @@ class DocType(DocListController):
if not self.doc.posting_time or self.doc.posting_time == '00:0':
self.doc.posting_time = '00:00'
def on_doctype_update(self):
webnotes.msgprint(webnotes.conn.sql("""show index from `tabStock Ledger Entry`
where Key_name="posting_sort_index" """))
if not webnotes.conn.sql("""show index from `tabStock Ledger Entry`
where Key_name="posting_sort_index" """):
webnotes.conn.commit()
webnotes.conn.sql("""alter table `tabStock Ledger Entry`
add index posting_sort_index(posting_date, posting_time, name)""")
webnotes.conn.begin()

View File

@ -2,7 +2,7 @@
{
"creation": "2013-01-29 19:25:42",
"docstatus": 0,
"modified": "2013-03-25 16:04:59",
"modified": "2013-06-28 12:39:07",
"modified_by": "Administrator",
"owner": "Administrator"
},

View File

@ -45,9 +45,12 @@ class DocType(StockController):
return
data = json.loads(self.doc.reconciliation_json)
# strip out extra columns (if any)
data = [row[:4] for row in data]
if self.head_row not in data:
msgprint(_("""Hey! You seem to be using the wrong template. \
Click on 'Download Template' button to get the correct template."""),
msgprint(_("""Wrong Template: Unable to find head row."""),
raise_exception=1)
# remove the help part and save the json

View File

@ -42,7 +42,7 @@ class DocType:
bin_wrapper.ignore_permissions = 1
bin_wrapper.insert()
bin_obj = bin_wrapper.make_obj()
bin_obj = bin_wrapper.make_controller()
else:
bin_obj = get_obj('Bin', bin)
return bin_obj