Merge branch 'master' into edge

This commit is contained in:
Nabin Hait 2013-03-26 11:01:45 +05:30
commit d216390bcb
36 changed files with 498 additions and 276 deletions

View File

@ -1,34 +0,0 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from webnotes.utils import flt
from webnotes.model.code import get_obj
from accounts.utils import get_balance_on
@webnotes.whitelist()
def get_default_bank_account():
"""
Get default bank account for a company
"""
company = webnotes.form_dict.get('company')
if not company: return
res = webnotes.conn.sql("""\
SELECT default_bank_account FROM `tabCompany`
WHERE name=%s AND docstatus<2""", company)
if res: return res[0][0]

View File

@ -48,15 +48,17 @@ class DocType:
from tabAccount where name =%s""", self.doc.parent_account) from tabAccount where name =%s""", self.doc.parent_account)
if not par: if not par:
msgprint("Parent account does not exists", raise_exception=1) msgprint("Parent account does not exists", raise_exception=1)
elif par and par[0][0] == self.doc.name: elif par[0][0] == self.doc.name:
msgprint("You can not assign itself as parent account", raise_exception=1) msgprint("You can not assign itself as parent account", raise_exception=1)
elif par and par[0][1] != 'Group': elif par[0][1] != 'Group':
msgprint("Parent account can not be a ledger", raise_exception=1) msgprint("Parent account can not be a ledger", raise_exception=1)
elif par and self.doc.debit_or_credit and par[0][3] != self.doc.debit_or_credit: elif self.doc.debit_or_credit and par[0][3] != self.doc.debit_or_credit:
msgprint("You can not move a %s account under %s account" % msgprint("You can not move a %s account under %s account" %
(self.doc.debit_or_credit, par[0][3]), raise_exception=1) (self.doc.debit_or_credit, par[0][3]), raise_exception=1)
elif par and not self.doc.is_pl_account:
if not self.doc.is_pl_account:
self.doc.is_pl_account = par[0][2] self.doc.is_pl_account = par[0][2]
if not self.doc.debit_or_credit:
self.doc.debit_or_credit = par[0][3] self.doc.debit_or_credit = par[0][3]
def validate_max_root_accounts(self): def validate_max_root_accounts(self):

View File

