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

This commit is contained in:
Rushabh Mehta 2013-02-14 17:35:32 +05:30
commit b496756696
12 changed files with 254 additions and 124 deletions

View File

@ -3,17 +3,19 @@ def make_test_records(verbose):
accounts = [
# [account_name, parent_account, group_or_ledger]
["_Test Account Bank Account", "Bank Accounts - _TC", "Ledger"],
["_Test Account Stock Expenses", "Direct Expenses - _TC", "Group"],
["_Test Account Shipping Charges", "_Test Account Stock Expenses - _TC", "Ledger"],
["_Test Account Customs Duty", "_Test Account Stock Expenses - _TC", "Ledger"],
["_Test Account Tax Assets", "Current Assets - _TC", "Group"],
["_Test Account VAT", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Service Tax", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Cost for Goods Sold", "Expenses - _TC", "Ledger"],
["_Test Account Excise Duty", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account S&H Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account CST", "Direct Expenses - _TC", "Ledger"],
["_Test Account Discount", "Direct Expenses - _TC", "Ledger"]
["_Test Account Discount", "Direct Expenses - _TC", "Ledger"],
]
return make_test_objects("Account", [[{

View File

@ -18,110 +18,147 @@
from __future__ import unicode_literals
import unittest
import webnotes
import webnotes.model
from webnotes.utils import nowdate, flt, add_days
from accounts.utils import get_fiscal_year, get_balance_on
company = webnotes.conn.get_default("company")
abbr = webnotes.conn.get_value("Company", company, "abbr")
test_records = [[
{
"company": "_Test Company",
"doctype": "Journal Voucher",
"fiscal_year": "_Test Fiscal Year 2013",
"naming_series": "_T-Journal Voucher-",
"posting_date": "2013-02-14",
"tds_applicable": "No",
"user_remark": "test",
"voucher_type": "Bank Voucher",
"cheque_no": "33",
"cheque_date": "2013-02-14"
},
{
"account": "_Test Customer - _TC",
"doctype": "Journal Voucher Detail",
"credit": 400.0,
"debit": 0.0,
"parentfield": "entries"
},
{
"account": "_Test Account Bank Account - _TC",
"doctype": "Journal Voucher Detail",
"debit": 400.0,
"credit": 0.0,
"parentfield": "entries"
}
]]
data = {
"expense_account": {
"doctype": "Account",
"account_name": "Test Expense",
"parent_account": "Direct Expenses - %s" % abbr,
"company": company,
"debit_or_credit": "Debit",
"is_pl_account": "Yes",
"group_or_ledger": "Ledger"
},
"supplier_account": {
"doctype": "Account",
"account_name": "Test Supplier",
"parent_account": "Accounts Payable - %s" % abbr,
"company": company,
"debit_or_credit": "Credit",
"is_pl_account": "No",
"group_or_ledger": "Ledger"
},
"test_cost_center": {
"doctype": "Cost Center",
"cost_center_name": "Test Cost Center",
"parent_cost_center": "Root - %s" % abbr,
"company_name": company,
"group_or_ledger": "Ledger",
"company_abbr": abbr
},
"journal_voucher": [
{
"doctype": "Journal Voucher",
"voucher_type": "Journal Entry",
"naming_series": "JV",
"posting_date": nowdate(),
"remark": "Test Journal Voucher",
"fiscal_year": get_fiscal_year(nowdate())[0],
"company": company
},
{
"doctype": "Journal Voucher Detail",
"parentfield": "entries",
"account": "Test Expense - %s" % abbr,
"debit": 5000,
"cost_center": "Test Cost Center - %s" % abbr,
},
{
"doctype": "Journal Voucher Detail",
"parentfield": "entries",
"account": "Test Supplier - %s" % abbr,
"credit": 5000,
},
]
}
def get_name(s):
return s + " - " + abbr
class TestJournalVoucher(unittest.TestCase):
def setUp(self):
webnotes.conn.begin()
# create a dummy account
webnotes.model.insert([data["expense_account"]])
webnotes.model.insert([data["supplier_account"]])
webnotes.model.insert([data["test_cost_center"]])
def tearDown(self):
webnotes.conn.rollback()
def test_save_journal_voucher(self):
expense_ac_balance = get_balance_on(get_name("Test Expense"), nowdate())
supplier_ac_balance = get_balance_on(get_name("Test Supplier"), nowdate())
dl = webnotes.model.insert(data["journal_voucher"])
dl.submit()
dl.load_from_db()
# test submitted jv
self.assertTrue(webnotes.conn.exists("Journal Voucher", dl.doclist[0].name))
for d in dl.doclist[1:]:
self.assertEquals(webnotes.conn.get_value("Journal Voucher Detail",
d.name, "parent"), dl.doclist[0].name)
# test gl entry
gle = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_no = %s order by account""",
dl.doclist[0].name)
self.assertEquals((gle[0][0], flt(gle[0][1]), flt(gle[0][2])),
('Test Expense - %s' % abbr, 5000.0, 0.0))
self.assertEquals((gle[1][0], flt(gle[1][1]), flt(gle[1][2])),
('Test Supplier - %s' % abbr, 0.0, 5000.0))
# check balance as on today
self.assertEqual(get_balance_on(get_name("Test Expense"), nowdate()),
expense_ac_balance + 5000)
self.assertEqual(get_balance_on(get_name("Test Supplier"), nowdate()),
supplier_ac_balance + 5000)
# check previous balance
self.assertEqual(get_balance_on(get_name("Test Expense"), add_days(nowdate(), -1)), 0)
#
#
# import webnotes.model
# from webnotes.utils import nowdate, flt, add_days
# from accounts.utils import get_fiscal_year, get_balance_on
#
# company = webnotes.conn.get_default("company")
# abbr = webnotes.conn.get_value("Company", company, "abbr")
#
# data = {
# "expense_account": {
# "doctype": "Account",
# "account_name": "Test Expense",
# "parent_account": "Direct Expenses - %s" % abbr,
# "company": company,
# "debit_or_credit": "Debit",
# "is_pl_account": "Yes",
# "group_or_ledger": "Ledger"
# },
# "supplier_account": {
# "doctype": "Account",
# "account_name": "Test Supplier",
# "parent_account": "Accounts Payable - %s" % abbr,
# "company": company,
# "debit_or_credit": "Credit",
# "is_pl_account": "No",
# "group_or_ledger": "Ledger"
# },
# "test_cost_center": {
# "doctype": "Cost Center",
# "cost_center_name": "Test Cost Center",
# "parent_cost_center": "Root - %s" % abbr,
# "company_name": company,
# "group_or_ledger": "Ledger",
# "company_abbr": abbr
# },
# "journal_voucher": [
# {
# "doctype": "Journal Voucher",
# "voucher_type": "Journal Entry",
# "naming_series": "JV",
# "posting_date": nowdate(),
# "remark": "Test Journal Voucher",
# "fiscal_year": get_fiscal_year(nowdate())[0],
# "company": company
# },
# {
# "doctype": "Journal Voucher Detail",
# "parentfield": "entries",
# "account": "Test Expense - %s" % abbr,
# "debit": 5000,
# "cost_center": "Test Cost Center - %s" % abbr,
# },
# {
# "doctype": "Journal Voucher Detail",
# "parentfield": "entries",
# "account": "Test Supplier - %s" % abbr,
# "credit": 5000,
# },
# ]
# }
#
# def get_name(s):
# return s + " - " + abbr
#
# class TestJournalVoucher(unittest.TestCase):
# def setUp(self):
# webnotes.conn.begin()
#
# # create a dummy account
# webnotes.model.insert([data["expense_account"]])
# webnotes.model.insert([data["supplier_account"]])
# webnotes.model.insert([data["test_cost_center"]])
#
# def tearDown(self):
# webnotes.conn.rollback()
#
# def test_save_journal_voucher(self):
# expense_ac_balance = get_balance_on(get_name("Test Expense"), nowdate())
# supplier_ac_balance = get_balance_on(get_name("Test Supplier"), nowdate())
#
# dl = webnotes.model.insert(data["journal_voucher"])
# dl.submit()
# dl.load_from_db()
#
# # test submitted jv
# self.assertTrue(webnotes.conn.exists("Journal Voucher", dl.doclist[0].name))
# for d in dl.doclist[1:]:
# self.assertEquals(webnotes.conn.get_value("Journal Voucher Detail",
# d.name, "parent"), dl.doclist[0].name)
#
# # test gl entry
# gle = webnotes.conn.sql("""select account, debit, credit
# from `tabGL Entry` where voucher_no = %s order by account""",
# dl.doclist[0].name)
#
# self.assertEquals((gle[0][0], flt(gle[0][1]), flt(gle[0][2])),
# ('Test Expense - %s' % abbr, 5000.0, 0.0))
# self.assertEquals((gle[1][0], flt(gle[1][1]), flt(gle[1][2])),
# ('Test Supplier - %s' % abbr, 0.0, 5000.0))
#
# # check balance as on today
# self.assertEqual(get_balance_on(get_name("Test Expense"), nowdate()),
# expense_ac_balance + 5000)
# self.assertEqual(get_balance_on(get_name("Test Supplier"), nowdate()),
# supplier_ac_balance + 5000)
#
# # check previous balance
# self.assertEqual(get_balance_on(get_name("Test Expense"), add_days(nowdate(), -1)), 0)

View File

@ -0,0 +1,84 @@
import webnotes
import unittest
class TestSalesInvoice(unittest.TestCase):
def make(self):
w = webnotes.model_wrapper(webnotes.copy_doclist(test_records[0]))
w.insert()
w.submit()
return w
def test_outstanding(self):
w = self.make()
self.assertEquals(w.doc.outstanding_amount, w.doc.grand_total)
def test_payment(self):
w = self.make()
from accounts.doctype.journal_voucher.test_journal_voucher \
import test_records as jv_test_records
jv = webnotes.model_wrapper(webnotes.copy_doclist(jv_test_records[0]))
jv.doclist[1].against_invoice = w.doc.name
jv.insert()
jv.submit()
self.assertEquals(webnotes.conn.get_value("Sales Invoice", w.doc.name, "outstanding_amount"),
161.8)
jv.cancel()
self.assertEquals(webnotes.conn.get_value("Sales Invoice", w.doc.name, "outstanding_amount"),
561.8)
test_dependencies = ["Journal Voucher"]
test_records = [[
{
"naming_series": "_T-Sales Invoice-",
"company": "_Test Company",
"conversion_rate": 1.0,
"currency": "INR",
"debit_to": "_Test Customer - _TC",
"customer": "_Test Customer",
"customer_name": "_Test Customer",
"doctype": "Sales Invoice",
"due_date": "2013-01-23",
"fiscal_year": "_Test Fiscal Year 2013",
"grand_total": 561.8,
"grand_total_export": 561.8,
"net_total": 500.0,
"plc_conversion_rate": 1.0,
"posting_date": "2013-01-23",
"price_list_currency": "INR",
"price_list_name": "_Test Price List",
"territory": "_Test Territory"
},
{
"amount": 500.0,
"basic_rate": 500.0,
"description": "138-CMS Shoe",
"doctype": "Sales Invoice Item",
"export_amount": 500.0,
"export_rate": 500.0,
"income_account": "Sales - _TC",
"cost_center": "_Test Cost Center - _TC",
"item_name": "138-CMS Shoe",
"parentfield": "entries",
"qty": 1.0
},
{
"account_head": "_Test Account VAT - _TC",
"charge_type": "On Net Total",
"description": "VAT",
"doctype": "Sales Taxes and Charges",
"parentfield": "other_charges",
"tax_amount": 30.0,
},
{
"account_head": "_Test Account Service Tax - _TC",
"charge_type": "On Net Total",
"description": "Service Tax",
"doctype": "Sales Taxes and Charges",
"parentfield": "other_charges",
"tax_amount": 31.8,
}
]]

View File

@ -24,11 +24,11 @@ def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True,
if merge_entries:
gl_map = merge_similar_entries(gl_map)
check_budget(gl_map, cancel)
save_entries(gl_map, cancel, adv_adj, update_outstanding)
if cancel:
set_as_cancel(gl_map[0]["voucher_type"], gl_map[0]["voucher_no"])
check_budget(gl_map, cancel)
save_entries(gl_map, cancel, adv_adj, update_outstanding)
def merge_similar_entries(gl_map):
merged_gl_map = []

View File

@ -79,7 +79,7 @@ if group_by:
cols.append([group_by,'Data','150px',''])
for c in col_names:
cols.append([c,'Currency','150px',''])
cols.append([c, ("Amt" in c) and 'Currency' or 'Float','150px',''])
for c in cols:
colnames.append(c[0])

View File

@ -12,4 +12,4 @@ def execute():
if flt(r[1]) != abs(flt(outstanding[0][0])):
# print r, outstanding
webnotes.conn.sql("update `tab%s` set outstanding_amount = %s where name = %s" %
(dt, '%s', '%s'), (abs(flt(outstanding[0][0])), si[0]))
(dt, '%s', '%s'), (abs(flt(outstanding[0][0])), r[0]))

View File

@ -169,4 +169,5 @@ patch_list = [
"patches.february_2013.update_company_in_leave_application",
"execute:webnotes.conn.sql_ddl('alter table tabSeries change `name` `name` varchar(100)')",
"execute:webnotes.conn.sql('update tabUserRole set parentfield=\"user_roles\" where parentfield=\"userroles\"')",
"patches.february_2013.fix_outstanding"
]

View File

@ -734,13 +734,14 @@ class StatusUpdater:
"""
# get unique transactions to update
for d in self.obj.doclist:
if d.doctype == args['source_dt']:
if d.doctype == args['source_dt'] and d.fields.get(args["join_field"]):
args['name'] = d.fields[args['join_field']]
# get all qty where qty > compare_field
item = webnotes.conn.sql("""
select item_code, `%(compare_ref_field)s`, `%(compare_field)s`, parenttype, parent from `tab%(target_dt)s`
where `%(compare_ref_field)s` < `%(compare_field)s` and name="%(name)s" and docstatus=1
item = webnotes.conn.sql("""select item_code, `%(compare_ref_field)s`,
`%(compare_field)s`, parenttype, parent from `tab%(target_dt)s`
where `%(compare_ref_field)s` < `%(compare_field)s`
and name="%(name)s" and docstatus=1
""" % args, as_dict=1)
if item:
item = item[0]

View File

@ -0,0 +1 @@
test_records = [[{"print_heading": "_Test Print Heading"}]]

View File

@ -0,0 +1 @@
test_records = [[{"title": "_Test Terms and Conditions", "terms": "_Test Terms"}]]

View File

@ -53,3 +53,14 @@ def get_monthly_bulk_mail_limit():
return 999999
else:
return 500
def get_url():
from webnotes.utils import get_request_site_address
url = get_request_site_address()
if not url or "localhost" in url:
subdomain = webnotes.conn.get_value("Website Settings", "Website Settings",
"subdomain")
if subdomain:
if "http" not in subdomain:
url = "http://" + subdomain
return url

View File

@ -91,6 +91,8 @@ def delete(arg=None):
def notify(arg=None):
from webnotes.utils import cstr
from startup import get_url
fn = webnotes.conn.sql('select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0]
if fn[0] or f[1]:
fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1])
@ -110,14 +112,4 @@ def notify(arg=None):
from webnotes.utils.email_lib import sendmail
sendmail([arg['contact']], sender, message, "You have a message from %s" % (fn,))
def get_url():
from webnotes.utils import get_request_site_address
url = get_request_site_address()
if not url or "localhost" in url:
subdomain = webnotes.conn.get_value("Website Settings", "Website Settings",
"subdomain")
if subdomain:
if "http" not in subdomain:
url = "http://" + subdomain
return url