fixed conflict and aii check in global defaults

This commit is contained in:
Nabin Hait
2013-03-28 15:54:11 +05:30
21 changed files with 595 additions and 494 deletions

View File

@@ -18,169 +18,171 @@ from __future__ import unicode_literals
import unittest
import webnotes
from webnotes.model.doc import Document
from webnotes.model.code import get_obj
from webnotes.utils import cstr, flt
sql = webnotes.conn.sql
test_records = []
class TestInternalReco(unittest.TestCase):
def setUp(self):
webnotes.conn.begin()
comp1.save(1)
cust1.save(1)
bank1.save(1)
rv1.save(1)
rv_gle.save(1)
for t in jv1: t.save(1)
for t in jv1[1:]:
sql("update `tabJournal Voucher Detail` set parent = '%s' where name = '%s'" % (jv1[0].name, t.name))
ir[0].save()
for t in ir[1:]:
t.save(1)
sql("update `tabPayment to Invoice Matching Tool Detail` set voucher_no = '%s', voucher_detail_no = '%s' where parent = 'Payment to Invoice Matching Tool'" % (jv1[0].name, jv1[1].name))
sql("update `tabGL Entry` set voucher_no = %s, against_voucher = %s where voucher_no = 'rv1'", (rv1.name, rv1.name))
sql("update `tabSingles` set value = %s where doctype = 'Payment to Invoice Matching Tool' and field = 'voucher_no'", rv1.name)
self.ir = get_obj('Payment to Invoice Matching Tool', with_children=1)
self.ir.reconcile()
#===========================
def test_jv(self):
"""
Test whether JV has benn properly splitted and against doc has been updated
"""
amt_against_doc = [[cstr(d[0]), flt(d[1]), flt(d[2])]for d in sql("select against_invoice, debit, credit from `tabJournal Voucher Detail` where parent = %s and account = 'cust1 - c1'", jv1[0].name)]
self.assertTrue(amt_against_doc == [[rv1.name, 0, 100.0], ['', 0, 400.0]])
#============================
def test_gl_entry(self):
"""
Check proper gl entry has been made
"""
gle = [[cstr(d[0]), flt(d[1])] for d in sql("select against_voucher, sum(credit) - sum(debit) from `tabGL Entry` where voucher_no = %s and account = 'cust1 - c1' and ifnull(is_cancelled, 'No') = 'No' group by against_voucher", jv1[0].name)]
self.assertTrue([rv1.name, 100.0] in gle)
self.assertTrue(['', 400.0] in gle)
#============================
def test_outstanding(self):
"""
Check whether Outstanding amount has been properly updated in RV
"""
amt = sql("select outstanding_amount from `tabSales Invoice` where name = '%s'" % rv1.name)[0][0]
self.assertTrue(amt == 0)
#============================
def tearDown(self):
webnotes.conn.rollback()
# test data
#---------------
rv1 = Document(fielddata={
'doctype':'Sales Invoice',
'docstatus':1,
'debit_to':'cust1 - c1',
'grand_total': 100,
'outstanding_amount': 100,
'name': 'rv1'
})
jv1 = [Document(fielddata={
'doctype':'Journal Voucher',
'docstatus':1,
'cheque_no': '163567',
'docstatus':1,
'company': 'comp1',
'posting_date' : '2011-05-02',
'remark': 'test data',
'fiscal_year': '2011-2012',
'total_debit': 500,
'total_credit': 500
}),
Document(fielddata = {
'parenttype':'Journal Voucher',
'parentfield':'entries',
'doctype':'Journal Voucher Detail',
'account' : 'cust1 - c1',
'credit':500,
'debit' : 0,
'docstatus':1
}),
Document(fielddata = {
'parenttype':'Journal Voucher',
'parentfield':'entries',
'doctype':'Journal Voucher Detail',
'account' : 'bank1 - c1',
'credit':0,
'debit' : 500,
'docstatus':1
})]
ir = [Document(fielddata = {
'doctype':'Payment to Invoice Matching Tool',
'name' : 'Payment to Invoice Matching Tool',
'account':'cust1 - c1',
'voucher_type' : 'Sales Invoice',
'voucher_no': 'rv1'
}),
Document(fielddata = {
'parenttype':'Payment to Invoice Matching Tool',
'parentfield':'ir_payment_details',
'doctype':'Payment to Invoice Matching Tool Detail',
'parent': 'Payment to Invoice Matching Tool',
'voucher_no': 'jv1',
'name' : '123112',
'voucher_detail_no' : 'jvd1',
'selected' : 1,
'amt_due' : 500,
'amt_to_be_reconciled':100
})]
cust1 = Document(fielddata={
'doctype':'Account',
'docstatus':0,
'account_name' : 'cust1',
'debit_or_credit': 'Debit',
'company' : 'comp1',
'lft': 1,
'rgt': 2
})
bank1 = Document(fielddata={
'doctype':'Account',
'docstatus':0,
'account_name' : 'bank1',
'debit_or_credit': 'Debit',
'company' : 'comp1',
'lft': 3,
'rgt': 4
})
comp1 = Document(fielddata={
'doctype':'Company',
'abbr': 'c1',
'company_name' : 'comp1',
'name': 'comp1'
})
rv_gle = Document(fielddata={
'doctype':'GL Entry',
'account': 'cust1 - c1',
'company' : 'comp1',
'voucher_no': 'rv1',
'against_voucher': 'rv1',
'against_voucher_type': 'Sales Invoice',
'voucher_type' : 'Sales Invoice',
'debit': 100,
'credit': 0
})
# from webnotes.model.doc import Document
# from webnotes.model.code import get_obj
# from webnotes.utils import cstr, flt
# sql = webnotes.conn.sql
#
# class TestInternalReco(unittest.TestCase):
# def setUp(self):
# webnotes.conn.begin()
#
# comp1.save(1)
# cust1.save(1)
# bank1.save(1)
# rv1.save(1)
# rv_gle.save(1)
#
#
# for t in jv1: t.save(1)
# for t in jv1[1:]:
# sql("update `tabJournal Voucher Detail` set parent = '%s' where name = '%s'" % (jv1[0].name, t.name))
#
# ir[0].save()
# for t in ir[1:]:
# t.save(1)
# sql("update `tabPayment to Invoice Matching Tool Detail` set voucher_no = '%s', voucher_detail_no = '%s' where parent = 'Payment to Invoice Matching Tool'" % (jv1[0].name, jv1[1].name))
#
#
# sql("update `tabGL Entry` set voucher_no = %s, against_voucher = %s where voucher_no = 'rv1'", (rv1.name, rv1.name))
# sql("update `tabSingles` set value = %s where doctype = 'Payment to Invoice Matching Tool' and field = 'voucher_no'", rv1.name)
#
#
# self.ir = get_obj('Payment to Invoice Matching Tool', with_children=1)
# self.ir.reconcile()
#
# #===========================
# def test_jv(self):
# """
# Test whether JV has benn properly splitted and against doc has been updated
# """
# amt_against_doc = [[cstr(d[0]), flt(d[1]), flt(d[2])]for d in sql("select against_invoice, debit, credit from `tabJournal Voucher Detail` where parent = %s and account = 'cust1 - c1'", jv1[0].name)]
# self.assertTrue(amt_against_doc == [[rv1.name, 0, 100.0], ['', 0, 400.0]])
#
# #============================
# def test_gl_entry(self):
# """
# Check proper gl entry has been made
# """
# gle = [[cstr(d[0]), flt(d[1])] for d in sql("select against_voucher, sum(credit) - sum(debit) from `tabGL Entry` where voucher_no = %s and account = 'cust1 - c1' and ifnull(is_cancelled, 'No') = 'No' group by against_voucher", jv1[0].name)]
#
# self.assertTrue([rv1.name, 100.0] in gle)
# self.assertTrue(['', 400.0] in gle)
#
# #============================
# def test_outstanding(self):
# """
# Check whether Outstanding amount has been properly updated in RV
# """
# amt = sql("select outstanding_amount from `tabSales Invoice` where name = '%s'" % rv1.name)[0][0]
# self.assertTrue(amt == 0)
#
# #============================
# def tearDown(self):
# webnotes.conn.rollback()
#
#
#
#
# # test data
# #---------------
# rv1 = Document(fielddata={
# 'doctype':'Sales Invoice',
# 'docstatus':1,
# 'debit_to':'cust1 - c1',
# 'grand_total': 100,
# 'outstanding_amount': 100,
# 'name': 'rv1'
# })
#
# jv1 = [Document(fielddata={
# 'doctype':'Journal Voucher',
# 'docstatus':1,
# 'cheque_no': '163567',
# 'docstatus':1,
# 'company': 'comp1',
# 'posting_date' : '2011-05-02',
# 'remark': 'test data',
# 'fiscal_year': '2011-2012',
# 'total_debit': 500,
# 'total_credit': 500
# }),
# Document(fielddata = {
# 'parenttype':'Journal Voucher',
# 'parentfield':'entries',
# 'doctype':'Journal Voucher Detail',
# 'account' : 'cust1 - c1',
# 'credit':500,
# 'debit' : 0,
# 'docstatus':1
# }),
# Document(fielddata = {
# 'parenttype':'Journal Voucher',
# 'parentfield':'entries',
# 'doctype':'Journal Voucher Detail',
# 'account' : 'bank1 - c1',
# 'credit':0,
# 'debit' : 500,
# 'docstatus':1
# })]
#
# ir = [Document(fielddata = {
# 'doctype':'Payment to Invoice Matching Tool',
# 'name' : 'Payment to Invoice Matching Tool',
# 'account':'cust1 - c1',
# 'voucher_type' : 'Sales Invoice',
# 'voucher_no': 'rv1'
# }),
# Document(fielddata = {
# 'parenttype':'Payment to Invoice Matching Tool',
# 'parentfield':'ir_payment_details',
# 'doctype':'Payment to Invoice Matching Tool Detail',
# 'parent': 'Payment to Invoice Matching Tool',
# 'voucher_no': 'jv1',
# 'name' : '123112',
# 'voucher_detail_no' : 'jvd1',
# 'selected' : 1,
# 'amt_due' : 500,
# 'amt_to_be_reconciled':100
# })]
#
# cust1 = Document(fielddata={
# 'doctype':'Account',
# 'docstatus':0,
# 'account_name' : 'cust1',
# 'debit_or_credit': 'Debit',
# 'company' : 'comp1',
# 'lft': 1,
# 'rgt': 2
# })
#
# bank1 = Document(fielddata={
# 'doctype':'Account',
# 'docstatus':0,
# 'account_name' : 'bank1',
# 'debit_or_credit': 'Debit',
# 'company' : 'comp1',
# 'lft': 3,
# 'rgt': 4
# })
#
# comp1 = Document(fielddata={
# 'doctype':'Company',
# 'abbr': 'c1',
# 'company_name' : 'comp1',
# 'name': 'comp1'
# })
#
# rv_gle = Document(fielddata={
# 'doctype':'GL Entry',
# 'account': 'cust1 - c1',
# 'company' : 'comp1',
# 'voucher_no': 'rv1',
# 'against_voucher': 'rv1',
# 'against_voucher_type': 'Sales Invoice',
# 'voucher_type' : 'Sales Invoice',
# 'debit': 100,
# 'credit': 0
# })

View File

@@ -7,8 +7,10 @@ test_records = [
"price_list_name": "_Test Price List",
"company": "_Test Company",
"warehouse": "_Test Warehouse",
"territory": "_Test Territory",
"cash_bank_account": "_Test Account Bank Account - _TC",
"income_account": "Sales - _TC",
"cost_center": "_Test Cost Center - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
}]
]

View File

@@ -217,21 +217,11 @@ class TestSalesInvoice(unittest.TestCase):
return dn
def _insert_pos_settings(self):
from accounts.doctype.pos_setting.test_pos_setting \
import test_records as pos_setting_test_records
webnotes.conn.sql("""delete from `tabPOS Setting`""")
ps = webnotes.bean([
{
"cash_bank_account": "_Test Account Bank Account - _TC",
"company": "_Test Company",
"conversion_rate": 1.0,
"cost_center": "_Test Cost Center - _TC",
"currency": "INR",
"doctype": "POS Setting",
"income_account": "_Test Account Bank Account - _TC",
"price_list_name": "_Test Price List",
"territory": "_Test Territory",
"warehouse": "_Test Warehouse"
}
])
ps = webnotes.bean(copy=pos_setting_test_records[0])
ps.insert()
def test_sales_invoice_with_advance(self):

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-03-25 15:35:04",
"creation": "2013-03-26 11:03:08",
"docstatus": 0,
"modified": "2013-03-25 15:35:23",
"modified": "2013-03-28 15:42:14",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -210,7 +210,7 @@
"doctype": "DocField",
"fieldname": "expense_account",
"fieldtype": "Link",
"hidden": 1,
"hidden": 0,
"in_filter": 1,
"label": "Expense Account",
"options": "Account",

View File

@@ -12,7 +12,7 @@ def execute(filters=None):
item_sales_bom = get_item_sales_bom()
columns = ["Delivery Note/Sales Invoice::120", "Posting Date:Date", "Posting Time",
columns = ["Delivery Note/Sales Invoice::120", "Link::30", "Posting Date:Date", "Posting Time",
"Item Code:Link/Item", "Item Name", "Description", "Warehouse:Link/Warehouse",
"Qty:Float", "Selling Rate:Currency", "Selling Amount:Currency", "Buying Amount:Currency",
"Gross Profit:Currency", "Gross Profit %:Percent", "Project:Link/Project"]
@@ -32,8 +32,9 @@ def execute(filters=None):
else:
gross_profit = gross_profit_percent = 0.0
name = """<a href="%s">%s</a>""" % ("/".join(["#Form", row.parenttype, row.name]), row.name)
data.append([name, row.posting_date, row.posting_time, row.item_code, row.item_name,
icon = """<a href="%s"><i class="icon icon-share" style="cursor: pointer;"></i></a>""" \
% ("/".join(["#Form", row.parenttype, row.name]),)
data.append([row.name, icon, row.posting_date, row.posting_time, row.item_code, row.item_name,
row.description, row.warehouse, row.qty, row.basic_rate, row.amount, buying_amount,
gross_profit, gross_profit_percent, row.project])
@@ -57,7 +58,7 @@ def get_item_sales_bom():
item_sales_bom = {}
for d in webnotes.conn.sql("""select parenttype, parent, parent_item,
item_code, warehouse, -1*qty as total_qty
item_code, warehouse, -1*qty as total_qty, parent_detail_docname
from `tabDelivery Note Packing Item` where docstatus=1""", as_dict=True):
item_sales_bom.setdefault(d.parenttype, webnotes._dict()).setdefault(d.parent,
webnotes._dict()).setdefault(d.parent_item, []).append(d)

View File

@@ -294,18 +294,18 @@ def create_stock_in_hand_jv(reverse=False):
jv.submit()
def get_stock_rbnb_value(company):
total_received_amount = webnotes.conn.sql("""select sum(valuation_amount)
total_received_amount = webnotes.conn.sql("""select sum(valuation_rate*qty)
from `tabPurchase Receipt Item` pr_item where docstatus=1
and exists(select name from `tabItem` where name = pr_item.item_code
and is_stock_item='Yes')
and exist(select name from `tabPurchase Receipt`
and exists(select name from `tabPurchase Receipt`
where name = pr_item.parent and company = %s)""", company)
total_billed_amount = webnotes.conn.sql("""select sum(valuation_amount)
total_billed_amount = webnotes.conn.sql("""select sum(valuation_rate*qty)
from `tabPurchase Invoice Item` pi_item where docstatus=1
and exists(select name from `tabItem` where name = pi_item.item_code
and is_stock_item='Yes')
and exist(select name from `tabPurchase Invoice`
and exists(select name from `tabPurchase Invoice`
where name = pi_item.parent and company = %s)""", company)
return flt(total_received_amount[0][0]) - flt(total_billed_amount[0][0])