@ -137,23 +137,29 @@ cur_frm.cscript.view_ledger_entry = function(doc,cdt,cdn){
cur_frm.cscript.voucher_type = function(doc, cdt, cdn) { cur_frm.cscript.voucher_type = function(doc, cdt, cdn) {
if(doc.voucher_type == 'Bank Voucher' && cstr(doc.company)) { cur_frm.set_df_property("cheque_no", "reqd", doc.voucher_type=="Bank Voucher");
cur_frm.set_df_property("cheque_no", "reqd", true); cur_frm.set_df_property("cheque_date", "reqd", doc.voucher_type=="Bank Voucher");
cur_frm.set_df_property("cheque_date", "reqd", true);
var children = getchildren('Journal Voucher Detail', doc.name, 'entries'); if(in_list(["Bank Voucher", "Cash Voucher"], doc.voucher_type)
if(!children || children.length==0) { && doc.company
$c('accounts.get_default_bank_account', {company: doc.company }, function(r, rt) { && wn.model.get("Journal Voucher Detail", {"parent":doc.name}).length==0) {
if(!r.exc) { wn.call({
var jvd = wn.model.add_child(doc, 'Journal Voucher Detail', 'entries'); type: "GET",
jvd.account = cstr(r.message); method: "accounts.doctype.journal_voucher.journal_voucher.get_default_bank_cash_account",
refresh_field('entries'); args: {
"voucher_type": doc.voucher_type,
"company": doc.company
},
callback: function(r) {
if(r.message) {
var jvdetail = wn.model.add_child(doc, "Journal Voucher Detail", "entries");
jvdetail.account = r.message.account;
// this is a data field????
jvdetail.balance = format_currency(r.message.balance);
refresh_field("entries");
} }
});
} }
} else { })
cur_frm.set_df_property("cheque_no", "reqd", false);
cur_frm.set_df_property("cheque_date", "reqd", false);
} }
} }

View File

@ -68,6 +68,11 @@ class DocType(AccountsController):
self.make_gl_entries(cancel=1) self.make_gl_entries(cancel=1)
def on_trash(self):
pass
#if self.doc.amended_from:
# webnotes.delete_doc("Journal Voucher", self.doc.amended_from)
def validate_debit_credit(self): def validate_debit_credit(self):
for d in getlist(self.doclist, 'entries'): for d in getlist(self.doclist, 'entries'):
if d.debit and d.credit: if d.debit and d.credit:
@ -344,6 +349,16 @@ class DocType(AccountsController):
from `tabPurchase Invoice` where docstatus = 1 and company = %s from `tabPurchase Invoice` where docstatus = 1 and company = %s
and outstanding_amount > 0 %s""" % ('%s', cond), self.doc.company) and outstanding_amount > 0 %s""" % ('%s', cond), self.doc.company)
@webnotes.whitelist()
def get_default_bank_cash_account(company, voucher_type):
from accounts.utils import get_balance_on
account = webnotes.conn.get_value("Company", company,
voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account")
if account:
return {
"account": account,
"balance": get_balance_on(account)
}
def get_against_purchase_invoice(doctype, txt, searchfield, start, page_len, filters): def get_against_purchase_invoice(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name, credit_to, outstanding_amount, bill_no, bill_date return webnotes.conn.sql("""select name, credit_to, outstanding_amount, bill_no, bill_date

View File

@ -1,8 +1,8 @@
[ [
{ {
"creation": "2013-01-10 16:34:07", "creation": "2013-01-24 11:03:29",
"docstatus": 0, "docstatus": 0,
"modified": "2013-01-22 16:55:20", "modified": "2013-03-25 15:27:52",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -140,6 +140,14 @@
"options": "Account", "options": "Account",
"reqd": 1 "reqd": 1
}, },
{
"doctype": "DocField",
"fieldname": "expense_account",
"fieldtype": "Link",
"label": "Expense Account",
"options": "Account",
"reqd": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "warehouse", "fieldname": "warehouse",

View File

@ -27,8 +27,6 @@ from webnotes.model.bean import getlist
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
from webnotes import _, msgprint from webnotes import _, msgprint
session = webnotes.session
month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12} month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
@ -156,46 +154,57 @@ class DocType(SellingController):
def set_pos_fields(self): def set_pos_fields(self):
"""Set retail related fields from pos settings""" """Set retail related fields from pos settings"""
pos = webnotes.conn.sql("select * from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1) pos = self.pos_details
if not pos:
pos = webnotes.conn.sql("select * from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % (self.doc.company), as_dict=1)
if pos: if pos:
val = webnotes.conn.sql("select name from `tabAccount` where name = %s and docstatus != 2", (cstr(self.doc.customer) + " - " + self.get_company_abbr())) val = webnotes.conn.sql("""select name from `tabAccount`
where name = %s and docstatus != 2""",
(cstr(self.doc.customer) + " - " + self.get_company_abbr()))
val = val and val[0][0] or '' val = val and val[0][0] or ''
if not val: val = pos and pos[0]['customer_account'] or '' if not val: val = pos[0]['customer_account'] or ''
if not self.doc.debit_to: if not self.doc.debit_to:
webnotes.conn.set(self.doc,'debit_to',val) webnotes.conn.set(self.doc,'debit_to',val)
lst = ['territory','naming_series','currency','charge','letter_head','tc_name','price_list_name','company','select_print_heading','cash_bank_account'] lst = ['territory', 'naming_series', 'currency', 'charge', 'letter_head', 'tc_name',
'price_list_name', 'company', 'select_print_heading', 'cash_bank_account']
for i in lst: for i in lst:
val = pos and pos[0][i] or '' self.doc.fields[i] = pos[0][i] or ''
self.doc.fields[i] = val
self.set_pos_item_values() self.set_pos_item_values()
val = pos and flt(pos[0]['conversion_rate']) or 0 self.doc.conversion_rate = flt(pos[0]['conversion_rate']) or 0
self.doc.conversion_rate = val
#fetch terms #fetch terms
if self.doc.tc_name: self.get_tc_details() if self.doc.tc_name:
self.get_tc_details()
#fetch charges #fetch charges
if self.doc.charge: self.get_other_charges() if self.doc.charge:
self.get_other_charges()
def set_pos_item_values(self): def set_pos_item_values(self):
"""Set default values related to pos for previously created sales invoice.""" """Set default values related to pos for previously created sales invoice."""
if cint(self.doc.is_pos) == 1: if cint(self.doc.is_pos) == 1:
dtl = webnotes.conn.sql("select income_account, warehouse, cost_center from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1) dtl = self.pos_details
if not dtl:
dtl = webnotes.conn.sql("select income_account, warehouse, cost_center from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % (self.doc.company), as_dict=1)
for d in getlist(self.doclist,'entries'): for d in getlist(self.doclist,'entries'):
# overwrite if mentioned in item # overwrite if mentioned in item
item = webnotes.conn.sql("select default_income_account, default_sales_cost_center, default_warehouse from tabItem where name = '%s'" %(d.item_code), as_dict=1) item = webnotes.conn.sql("""select default_income_account,
d.income_account = item and item[0]['default_income_account'] or dtl and dtl[0]['income_account'] or d.income_account default_sales_cost_center, default_warehouse, purchase_account
d.cost_center = item and item[0]['default_sales_cost_center'] or dtl and dtl[0]['cost_center'] or d.cost_center from tabItem where name = %s""", (d.item_code,), as_dict=1)
d.warehouse = item and item[0]['default_warehouse'] or dtl and dtl[0]['warehouse'] or d.warehouse
d.income_account = (item and item[0]['default_income_account']) \
or (dtl and dtl[0]['income_account']) or d.income_account
d.cost_center = (item and item[0]['default_sales_cost_center']) \
or (dtl and dtl[0]['cost_center']) or d.cost_center
d.warehouse = (item and item[0]['default_warehouse']) \
or (dtl and dtl[0]['warehouse']) or d.warehouse
d.expense_account = (item and item[0].purchase_account) \
or (dtl and dtl[0].expense_account) or d.expense_account
def get_customer_account(self): def get_customer_account(self):
"""Get Account Head to which amount needs to be Debited based on Customer""" """Get Account Head to which amount needs to be Debited based on Customer"""
@ -276,15 +285,13 @@ class DocType(SellingController):
for d in getlist(self.doclist, doctype): for d in getlist(self.doclist, doctype):
if d.item_code: if d.item_code:
item = webnotes.conn.get_value("Item", d.item_code, ["default_income_account", item = webnotes.conn.get_value("Item", d.item_code, ["default_income_account",
"default_sales_cost_center", "purchase_account", "cost_center"], as_dict=True) "default_sales_cost_center", "purchase_account"], as_dict=True)
d.income_account = item['default_income_account'] or "" d.income_account = item['default_income_account'] or ""
d.cost_center = item['default_sales_cost_center'] or "" d.cost_center = item['default_sales_cost_center'] or ""
if cint(webnotes.defaults.get_global_default("auto_inventory_accounting")) \ if cint(webnotes.defaults.get_global_default("auto_inventory_accounting")) \
and cint(self.doc.is_pos) and cint(self.doc.update_stock): and cint(self.doc.is_pos) and cint(self.doc.update_stock):
d.expense_account = item['purchase_account'] or "" d.expense_account = item['purchase_account'] or ""
d.purchase_cost_center = item['cost_center'] or ""
def get_item_details(self, args=None): def get_item_details(self, args=None):
import json import json
@ -301,7 +308,6 @@ class DocType(SellingController):
'cost_center': doc.fields.get('cost_center'), 'cost_center': doc.fields.get('cost_center'),
'warehouse': doc.fields.get('warehouse'), 'warehouse': doc.fields.get('warehouse'),
'expense_account': doc.fields.get('expense_account'), 'expense_account': doc.fields.get('expense_account'),
'purchase_cost_center': doc.fields.get('purchase_cost_center')
} }
ret = self.get_pos_details(arg) ret = self.get_pos_details(arg)
@ -309,14 +315,27 @@ class DocType(SellingController):
if not doc.fields.get(r): if not doc.fields.get(r):
doc.fields[r] = ret[r] doc.fields[r] = ret[r]
@property
def pos_details(self):
if not hasattr(self, "_pos_details"):
dtl = webnotes.conn.sql("""select income_account, warehouse, cost_center,
expense_account from `tabPOS Setting` where user = %s and company = %s""",
(webnotes.session['user'], self.doc.company), as_dict=1)
if not dtl:
dtl = webnotes.conn.sql("""select income_account, warehouse, cost_center,
expense_account from `tabPOS Setting` where ifnull(user,'') = ''
and company = %s""", self.doc.company, as_dict=1)
self._pos_details = dtl
return self._pos_details
def get_pos_details(self, args, ret = {}): def get_pos_details(self, args, ret = {}):
if args['item_code'] and cint(self.doc.is_pos) == 1: if args['item_code'] and cint(self.doc.is_pos) == 1:
dtl = webnotes.conn.sql("select income_account, warehouse, cost_center from `tabPOS Setting` where user = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1) dtl = self.pos_details
if not dtl:
dtl = webnotes.conn.sql("select income_account, warehouse, cost_center from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % (self.doc.company), as_dict=1)
item = webnotes.conn.sql("select default_income_account, default_sales_cost_center, default_warehouse from tabItem where name = '%s'" %(args['item_code']), as_dict=1) item = webnotes.conn.sql("""select default_income_account, default_sales_cost_center,
default_warehouse, purchase_account from tabItem where name = %s""",
args['item_code'], as_dict=1)
ret['income_account'] = item and item[0].get('default_income_account') \ ret['income_account'] = item and item[0].get('default_income_account') \
or (dtl and dtl[0].get('income_account') or args.get('income_account')) or (dtl and dtl[0].get('income_account') or args.get('income_account'))
@ -327,8 +346,13 @@ class DocType(SellingController):
ret['warehouse'] = item and item[0].get('default_warehouse') \ ret['warehouse'] = item and item[0].get('default_warehouse') \
or (dtl and dtl[0].get('warehouse') or args.get('warehouse')) or (dtl and dtl[0].get('warehouse') or args.get('warehouse'))
ret['expense_account'] = item and item[0].get('purchase_account') \
or (dtl and dtl[0].get('expense_account') or args.get('expense_account'))
if ret['warehouse']: if ret['warehouse']:
actual_qty = webnotes.conn.sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (args['item_code'], ret['warehouse'])) actual_qty = webnotes.conn.sql("""select actual_qty from `tabBin`
where item_code = %s and warehouse = %s""",
(args['item_code'], ret['warehouse']))
ret['actual_qty']= actual_qty and flt(actual_qty[0][0]) or 0 ret['actual_qty']= actual_qty and flt(actual_qty[0][0]) or 0
return ret return ret
@ -545,7 +569,7 @@ class DocType(SellingController):
def get_warehouse(self): def get_warehouse(self):
w = webnotes.conn.sql("select warehouse from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company)) w = webnotes.conn.sql("select warehouse from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (webnotes.session['user'], self.doc.company))
w = w and w[0][0] or '' w = w and w[0][0] or ''
if not w: if not w:
ps = webnotes.conn.sql("select name, warehouse from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % self.doc.company) ps = webnotes.conn.sql("select name, warehouse from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % self.doc.company)
@ -630,7 +654,8 @@ class DocType(SellingController):
'fiscal_year' : self.doc.fiscal_year, 'fiscal_year' : self.doc.fiscal_year,
'is_cancelled' : (update_stock==1) and 'No' or 'Yes', 'is_cancelled' : (update_stock==1) and 'No' or 'Yes',
'batch_no' : cstr(d['batch_no']), 'batch_no' : cstr(d['batch_no']),
'serial_no' : d['serial_no'] 'serial_no' : d['serial_no'],
"project" : self.doc.project_name
}) })
def update_stock_ledger(self, update_stock): def update_stock_ledger(self, update_stock):

View File

@ -1,8 +1,8 @@
[ [
{ {
"creation": "2013-03-07 11:42:55", "creation": "2013-03-25 15:35:04",
"docstatus": 0, "docstatus": 0,
"modified": "2013-03-22 18:40:48", "modified": "2013-03-25 15:35:23",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -215,6 +215,7 @@
"label": "Expense Account", "label": "Expense Account",
"options": "Account", "options": "Account",
"print_hide": 1, "print_hide": 1,
"read_only": 0,
"width": "120px" "width": "120px"
}, },
{ {
@ -232,17 +233,6 @@
"reqd": 0, "reqd": 0,
"width": "120px" "width": "120px"
}, },
{
"doctype": "DocField",
"fieldname": "purchase_cost_center",
"fieldtype": "Link",
"hidden": 1,
"in_filter": 1,
"label": "Purchase Cost Center",
"options": "Cost Center",
"print_hide": 1,
"width": "120px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "serial_no", "fieldname": "serial_no",

View File

@ -39,6 +39,16 @@ wn.module_page["Accounts"] = [
description: wn._("Structure cost centers for budgeting."), description: wn._("Structure cost centers for budgeting."),
doctype:"Cost Center" doctype:"Cost Center"
}, },
{
label: wn._("Customer"),
description: wn._("Customer database."),
doctype:"Customer"
},
{
label: wn._("Supplier"),
description: wn._("Supplier database."),
doctype:"Supplier"
},
] ]
}, },
{ {

View File

@ -106,9 +106,9 @@ class DocType(TransactionBase):
def create_account_head(self): def create_account_head(self):
if self.doc.company : if self.doc.company :
abbr = self.get_company_abbr() abbr = self.get_company_abbr()
parent_account = self.get_parent_account(abbr)
if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)): if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
parent_account = self.get_parent_account(abbr)
ac = add_ac({ ac = add_ac({
'account_name': self.doc.name, 'account_name': self.doc.name,
@ -121,10 +121,18 @@ class DocType(TransactionBase):
'master_name': self.doc.name, 'master_name': self.doc.name,
}) })
msgprint(_("Created Account Head: ") + ac) msgprint(_("Created Account Head: ") + ac)
else:
self.check_parent_account(parent_account, abbr)
else : else :
msgprint("Please select Company under which you want to create account head") msgprint("Please select Company under which you want to create account head")
def check_parent_account(self, parent_account, abbr):
if webnotes.conn.get_value("Account", self.doc.name + " - " + abbr,
"parent_account") != parent_account:
ac = webnotes.bean("Account", self.doc.name + " - " + abbr)
ac.doc.parent_account = parent_account
ac.save()
def get_contacts(self,nm): def get_contacts(self,nm):
if nm: if nm:
contact_details =webnotes.conn.convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm)) contact_details =webnotes.conn.convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))

View File

@ -0,0 +1,42 @@
import webnotes
def execute():
webnotes.reload_doc("stock", "doctype", "stock_ledger_entry")
# from stock entry
webnotes.conn.sql("""update
`tabStock Ledger Entry` sle,
`tabStock Entry` st
set sle.project = st.project_name
where
sle.voucher_type = "Stock Entry"
and sle.voucher_no = st.name""")
# from purchase
webnotes.conn.sql("""update
`tabStock Ledger Entry` sle,
`tabPurchase Receipt Item` pri
set sle.project = pri.project_name
where
sle.voucher_type = "Purchase Receipt"
and sle.voucher_detail_no = pri.name""")
# from delivery note
webnotes.conn.sql("""update
`tabStock Ledger Entry` sle,
`tabDelivery Note` dn
set sle.project = dn.project_name
where
sle.voucher_type = "Delivery Note"
and sle.voucher_no = dn.name""")
# from pos invoice
webnotes.conn.sql("""update
`tabStock Ledger Entry` sle,
`tabSales Invoice` si
set sle.project = si.project_name
where
sle.voucher_type = "Sales Invoice"
and sle.voucher_no = si.name""")

View File

@ -0,0 +1,26 @@
import webnotes
def execute():
accounts_to_add = [
["Stock Assets", "Current Assets", "Group", ""],
["Stock In Hand", "Stock Assets", "Ledger", ""],
["Stock Debit But Not Billed", "Stock Assets", "Ledger", ""],
["Stock Expenses", "Direct Expenses", "Group", "Expense Account"],
["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"],
["Stock Liabilities", "Current Liabilities", "Group", ""],
["Stock Received But Not Billed", "Stock Liabilities", "Ledger", ""],
]
for company, abbr in webnotes.conn.sql_list("""select name, abbr from `tabCompany`"""):
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)):
account = webnotes.bean({
"doctype": "Account",
"account_name": account_name,
"parent_account": "%s - %s" % (parent_account_name, abbr),
"group_or_ledger": group_or_ledger,
"account_type": account_type,
"company": company
})
account.insert()

View File

@ -214,5 +214,8 @@ patch_list = [
"patches.march_2013.p04_pos_update_stock_check", "patches.march_2013.p04_pos_update_stock_check",
"patches.march_2013.p05_payment_reconciliation", "patches.march_2013.p05_payment_reconciliation",
"patches.march_2013.p06_remove_sales_purchase_return_tool", "patches.march_2013.p06_remove_sales_purchase_return_tool",
"execute:webnotes.bean('Global Defaults').save()" "execute:webnotes.bean('Global Defaults').save()",
"patches.march_2013.p07_update_project_in_stock_ledger",
"execute:webnotes.bean('Style Settings').save() #2013-03-25",
"execute:webnotes.conn.set_value('Email Settings', None, 'send_print_in_body_and_attachment', 1)"
] ]

View File

@ -127,7 +127,7 @@ function getCookies() {
var parts = cookie.split(/=/, 2), var parts = cookie.split(/=/, 2),
name = decodeURIComponent(parts[0].trimLeft()), name = decodeURIComponent(parts[0].trimLeft()),
value = parts.length > 1 ? decodeURIComponent(parts[1].trimRight()) : null; value = parts.length > 1 ? decodeURIComponent(parts[1].trimRight()) : null;
if(value.charAt(0)==='"') { if(value && value.charAt(0)==='"') {
value = value.substr(1, value.length-2); value = value.substr(1, value.length-2);
} }
cookies[name] = value; cookies[name] = value;

View File

@ -127,24 +127,35 @@ class DocType(TransactionBase):
if not obj.doc.price_list_name: if not obj.doc.price_list_name:
msgprint("Please Select Price List before selecting Items") msgprint("Please Select Price List before selecting Items")
raise Exception raise Exception
item = webnotes.conn.sql("select description, item_name, brand, item_group, stock_uom, default_warehouse, default_income_account, default_sales_cost_center, purchase_account, cost_center, description_html, barcode from `tabItem` where name = '%s' and (ifnull(end_of_life,'')='' or end_of_life > now() or end_of_life = '0000-00-00') and (is_sales_item = 'Yes' or is_service_item = 'Yes')" % (args['item_code']), as_dict=1) item = webnotes.conn.sql("""select description, item_name, brand, item_group, stock_uom,
tax = webnotes.conn.sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , args['item_code']) default_warehouse, default_income_account, default_sales_cost_center,
purchase_account, description_html, barcode from `tabItem`
where name = %s and (ifnull(end_of_life,'')='' or end_of_life > now()
or end_of_life = '0000-00-00') and (is_sales_item = 'Yes'
or is_service_item = 'Yes')""", args['item_code'], as_dict=1)
tax = webnotes.conn.sql("""select tax_type, tax_rate from `tabItem Tax`
where parent = %s""", args['item_code'])
t = {} t = {}
for x in tax: t[x[0]] = flt(x[1]) for x in tax: t[x[0]] = flt(x[1])
ret = { ret = {
'description' : item and item[0]['description_html'] or item[0]['description'], 'description': item and item[0]['description_html'] or \
item[0]['description'],
'barcode': item and item[0]['barcode'] or '', 'barcode': item and item[0]['barcode'] or '',
'item_group': item and item[0]['item_group'] or '', 'item_group': item and item[0]['item_group'] or '',
'item_name': item and item[0]['item_name'] or '', 'item_name': item and item[0]['item_name'] or '',
'brand': item and item[0]['brand'] or '', 'brand': item and item[0]['brand'] or '',
'stock_uom': item and item[0]['stock_uom'] or '', 'stock_uom': item and item[0]['stock_uom'] or '',
'reserved_warehouse': item and item[0]['default_warehouse'] or '', 'reserved_warehouse': item and item[0]['default_warehouse'] or '',
'warehouse' : item and item[0]['default_warehouse'] or args.get('warehouse'), 'warehouse': item and item[0]['default_warehouse'] or \
'income_account' : item and item[0]['default_income_account'] or args.get('income_account'), args.get('warehouse'),
'expense_account' : item and item[0]['purchase_account'] or args.get('expense_account'), 'income_account': item and item[0]['default_income_account'] or \
'cost_center' : item and item[0]['default_sales_cost_center'] or args.get('cost_center'), args.get('income_account'),
'purchase_cost_center' : item and item[0]['cost_center'] or args.get('purchase_cost_center'), 'expense_account': item and item[0]['purchase_account'] or \
'qty' : 1.00, # this is done coz if item once fetched is fetched again thn its qty shld be reset to 1 args.get('expense_account'),
'cost_center': item and item[0]['default_sales_cost_center'] or \
args.get('cost_center'),
# this is done coz if item once fetched is fetched again than its qty shld be reset to 1
'qty': 1.00,
'adj_rate': 0, 'adj_rate': 0,
'amount': 0, 'amount': 0,
'export_amount': 0, 'export_amount': 0,
@ -174,14 +185,18 @@ class DocType(TransactionBase):
def get_item_defaults(self, args): def get_item_defaults(self, args):
item = webnotes.conn.sql("""select default_warehouse, default_income_account, default_sales_cost_center from `tabItem` item = webnotes.conn.sql("""select default_warehouse, default_income_account,
where name = '%s' and (ifnull(end_of_life,'') = '' or end_of_life > now() or end_of_life = '0000-00-00') default_sales_cost_center, purchase_account from `tabItem` where name = %s
and (is_sales_item = 'Yes' or is_service_item = 'Yes') """ % (args['item_code']), as_dict=1) and (ifnull(end_of_life,'') = '' or end_of_life > now() or end_of_life = '0000-00-00')
and (is_sales_item = 'Yes' or is_service_item = 'Yes') """,
(args['item_code']), as_dict=1)
ret = { ret = {
'reserved_warehouse': item and item[0]['default_warehouse'] or '', 'reserved_warehouse': item and item[0]['default_warehouse'] or '',
'warehouse': item and item[0]['default_warehouse'] or args.get('warehouse'), 'warehouse': item and item[0]['default_warehouse'] or args.get('warehouse'),
'income_account' : item and item[0]['default_income_account'] or args.get('income_account'), 'income_account': item and item[0]['default_income_account'] or \
'cost_center' : item and item[0]['default_sales_cost_center'] or args.get('cost_center') args.get('income_account'),
'expense_account': item and item[0]['purchase_account'] or args.get('expense_account'),
'cost_center': item and item[0]['default_sales_cost_center'] or args.get('cost_center'),
} }
return ret return ret

View File

@ -49,6 +49,10 @@ cur_frm.fields_dict.default_bank_account.get_query = function(doc) {
return 'SELECT `tabAccount`.name, `tabAccount`.debit_or_credit, `tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.docstatus != 2 AND `tabAccount`.account_type = "Bank or Cash" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; return 'SELECT `tabAccount`.name, `tabAccount`.debit_or_credit, `tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.docstatus != 2 AND `tabAccount`.account_type = "Bank or Cash" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50';
} }
cur_frm.fields_dict.default_cash_account.get_query = function(doc) {
return 'SELECT `tabAccount`.name, `tabAccount`.debit_or_credit, `tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.docstatus != 2 AND `tabAccount`.account_type = "Bank or Cash" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50';
}
cur_frm.fields_dict.receivables_group.get_query = function(doc) { cur_frm.fields_dict.receivables_group.get_query = function(doc) {
return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Group" AND `tabAccount`.docstatus != 2 AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Group" AND `tabAccount`.docstatus != 2 AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50';

View File

@ -249,15 +249,17 @@ class DocType:
def on_update(self): def on_update(self):
self.set_letter_head() self.set_letter_head()
ac = sql("select name from tabAccount where company=%s and docstatus<2 limit 1",
self.doc.name) if not webnotes.conn.sql("""select name from tabAccount
if not ac: where company=%s and docstatus<2 limit 1""", self.doc.name):
self.create_default_accounts() self.create_default_accounts()
self.set_default_accounts()
cc = sql("select name from `tabCost Center` where cost_center_name = 'Root' and company_name = '%s'"%(self.doc.name)) if not webnotes.conn.sql("""select name from `tabCost Center`
if not cc: where cost_center_name = 'Root' and company_name = %s""", self.doc.name):
self.create_default_cost_center() self.create_default_cost_center()
self.set_default_accounts()
if self.doc.default_currency: if self.doc.default_currency:
webnotes.conn.set_value("Currency", self.doc.default_currency, "enabled", 1) webnotes.conn.set_value("Currency", self.doc.default_currency, "enabled", 1)

View File

@ -1,8 +1,8 @@
[ [
{ {
"creation": "2013-02-27 09:38:05", "creation": "2013-03-21 17:41:00",
"docstatus": 0, "docstatus": 0,
"modified": "2013-03-22 18:19:36", "modified": "2013-03-25 15:35:34",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -25,19 +25,14 @@
}, },
{ {
"amend": 0, "amend": 0,
"cancel": 1,
"create": 1,
"doctype": "DocPerm", "doctype": "DocPerm",
"name": "__common__", "name": "__common__",
"parent": "Company", "parent": "Company",
"parentfield": "permissions", "parentfield": "permissions",
"parenttype": "DocType", "parenttype": "DocType",
"permlevel": 0,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "System Manager", "submit": 0
"submit": 0,
"write": 1
}, },
{ {
"doctype": "DocType", "doctype": "DocType",
@ -102,6 +97,13 @@
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Account" "options": "Account"
}, },
{
"doctype": "DocField",
"fieldname": "default_cash_account",
"fieldtype": "Link",
"label": "Default Cash Account",
"options": "Account"
},
{ {
"depends_on": "eval:!doc.__islocal", "depends_on": "eval:!doc.__islocal",
"doctype": "DocField", "doctype": "DocField",
@ -311,6 +313,19 @@
"read_only": 1 "read_only": 1
}, },
{ {
"doctype": "DocPerm" "cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "System Manager",
"write": 1
},
{
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "All",
"write": 0
} }
] ]

View File

@ -1,4 +1,4 @@
test_ignore = ["Account"] test_ignore = ["Account", "Cost Center"]
test_records = [ test_records = [
[{ [{
@ -7,4 +7,10 @@ test_records = [
"abbr": "_TC", "abbr": "_TC",
"default_currency": "INR", "default_currency": "INR",
}], }],
[{
"doctype": "Company",
"company_name": "_Test Company 1",
"abbr": "_TC1",
"default_currency": "USD",
}],
] ]

View File

@ -1,13 +1,12 @@
[ [
{ {
"creation": "2012-07-03 13:30:55", "creation": "2012-07-12 23:29:44",
"docstatus": 0, "docstatus": 0,
"modified": "2012-07-12 16:16:27", "modified": "2013-03-25 17:32:05",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "harshada@webnotestech.com" "owner": "harshada@webnotestech.com"
}, },
{ {
"_last_update": "1325570647",
"allow_copy": 1, "allow_copy": 1,
"allow_email": 1, "allow_email": 1,
"allow_print": 1, "allow_print": 1,
@ -16,9 +15,7 @@
"in_create": 1, "in_create": 1,
"issingle": 1, "issingle": 1,
"module": "Setup", "module": "Setup",
"name": "__common__", "name": "__common__"
"section_style": "Simple",
"version": 1
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -37,19 +34,15 @@
"parenttype": "DocType", "parenttype": "DocType",
"permlevel": 0, "permlevel": 0,
"read": 1, "read": 1,
"report": 0,
"role": "System Manager", "role": "System Manager",
"submit": 0,
"write": 1 "write": 1
}, },
{ {
"doctype": "DocType", "doctype": "DocType",
"name": "Email Settings" "name": "Email Settings"
}, },
{
"doctype": "DocPerm"
},
{
"doctype": "DocPerm"
},
{ {
"description": "Set your outgoing mail SMTP settings here. All system generated notifications, emails will go from this mail server. If you are not sure, leave this blank to use ERPNext servers (emails will still be sent from your email id) or contact your email provider.", "description": "Set your outgoing mail SMTP settings here. All system generated notifications, emails will go from this mail server. If you are not sure, leave this blank to use ERPNext servers (emails will still be sent from your email id) or contact your email provider.",
"doctype": "DocField", "doctype": "DocField",
@ -102,6 +95,13 @@
"fieldtype": "Data", "fieldtype": "Data",
"label": "Auto Email Id" "label": "Auto Email Id"
}, },
{
"description": "If checked, an email with an attached HTML format will be added to part of the EMail body as well as attachment. To only send as attachment, uncheck this.",
"doctype": "DocField",
"fieldname": "send_print_in_body_and_attachment",
"fieldtype": "Check",
"label": "Send Print in Body and Attachment"
},
{ {
"description": "Set the POP3 email settings to pull emails directly from a mailbox and create Support Tickets", "description": "Set the POP3 email settings to pull emails directly from a mailbox and create Support Tickets",
"doctype": "DocField", "doctype": "DocField",
@ -180,5 +180,8 @@
"fieldname": "support_autoreply", "fieldname": "support_autoreply",
"fieldtype": "Text", "fieldtype": "Text",
"label": "Custom Autoreply Message" "label": "Custom Autoreply Message"
},
{
"doctype": "DocPerm"
} }
] ]

50
startup/boot.py Normal file
View File

@ -0,0 +1,50 @@
# ERPNext: Copyright 2013 Web Notes Technologies Pvt Ltd
# GNU General Public License. See "license.txt"
from __future__ import unicode_literals
import webnotes
import home
def boot_session(bootinfo):
"""boot session - send website info if guest"""
import webnotes
import webnotes.model.doc
bootinfo['custom_css'] = webnotes.conn.get_value('Style Settings', None, 'custom_css') or ''
bootinfo['website_settings'] = webnotes.model.doc.getsingle('Website Settings')
if webnotes.session['user']=='Guest':
bootinfo['website_menus'] = webnotes.conn.sql("""select label, url, custom_page,
parent_label, parentfield
from `tabTop Bar Item` where parent='Website Settings' order by idx asc""", as_dict=1)
bootinfo['startup_code'] = \
webnotes.conn.get_value('Website Settings', None, 'startup_code')
else:
bootinfo['letter_heads'] = get_letter_heads()
import webnotes.model.doctype
bootinfo['notification_settings'] = webnotes.doc("Notification Control",
"Notification Control").get_values()
bootinfo['modules_list'] = webnotes.conn.get_global('modules_list')
# if no company, show a dialog box to create a new company
bootinfo['setup_complete'] = webnotes.conn.sql("""select name from
tabCompany limit 1""") and 'Yes' or 'No'
# load subscription info
import conf
for key in ['max_users', 'expires_on', 'max_space', 'status', 'developer_mode']:
if hasattr(conf, key): bootinfo[key] = getattr(conf, key)
bootinfo['docs'] += webnotes.conn.sql("select name, default_currency from `tabCompany`",
as_dict=1, update={"doctype":":Company"})
def get_letter_heads():
"""load letter heads with startup"""
import webnotes
ret = webnotes.conn.sql("""select name, content from `tabLetter Head`
where ifnull(disabled,0)=0""")
return dict(ret)

View File

@ -31,55 +31,6 @@ def on_login_post_session(login_manager):
login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D') login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D')
webnotes.conn.commit() webnotes.conn.commit()
def comment_added(doc):
"""add comment to feed"""
home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by,
'<i>"' + doc.comment + '"</i>', '#6B24B3')
def boot_session(bootinfo):
"""boot session - send website info if guest"""
import webnotes
import webnotes.model.doc
bootinfo['custom_css'] = webnotes.conn.get_value('Style Settings', None, 'custom_css') or ''
bootinfo['website_settings'] = webnotes.model.doc.getsingle('Website Settings')
if webnotes.session['user']=='Guest':
bootinfo['website_menus'] = webnotes.conn.sql("""select label, url, custom_page,
parent_label, parentfield
from `tabTop Bar Item` where parent='Website Settings' order by idx asc""", as_dict=1)
bootinfo['startup_code'] = \
webnotes.conn.get_value('Website Settings', None, 'startup_code')
else:
bootinfo['letter_heads'] = get_letter_heads()
import webnotes.model.doctype
bootinfo['notification_settings'] = webnotes.doc("Notification Control",
"Notification Control").get_values()
bootinfo['modules_list'] = webnotes.conn.get_global('modules_list')
# if no company, show a dialog box to create a new company
bootinfo['setup_complete'] = webnotes.conn.sql("""select name from
tabCompany limit 1""") and 'Yes' or 'No'
# load subscription info
import conf
for key in ['max_users', 'expires_on', 'max_space', 'status', 'developer_mode']:
if hasattr(conf, key): bootinfo[key] = getattr(conf, key)
bootinfo['docs'] += webnotes.conn.sql("select name, default_currency from `tabCompany`",
as_dict=1, update={"doctype":":Company"})
def get_letter_heads():
"""load letter heads with startup"""
import webnotes
ret = webnotes.conn.sql("""select name, content from `tabLetter Head`
where ifnull(disabled,0)=0""")
return dict(ret)
def check_if_expired(): def check_if_expired():
"""check if account is expired. If expired, do not allow login""" """check if account is expired. If expired, do not allow login"""
import conf import conf
@ -106,3 +57,10 @@ def check_if_expired():
webnotes.response['message'] = 'Account Expired' webnotes.response['message'] = 'Account Expired'
raise webnotes.AuthenticationError raise webnotes.AuthenticationError
def comment_added(doc):
"""add comment to feed"""
home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by,
'<i>"' + doc.comment + '"</i>', '#6B24B3')

View File

@ -80,6 +80,11 @@ data_map = {
"conditions": ["docstatus < 2"], "conditions": ["docstatus < 2"],
"order_by": "name" "order_by": "name"
}, },
"Project": {
"columns": ["name"],
"conditions": ["docstatus < 2"],
"order_by": "name"
},
"Warehouse": { "Warehouse": {
"columns": ["name"], "columns": ["name"],
"conditions": ["docstatus < 2"], "conditions": ["docstatus < 2"],
@ -87,13 +92,14 @@ data_map = {
}, },
"Stock Ledger Entry": { "Stock Ledger Entry": {
"columns": ["name", "posting_date", "posting_time", "item_code", "warehouse", "columns": ["name", "posting_date", "posting_time", "item_code", "warehouse",
"actual_qty as qty", "voucher_type", "voucher_no", "actual_qty as qty", "voucher_type", "voucher_no", "project",
"ifnull(incoming_rate,0) as incoming_rate", "stock_uom", "serial_no"], "ifnull(incoming_rate,0) as incoming_rate", "stock_uom", "serial_no"],
"conditions": ["ifnull(is_cancelled, 'No')='No'"], "conditions": ["ifnull(is_cancelled, 'No')='No'"],
"order_by": "posting_date, posting_time, name", "order_by": "posting_date, posting_time, name",
"links": { "links": {
"item_code": ["Item", "name"], "item_code": ["Item", "name"],
"warehouse": ["Warehouse", "name"] "warehouse": ["Warehouse", "name"],
"project": ["Project", "name"]
}, },
"force_index": "posting_sort_index" "force_index": "posting_sort_index"
}, },

View File

@ -323,7 +323,7 @@ cur_frm.fields_dict['delivery_note_details'].grid.get_field('expense_account').g
} }
// cost center // cost center
cur_frm.fields_dict["delivery_note_details"].grid.get_field("cost_center").get_query = function(doc) { cur_frm.fields_dict.delivery_note_details.grid.get_field("cost_center").get_query = function(doc) {
return { return {
query: "accounts.utils.get_cost_center_list", query: "accounts.utils.get_cost_center_list",
filters: { company_name: doc.company} filters: { company_name: doc.company}

View File

@ -85,8 +85,11 @@ class DocType(SellingController):
obj = get_obj('Sales Common') obj = get_obj('Sales Common')
for doc in self.doclist: for doc in self.doclist:
if doc.fields.get('item_code'): if doc.fields.get('item_code'):
arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'), arg = {
'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')}; 'item_code':doc.fields.get('item_code'),
'expense_account':doc.fields.get('expense_account'),
'cost_center': doc.fields.get('cost_center'),
'warehouse': doc.fields.get('warehouse')};
ret = obj.get_item_defaults(arg) ret = obj.get_item_defaults(arg)
for r in ret: for r in ret:
if not doc.fields.get(r): if not doc.fields.get(r):
@ -387,7 +390,8 @@ class DocType(SellingController):
'fiscal_year' : self.doc.fiscal_year, 'fiscal_year' : self.doc.fiscal_year,
'is_cancelled' : (update_stock==1) and 'No' or 'Yes', 'is_cancelled' : (update_stock==1) and 'No' or 'Yes',
'batch_no' : d['batch_no'], 'batch_no' : d['batch_no'],
'serial_no' : d['serial_no'] 'serial_no' : d['serial_no'],
"project" : self.doc.project_name
}) })

View File

@ -1,8 +1,8 @@
[ [
{ {
"creation": "2013-03-07 11:42:59", "creation": "2013-03-25 11:55:16",
"docstatus": 0, "docstatus": 0,
"modified": "2013-03-22 18:43:10", "modified": "2013-03-25 15:43:04",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -253,14 +253,15 @@
"no_copy": 1, "no_copy": 1,
"options": "Account", "options": "Account",
"print_hide": 1, "print_hide": 1,
"read_only": 0,
"width": "120px" "width": "120px"
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "purchase_cost_center", "fieldname": "cost_center",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 1, "hidden": 1,
"label": "Purchase Cost Center", "label": "Cost Center",
"no_copy": 1, "no_copy": 1,
"options": "Cost Center", "options": "Cost Center",
"print_hide": 1, "print_hide": 1,

View File

@ -210,7 +210,8 @@ class DocType(BuyingController):
'fiscal_year' : self.doc.fiscal_year, 'fiscal_year' : self.doc.fiscal_year,
'is_cancelled' : (is_submit==1) and 'No' or 'Yes', 'is_cancelled' : (is_submit==1) and 'No' or 'Yes',
'batch_no' : cstr(d.batch_no).strip(), 'batch_no' : cstr(d.batch_no).strip(),
'serial_no' : serial_no 'serial_no' : serial_no,
"project" : d.project_name
}) })

View File

@ -27,7 +27,7 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
if (sys_defaults.auto_inventory_accounting && !this.frm.doc.expense_adjustment_account) { if (sys_defaults.auto_inventory_accounting && !this.frm.doc.expense_adjustment_account) {
if (this.frm.doc.purpose == "Sales Return") if (this.frm.doc.purpose == "Sales Return")
account_for = "stock_delivered_but_not_billed"; account_for = "stock_in_hand_account";
else if (this.frm.doc.purpose == "Purchase Return") else if (this.frm.doc.purpose == "Purchase Return")
account_for = "stock_received_but_not_billed"; account_for = "stock_received_but_not_billed";
else account_for = "stock_adjustment_account"; else account_for = "stock_adjustment_account";

View File

@ -603,7 +603,8 @@ class DocType(StockController):
'company': self.doc.company, 'company': self.doc.company,
'is_cancelled': (is_cancelled ==1) and 'Yes' or 'No', 'is_cancelled': (is_cancelled ==1) and 'Yes' or 'No',
'batch_no': cstr(d.batch_no).strip(), 'batch_no': cstr(d.batch_no).strip(),
'serial_no': cstr(d.serial_no).strip() 'serial_no': cstr(d.serial_no).strip(),
"project": self.doc.project_name
}) })
def get_cust_values(self): def get_cust_values(self):

View File

@ -26,6 +26,13 @@ class TestStockEntry(unittest.TestCase):
self.assertTrue(mr_name) self.assertTrue(mr_name)
def test_warehouse_company_validation(self):
from stock.doctype.stock_ledger_entry.stock_ledger_entry import InvalidWarehouseCompany
st1 = webnotes.bean(copy=test_records[0])
st1.doclist[1].t_warehouse="_Test Warehouse 2"
st1.insert()
self.assertRaises(InvalidWarehouseCompany, st1.submit)
def test_material_receipt_gl_entry(self): def test_material_receipt_gl_entry(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`") webnotes.conn.sql("delete from `tabStock Ledger Entry`")
webnotes.defaults.set_global_default("auto_inventory_accounting", 1) webnotes.defaults.set_global_default("auto_inventory_accounting", 1)

View File

@ -24,7 +24,7 @@ sql = webnotes.conn.sql
msgprint = webnotes.msgprint msgprint = webnotes.msgprint
from accounts.utils import get_fiscal_year from accounts.utils import get_fiscal_year
class InvalidWarehouseCompany(Exception): pass
class DocType: class DocType:
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
@ -35,6 +35,7 @@ class DocType:
self.validate_mandatory() self.validate_mandatory()
self.validate_item() self.validate_item()
self.validate_warehouse_user() self.validate_warehouse_user()
self.validate_warehouse_company()
self.actual_amt_check() self.actual_amt_check()
self.check_stock_frozen_date() self.check_stock_frozen_date()
self.scrub_posting_time() self.scrub_posting_time()
@ -63,6 +64,13 @@ class DocType:
webnotes.msgprint(_("User not allowed entry in the Warehouse") \ webnotes.msgprint(_("User not allowed entry in the Warehouse") \
+ ": " + webnotes.session.user + " / " + self.doc.warehouse, raise_exception = 1) + ": " + webnotes.session.user + " / " + self.doc.warehouse, raise_exception = 1)
def validate_warehouse_company(self):
warehouse_company = webnotes.conn.get_value("Warehouse", self.doc.warehouse, "company")
if warehouse_company and warehouse_company != self.doc.company:
webnotes.msgprint(_("Warehouse does not belong to company.") + " (" + \
self.doc.warehouse + ", " + self.doc.company +")",
raise_exception=InvalidWarehouseCompany)
def validate_mandatory(self): def validate_mandatory(self):
mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company'] mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company']
for k in mandatory: for k in mandatory:

View File

@ -1,8 +1,8 @@
[ [
{ {
"creation": "2013-01-14 16:33:26", "creation": "2013-01-29 19:25:42",
"docstatus": 0, "docstatus": 0,
"modified": "2013-01-29 16:27:57", "modified": "2013-03-25 16:04:59",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -24,13 +24,9 @@
"parent": "Stock Ledger Entry", "parent": "Stock Ledger Entry",
"parentfield": "fields", "parentfield": "fields",
"parenttype": "DocType", "parenttype": "DocType",
"permlevel": 0, "permlevel": 0
"read_only": 1
}, },
{ {
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm", "doctype": "DocPerm",
"name": "__common__", "name": "__common__",
"parent": "Stock Ledger Entry", "parent": "Stock Ledger Entry",
@ -39,9 +35,7 @@
"permlevel": 0, "permlevel": 0,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "Material User", "submit": 0
"submit": 0,
"write": 0
}, },
{ {
"doctype": "DocType", "doctype": "DocType",
@ -57,6 +51,7 @@
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Item", "options": "Item",
"print_width": "100px", "print_width": "100px",
"read_only": 1,
"reqd": 0, "reqd": 0,
"search_index": 1, "search_index": 1,
"width": "100px" "width": "100px"
@ -68,6 +63,7 @@
"in_filter": 0, "in_filter": 0,
"label": "Serial No", "label": "Serial No",
"print_width": "100px", "print_width": "100px",
"read_only": 1,
"search_index": 0, "search_index": 0,
"width": "100px" "width": "100px"
}, },
@ -77,7 +73,8 @@
"fieldtype": "Data", "fieldtype": "Data",
"label": "Batch No", "label": "Batch No",
"oldfieldname": "batch_no", "oldfieldname": "batch_no",
"oldfieldtype": "Data" "oldfieldtype": "Data",
"read_only": 1
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -89,6 +86,7 @@
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Warehouse", "options": "Warehouse",
"print_width": "100px", "print_width": "100px",
"read_only": 1,
"search_index": 1, "search_index": 1,
"width": "100px" "width": "100px"
}, },
@ -101,6 +99,7 @@
"oldfieldname": "warehouse_type", "oldfieldname": "warehouse_type",
"oldfieldtype": "Select", "oldfieldtype": "Select",
"options": "link:Warehouse Type", "options": "link:Warehouse Type",
"read_only": 1,
"search_index": 0 "search_index": 0
}, },
{ {
@ -113,6 +112,7 @@
"oldfieldname": "posting_date", "oldfieldname": "posting_date",
"oldfieldtype": "Date", "oldfieldtype": "Date",
"print_width": "100px", "print_width": "100px",
"read_only": 1,
"reqd": 0, "reqd": 0,
"search_index": 1, "search_index": 1,
"width": "100px" "width": "100px"
@ -126,6 +126,7 @@
"oldfieldname": "posting_time", "oldfieldname": "posting_time",
"oldfieldtype": "Time", "oldfieldtype": "Time",
"print_width": "100px", "print_width": "100px",
"read_only": 1,
"search_index": 0, "search_index": 0,
"width": "100px" "width": "100px"
}, },
@ -138,6 +139,7 @@
"oldfieldname": "voucher_type", "oldfieldname": "voucher_type",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"print_width": "150px", "print_width": "150px",
"read_only": 1,
"search_index": 0, "search_index": 0,
"width": "150px" "width": "150px"
}, },
@ -150,6 +152,7 @@
"oldfieldname": "voucher_no", "oldfieldname": "voucher_no",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"print_width": "150px", "print_width": "150px",
"read_only": 1,
"search_index": 0, "search_index": 0,
"width": "150px" "width": "150px"
}, },
@ -161,6 +164,7 @@
"oldfieldname": "voucher_detail_no", "oldfieldname": "voucher_detail_no",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"print_width": "150px", "print_width": "150px",
"read_only": 1,
"width": "150px" "width": "150px"
}, },
{ {
@ -172,6 +176,7 @@
"oldfieldname": "actual_qty", "oldfieldname": "actual_qty",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"print_width": "150px", "print_width": "150px",
"read_only": 1,
"width": "150px" "width": "150px"
}, },
{ {
@ -181,7 +186,8 @@
"label": "Incoming Rate", "label": "Incoming Rate",
"oldfieldname": "incoming_rate", "oldfieldname": "incoming_rate",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency" "options": "Company:company:default_currency",
"read_only": 1
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -191,6 +197,7 @@
"oldfieldname": "stock_uom", "oldfieldname": "stock_uom",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"print_width": "150px", "print_width": "150px",
"read_only": 1,
"width": "150px" "width": "150px"
}, },
{ {
@ -202,6 +209,7 @@
"oldfieldname": "bin_aqat", "oldfieldname": "bin_aqat",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"print_width": "150px", "print_width": "150px",
"read_only": 1,
"width": "150px" "width": "150px"
}, },
{ {
@ -213,6 +221,7 @@
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_width": "150px", "print_width": "150px",
"read_only": 1,
"width": "150px" "width": "150px"
}, },
{ {
@ -222,7 +231,8 @@
"label": "Stock Value", "label": "Stock Value",
"oldfieldname": "stock_value", "oldfieldname": "stock_value",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency" "options": "Company:company:default_currency",
"read_only": 1
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -234,9 +244,17 @@
"oldfieldname": "fcfs_stack", "oldfieldname": "fcfs_stack",
"oldfieldtype": "Text", "oldfieldtype": "Text",
"print_hide": 1, "print_hide": 1,
"read_only": 1,
"report_hide": 1, "report_hide": 1,
"search_index": 0 "search_index": 0
}, },
{
"doctype": "DocField",
"fieldname": "project",
"fieldtype": "Link",
"label": "Project",
"options": "Project"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "company", "fieldname": "company",
@ -247,6 +265,7 @@
"oldfieldtype": "Data", "oldfieldtype": "Data",
"options": "link:Company", "options": "link:Company",
"print_width": "150px", "print_width": "150px",
"read_only": 1,
"search_index": 0, "search_index": 0,
"width": "150px" "width": "150px"
}, },
@ -259,6 +278,7 @@
"oldfieldname": "fiscal_year", "oldfieldname": "fiscal_year",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"print_width": "150px", "print_width": "150px",
"read_only": 1,
"search_index": 0, "search_index": 0,
"width": "150px" "width": "150px"
}, },
@ -272,10 +292,20 @@
"oldfieldtype": "Select", "oldfieldtype": "Select",
"options": "\nYes\nNo", "options": "\nYes\nNo",
"print_width": "100px", "print_width": "100px",
"read_only": 1,
"search_index": 0, "search_index": 0,
"width": "100px" "width": "100px"
}, },
{ {
"doctype": "DocPerm" "amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"role": "Material User",
"write": 0
},
{
"doctype": "DocPerm",
"role": "Accounts Manager"
} }
] ]

View File

@ -7,6 +7,12 @@ test_records = [
[{ [{
"doctype": "Warehouse", "doctype": "Warehouse",
"warehouse_name": "_Test Warehouse 1", "warehouse_name": "_Test Warehouse 1",
"warehouse_type": "_Test Warehouse Type" "warehouse_type": "_Test Warehouse Type",
}],
[{
"doctype": "Warehouse",
"warehouse_name": "_Test Warehouse 2",
"warehouse_type": "_Test Warehouse Type",
"company": "_Test Company 1"
}] }]
] ]

View File

@ -35,7 +35,7 @@ erpnext.StockBalance = erpnext.StockAnalytics.extend({
this._super(wrapper, { this._super(wrapper, {
title: "Stock Balance", title: "Stock Balance",
doctypes: ["Item", "Item Group", "Warehouse", "Stock Ledger Entry", "Brand", doctypes: ["Item", "Item Group", "Warehouse", "Stock Ledger Entry", "Brand",
"Stock Entry"], "Stock Entry", "Project"],
}); });
}, },
setup_columns: function() { setup_columns: function() {
@ -76,6 +76,10 @@ erpnext.StockBalance = erpnext.StockAnalytics.extend({
default_value: "Select Warehouse...", filter: function(val, item, opts, me) { default_value: "Select Warehouse...", filter: function(val, item, opts, me) {
return me.apply_zero_filter(val, item, opts, me); return me.apply_zero_filter(val, item, opts, me);
}}, }},
{fieldtype:"Select", label: "Project", link:"Project",
default_value: "Select Project...", filter: function(val, item, opts, me) {
return me.apply_zero_filter(val, item, opts, me);
}, link_formatter: {filter_input: "project"}},
{fieldtype:"Date", label: "From Date"}, {fieldtype:"Date", label: "From Date"},
{fieldtype:"Label", label: "To"}, {fieldtype:"Label", label: "To"},
{fieldtype:"Date", label: "To Date"}, {fieldtype:"Date", label: "To Date"},
@ -105,7 +109,8 @@ erpnext.StockBalance = erpnext.StockAnalytics.extend({
var sl = data[i]; var sl = data[i];
var sl_posting_date = dateutil.str_to_obj(sl.posting_date); var sl_posting_date = dateutil.str_to_obj(sl.posting_date);
if(me.is_default("warehouse") ? true : me.warehouse == sl.warehouse) { if((me.is_default("warehouse") ? true : me.warehouse == sl.warehouse) &&
(me.is_default("project") ? true : me.project == sl.project)) {
var item = me.item_by_name[sl.item_code]; var item = me.item_by_name[sl.item_code];
var wh = me.get_item_warehouse(sl.warehouse, sl.item_code); var wh = me.get_item_warehouse(sl.warehouse, sl.item_code);
var valuation_method = item.valuation_method ? var valuation_method = item.valuation_method ?

View File

@ -69,7 +69,6 @@ div.web-footer, div.web-footer a {
.navbar-inverse .navbar-inner { .navbar-inverse .navbar-inner {
background-color: #{{ doc.top_bar_background or "444444"}}; background-color: #{{ doc.top_bar_background or "444444"}};
background-repeat: repeat-x; background-repeat: repeat-x;
border-color: transparent;
background-image: none; background-image: none;
} }

View File

@ -85,7 +85,7 @@ class DocType:
"UPPERCASE": "uppercase", "UPPERCASE": "uppercase",
"Title Case":"capitalize", "Title Case":"capitalize",
"lowercase": "lowercase" "lowercase": "lowercase"
}[self.doc.heading_text_as] }.get(self.doc.heading_text_as) or ""
self.doc.at_import = "" self.doc.at_import = ""
for f in fonts: for f in fonts: