Merge branch 'master' of github.com:webnotes/erpnext

This commit is contained in:
Anand Doshi 2013-02-08 14:48:14 +05:30
commit c5c48fd147
13 changed files with 198 additions and 95 deletions

View File

@ -120,7 +120,7 @@ cur_frm.fields_dict['master_name'].get_query = function(doc) {
if (doc.master_type) {
return {
query: "accounts.doctype.account.account.get_master_name",
args: { "master_type": doc.master_type }
filters: { "master_type": doc.master_type }
}
}
}
@ -128,6 +128,6 @@ cur_frm.fields_dict['master_name'].get_query = function(doc) {
cur_frm.fields_dict['parent_account'].get_query = function(doc) {
return {
query: "accounts.doctype.account.account.get_parent_account",
args: { "company": doc.company}
filters: { "company": doc.company}
}
}

View File

@ -29,13 +29,12 @@ class DocType:
self.nsm_parent_field = 'parent_account'
def autoname(self):
company_abbr = sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
self.doc.name = self.doc.account_name.strip() + ' - ' + company_abbr
self.doc.name = self.doc.account_name.strip() + ' - ' + \
webnotes.conn.get_value("Company", self.doc.company, "abbr")
def get_address(self):
add=sql("Select address from `tab%s` where name='%s'" %
(self.doc.master_type, self.doc.master_name))
return {'address': add[0][0]}
def get_address(self):
address = webnotes.conn.get_value(self.doc.master_type, self.doc.master_name, "address")
return {'address': address}
def validate_master_name(self):
if (self.doc.master_type == 'Customer' or self.doc.master_type == 'Supplier') \
@ -46,7 +45,7 @@ class DocType:
"""Fetch Parent Details and validation for account not to be created under ledger"""
if self.doc.parent_account:
par = sql("""select name, group_or_ledger, is_pl_account, debit_or_credit
from tabAccount where name =%s""",self.doc.parent_account)
from tabAccount where name =%s""", self.doc.parent_account)
if not par:
msgprint("Parent account does not exists", raise_exception=1)
elif par and par[0][0] == self.doc.name:
@ -106,8 +105,8 @@ class DocType:
# Check if any previous balance exists
def check_gle_exists(self):
exists = sql("""select name from `tabGL Entry` where account = '%s'
and ifnull(is_cancelled, 'No') = 'No'""" % (self.doc.name))
exists = sql("""select name from `tabGL Entry` where account = %s
and ifnull(is_cancelled, 'No') = 'No'""", self.doc.name)
return exists and exists[0][0] or ''
def check_if_child_exists(self):
@ -150,7 +149,7 @@ class DocType:
credit_limit_from = 'Customer'
cr_limit = sql("""select t1.credit_limit from tabCustomer t1, `tabAccount` t2
where t2.name='%s' and t1.name = t2.master_name""" % account)
where t2.name=%s and t1.name = t2.master_name""", account)
credit_limit = cr_limit and flt(cr_limit[0][0]) or 0
if not credit_limit:
credit_limit = webnotes.conn.get_value('Company', company, 'credit_limit')
@ -193,19 +192,22 @@ class DocType:
# rename account name
account_name = " - ".join(parts[:-1])
sql("update `tabAccount` set account_name = '%s' where name = '%s'" % \
(account_name, old))
sql("update `tabAccount` set account_name = %s where name = %s", (account_name, old))
return " - ".join(parts)
def get_master_name(doctype, txt, searchfield, start, page_len, args):
return webnotes.conn.sql("""select name from `tab%s` where name like '%%%s%%'""" %
(args["master_type"], txt), as_list=1)
def get_master_name(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name from `tab%s` where %s like %s
order by name limit %s, %s""" %
(filters["master_type"], searchfield, "%s", "%s", "%s"),
("%%%s%%" % txt, start, page_len), as_list=1)
def get_parent_account(doctype, txt, searchfield, start, page_len, args):
def get_parent_account(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name from tabAccount
where group_or_ledger = 'Group' and docstatus != 2 and company = '%s'
and name like '%%%s%%'""" % (args["company"], txt))
where group_or_ledger = 'Group' and docstatus != 2 and company = %s
and %s like %s order by name limit %s, %s""" %
("%s", searchfield, "%s", "%s", "%s"),
(filters["company"], "%%%s%%" % txt, start, page_len), as_list=1)
def make_test_records(verbose):
from webnotes.test_runner import load_module_and_make_records, make_test_objects

View File

@ -17,15 +17,16 @@
//c-form js file
// -----------------------------
cur_frm.fields_dict.invoice_details.grid.get_field("invoice_no").get_query = function(doc) {
cond = ""
if (doc.customer) cond += ' AND `tabSales Invoice`.`customer` = "' + cstr(doc.customer) + '"';
if (doc.company) cond += ' AND `tabSales Invoice`.`company` = "' + cstr(doc.company) + '"';
return 'SELECT `tabSales Invoice`.`name` FROM `tabSales Invoice` WHERE `tabSales Invoice`.`docstatus` = 1 and `tabSales Invoice`.`c_form_applicable` = "Yes" and ifnull(`tabSales Invoice`.c_form_no, "") = ""'+cond+' AND `tabSales Invoice`.%(key)s LIKE "%s" ORDER BY `tabSales Invoice`.`name` ASC LIMIT 50';
return {
query: "accounts.doctype.c_form.c_form.get_invoice_nos",
filters: {
customer: doc.customer,
company: doc.company
}
}
}
cur_frm.cscript.invoice_no = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
get_server_fields('get_invoice_details', d.invoice_no, 'invoice_details', doc, cdt, cdn, 1);
}
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
}

View File

@ -32,22 +32,23 @@ class DocType:
and no other c-form is received for that"""
for d in getlist(self.doclist, 'invoice_details'):
inv = webnotes.conn.sql("""select c_form_applicable, c_form_no from
`tabSales Invoice` where name = %s""", d.invoice_no)
if d.invoice_no:
inv = webnotes.conn.sql("""select c_form_applicable, c_form_no from
`tabSales Invoice` where name = %s""", d.invoice_no)
if not inv:
webnotes.msgprint("Invoice: %s is not exists in the system, please check." %
d.invoice_no, raise_exception=1)
if not inv:
webnotes.msgprint("Invoice: %s is not exists in the system, please check." %
d.invoice_no, raise_exception=1)
elif inv[0][0] != 'Yes':
webnotes.msgprint("C-form is not applicable for Invoice: %s" %
d.invoice_no, raise_exception=1)
elif inv[0][0] != 'Yes':
webnotes.msgprint("C-form is not applicable for Invoice: %s" %
d.invoice_no, raise_exception=1)
elif inv[0][1] and inv[0][1] != self.doc.name:
webnotes.msgprint("""Invoice %s is tagged in another C-form: %s.
If you want to change C-form no for this invoice,
please remove invoice no from the previous c-form and then try again""" %
(d.invoice_no, inv[0][1]), raise_exception=1)
elif inv[0][1] and inv[0][1] != self.doc.name:
webnotes.msgprint("""Invoice %s is tagged in another C-form: %s.
If you want to change C-form no for this invoice,
please remove invoice no from the previous c-form and then try again""" %
(d.invoice_no, inv[0][1]), raise_exception=1)
def on_update(self):
""" Update C-Form No on invoices"""
@ -80,4 +81,14 @@ class DocType:
'territory' : inv and inv[0][1] or '',
'net_total' : inv and flt(inv[0][2]) or '',
'grand_total' : inv and flt(inv[0][3]) or ''
}
}
def get_invoice_nos(doctype, txt, searchfield, start, page_len, filters):
from utilities import build_filter_conditions
conditions, filter_values = build_filter_conditions(filters)
return webnotes.conn.sql("""select name from `tabSales Invoice` where docstatus = 1
and c_form_applicable = 'Yes' and ifnull(c_form_no, '') = '' %s
and %s like %s order by name limit %s, %s""" %
(conditions, searchfield, "%s", "%s", "%s"),
tuple(filter_values + ["%%%s%%" % txt, start, page_len]))

View File

@ -49,44 +49,6 @@ cur_frm.cscript.is_opening = function(doc, cdt, cdn) {
if (doc.is_opening == 'Yes') unhide_field('aging_date');
}
cur_frm.fields_dict['entries'].grid.get_field('account').get_query = function(doc) {
return "SELECT `tabAccount`.name, `tabAccount`.parent_account FROM `tabAccount` WHERE `tabAccount`.company='"+doc.company+"' AND tabAccount.group_or_ledger = 'Ledger' AND tabAccount.docstatus != 2 AND `tabAccount`.%(key)s LIKE '%s' ORDER BY `tabAccount`.name DESC LIMIT 50";
}
cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = function(doc, cdt, cdn) {
return 'SELECT `tabCost Center`.`name`, `tabCost Center`.parent_cost_center FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `tabCost Center`.%(key)s LIKE "%s" AND `tabCost Center`.`group_or_ledger` = "Ledger" AND `tabCost Center`.docstatus != 2 ORDER BY `tabCost Center`.`name` ASC LIMIT 50';
}
// Restrict Voucher based on Account
// ---------------------------------
cur_frm.fields_dict['entries'].grid.get_field('against_voucher').get_query = function(doc) {
var d = locals[this.doctype][this.docname];
return "SELECT `tabPurchase Invoice`.name, `tabPurchase Invoice`.credit_to, `tabPurchase Invoice`.outstanding_amount,`tabPurchase Invoice`.bill_no, `tabPurchase Invoice`.bill_date FROM `tabPurchase Invoice` WHERE `tabPurchase Invoice`.credit_to='"+d.account+"' AND `tabPurchase Invoice`.outstanding_amount > 0 AND `tabPurchase Invoice`.docstatus = 1 AND `tabPurchase Invoice`.%(key)s LIKE '%s' ORDER BY `tabPurchase Invoice`.name DESC LIMIT 200";
}
cur_frm.fields_dict['entries'].grid.get_field('against_invoice').get_query = function(doc) {
var d = locals[this.doctype][this.docname];
return "SELECT `tabSales Invoice`.name, `tabSales Invoice`.debit_to, `tabSales Invoice`.outstanding_amount FROM `tabSales Invoice` WHERE `tabSales Invoice`.debit_to='"+d.account+"' AND `tabSales Invoice`.outstanding_amount > 0 AND `tabSales Invoice`.docstatus = 1 AND `tabSales Invoice`.%(key)s LIKE '%s' ORDER BY `tabSales Invoice`.name DESC LIMIT 200";
}
cur_frm.fields_dict['entries'].grid.get_field('against_jv').get_query = function(doc) {
var d = locals[this.doctype][this.docname];
if(!d.account) {
msgprint("Please select Account first!")
throw "account not selected"
}
return "SELECT `tabJournal Voucher`.name, `tabJournal Voucher`.posting_date,\
`tabJournal Voucher`.user_remark\
from `tabJournal Voucher`, `tabJournal Voucher Detail`\
where `tabJournal Voucher Detail`.account = '"+ esc_quotes(d.account) + "'\
and `tabJournal Voucher`.name like '%s'\
and `tabJournal Voucher`.docstatus=1\
and `tabJournal Voucher`.voucher_type='Journal Entry'\
and `tabJournal Voucher Detail`.parent = `tabJournal Voucher`.name";
}
//Set debit and credit to zero on adding new row
//----------------------------------------------
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
@ -116,9 +78,8 @@ cur_frm.cscript.against_invoice = function(doc,cdt,cdn) {
}
}
// Update Totals
// ---------------
cur_frm.cscript.update_totals = function(doc) {
var td=0.0; var tc =0.0;
var el = getchildren('Journal Voucher Detail', doc.name, 'entries');
@ -161,12 +122,6 @@ cur_frm.cscript.validate = function(doc,cdt,cdn) {
cur_frm.cscript.update_totals(doc);
}
cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) {
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
}
cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){
if(doc.select_print_heading){
// print heading
@ -201,3 +156,49 @@ cur_frm.cscript.voucher_type = function(doc, cdt, cdn) {
cur_frm.set_df_property("cheque_date", "reqd", false);
}
}
// get_query
cur_frm.fields_dict['entries'].grid.get_field('account').get_query = function(doc) {
return {
query: "accounts.utils.get_account_list",
filters: { company: doc.company }
}
}
cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = function(doc) {
return {
query: "accounts.utils.get_cost_center_list",
filters: { company_name: doc.company}
}
}
cur_frm.fields_dict['entries'].grid.get_field('against_voucher').get_query = function(doc) {
var d = locals[this.doctype][this.docname];
return {
query: "accounts.doctype.journal_voucher.journal_voucher.get_against_purchase_invoice",
filters: { account: d.account }
}
}
cur_frm.fields_dict['entries'].grid.get_field('against_invoice').get_query = function(doc) {
var d = locals[this.doctype][this.docname];
return {
query: "accounts.doctype.journal_voucher.journal_voucher.get_against_sales_invoice",
filters: { account: d.account }
}
}
cur_frm.fields_dict['entries'].grid.get_field('against_jv').get_query = function(doc) {
var d = locals[this.doctype][this.docname];
if(!d.account) {
msgprint("Please select Account first!")
throw "account not selected"
}
return {
query: "accounts.doctype.journal_voucher.journal_voucher.get_against_jv",
filters: { account: d.account }
}
}

View File

@ -339,4 +339,27 @@ class DocType(AccountsController):
elif self.doc.write_off_based_on == 'Accounts Payable':
return webnotes.conn.sql("""select name, credit_to, outstanding_amount
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)
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
from `tabPurchase Invoice` where credit_to = %s and docstatus = 1
and outstanding_amount > 0 and %s like %s order by name desc limit %s, %s""" %
("%s", searchfield, "%s", "%s", "%s"),
(filters["account"], "%%%s%%" % txt, start, page_len))
def get_against_sales_invoice(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name, debit_to, outstanding_amount
from `tabSales Invoice` where debit_to = %s and docstatus = 1
and outstanding_amount > 0 and `%s` like %s order by name desc limit %s, %s""" %
("%s", searchfield, "%s", "%s", "%s"),
(filters["account"], "%%%s%%" % txt, start, page_len))
def get_against_jv(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name, posting_date, user_remark
from `tabJournal Voucher` jv, `tabJournal Voucher Detail` jv_detail
where jv_detail.parent = jv.name and jv_detail.account = %s and docstatus = 1
and jv.%s like %s order by jv.name desc limit %s, %s""" %
("%s", searchfield, "%s", "%s", "%s"),
(filters["account"], "%%%s%%" % txt, start, page_len))

View File

@ -21,6 +21,8 @@ from webnotes.utils import nowdate, cstr, flt
from webnotes.model.doc import addchild
from webnotes import msgprint, _
from webnotes.utils import formatdate
from utilities import build_filter_conditions
class FiscalYearError(webnotes.ValidationError): pass
@ -209,4 +211,26 @@ def update_against_doc(d, jv_obj):
ch.against_account = cstr(jvd[0][2])
ch.is_advance = cstr(jvd[0][3])
ch.docstatus = 1
ch.save(1)
ch.save(1)
def get_account_list(doctype, txt, searchfield, start, page_len, filters):
if not filters.get("group_or_ledger"):
filters["group_or_ledger"] = "Ledger"
conditions, filter_values = build_filter_conditions(filters)
return webnotes.conn.sql("""select name, parent_account from `tabAccount`
where docstatus < 2 %s and %s like %s order by name limit %s, %s""" %
(conditions, searchfield, "%s", "%s", "%s"),
tuple(filter_values + ["%%%s%%" % txt, start, page_len]))
def get_cost_center_list(doctype, txt, searchfield, start, page_len, filters):
if not filters.get("group_or_ledger"):
filters["group_or_ledger"] = "Ledger"
conditions, filter_values = build_filter_conditions(filters)
return webnotes.conn.sql("""select name, parent_cost_center from `tabCost Center`
where docstatus < 2 %s and %s like %s order by name limit %s, %s""" %
(conditions, searchfield, "%s", "%s", "%s"),
tuple(filter_values + ["%%%s%%" % txt, start, page_len]))

32
selling/utils.py Normal file
View File

@ -0,0 +1,32 @@
# 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
def get_customer_list(doctype, txt, searchfield, start, page_len, filters):
if webnotes.conn.get_default("cust_master_name") == "Customer Name":
fields = ["name", "customer_group", "territory"]
else:
fields = ["name", "customer_name", "customer_group", "territory"]
return webnotes.conn.sql("""select %s from `tabCustomer` where docstatus < 2
and (%s like %s or customer_name like %s) order by
case when name like %s then 0 else 1 end,
case when customer_name like %s then 0 else 1 end,
name, customer_name limit %s, %s""" %
(", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"),
("%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, start, page_len))

View File

@ -1,5 +1,7 @@
from __future__ import unicode_literals
standard_queries = {
"Warehouse": "stock.utils.get_warehouse_list"
"Warehouse": "stock.utils.get_warehouse_list",
"Customer": "selling.utils.get_customer_list",
}

View File

@ -114,8 +114,7 @@ erpnext.StockLedger = erpnext.StockGridReport.extend({
},
toggle_enable_brand: function() {
if(this.filter_inputs.item_code.val() ==
this.filter_inputs.item_code.get(0).opts.default_value) {
if(!this.filter_inputs.item_code.val()) {
this.filter_inputs.brand.removeAttr("disabled");
} else {
this.filter_inputs.brand

View File

@ -127,8 +127,7 @@ erpnext.StockLevel = erpnext.StockGridReport.extend({
},
toggle_enable_brand: function() {
if(this.filter_inputs.item_code.val() ==
this.filter_inputs.item_code.get(0).opts.default_value) {
if(!this.filter_inputs.item_code.val()) {
this.filter_inputs.brand.removeAttr("disabled");
} else {
this.filter_inputs.brand

View File

@ -148,7 +148,7 @@ def get_valid_serial_nos(sr_nos, qty=0, item_code=''):
return valid_serial_nos
def get_warehouse_list(doctype, txt, searchfield, start, page_len, args):
def get_warehouse_list(doctype, txt, searchfield, start, page_len, filters):
"""used in search queries"""
wlist = []
for w in webnotes.conn.sql_list("""select name from tabWarehouse

View File

@ -58,3 +58,12 @@ def get_report_list():
def validate_status(status, options):
if status not in options:
msgprint(_("Status must be one of ") + comma_or(options), raise_exception=True)
def build_filter_conditions(filters):
conditions, filter_values = [], []
for key in filters:
conditions.append('`' + key + '` = %s')
filter_values.append(filters[key])
conditions = conditions and " and " + " and ".join(conditions) or ""
return conditions, filter_values