fixes during testing version 5

This commit is contained in:
Nabin Hait 2014-11-26 15:35:08 +05:30
parent 9ed41b3abb
commit 249bbbc56f
21 changed files with 113 additions and 65 deletions

View File

@ -17,22 +17,25 @@ def create_charts(chart_name, company):
if root_account:
root_type = children.get("root_type")
if account_name not in ["account_type", "root_type"]:
if account_name not in ["account_type", "root_type", "group_or_ledger"]:
account_name_in_db = unidecode(account_name.strip().lower())
if account_name_in_db in accounts:
count = accounts.count(account_name_in_db)
account_name = account_name + " " + cstr(count)
group_or_ledger = identify_group_or_ledger(children)
report_type = "Balance Sheet" if root_type in ["Asset", "Liability", "Equity"] \
else "Profit and Loss"
account = frappe.get_doc({
"doctype": "Account",
"account_name": account_name,
"company": company,
"parent_account": parent,
"group_or_ledger": "Group" if len(children) else "Ledger",
"group_or_ledger": group_or_ledger,
"root_type": root_type,
"report_type": "Balance Sheet" \
if root_type in ["Asset", "Liability", "Equity"] else "Profit and Loss",
"report_type": report_type,
"account_type": children.get("account_type")
})
@ -47,6 +50,16 @@ def create_charts(chart_name, company):
_import_accounts(chart, None, None, root_account=True)
def identify_group_or_ledger(children):
if children.get("group_or_ledger"):
group_or_ledger = children.get("group_or_ledger")
elif len(set(children.keys()) - set(["account_type", "root_type", "group_or_ledger"])):
group_or_ledger = "Group"
else:
group_or_ledger = "Ledger"
return group_or_ledger
def get_chart(chart_name):
chart = {}
if chart_name == "Standard":

View File

@ -13,7 +13,8 @@ coa = {
}
},
_("Bank Accounts"): {
"account_type": "Bank"
"account_type": "Bank",
"group_or_ledger": "Group"
},
_("Cash In Hand"): {
_("Cash"): {
@ -26,7 +27,8 @@ coa = {
_("Earnest Money"): {}
},
_("Stock Assets"): {
"account_type": "Stock"
"account_type": "Stock",
"group_or_ledger": "Group"
},
_("Tax Assets"): {}
},
@ -47,7 +49,9 @@ coa = {
"account_type": "Fixed Asset"
}
},
_("Investments"): {},
_("Investments"): {
"group_or_ledger": "Group"
},
_("Temporary Accounts (Assets)"): {
_("Temporary Assets"): {}
},
@ -139,7 +143,8 @@ coa = {
"account_type": "Income Account"
},
_("Indirect Income"): {
"account_type": "Income Account"
"account_type": "Income Account",
"group_or_ledger": "Group"
},
"root_type": "Income"
},
@ -160,7 +165,8 @@ coa = {
},
},
_("Duties and Taxes"): {
"account_type": "Tax"
"account_type": "Tax",
"group_or_ledger": "Group"
},
_("Loans (Liabilities)"): {
_("Secured Loans"): {},

View File

@ -70,7 +70,7 @@ class JournalVoucher(AccountsController):
if not (d.party_type and d.party):
frappe.throw(_("Row{0}: Party Type and Party is required for Receivable / Payable account {1}").format(d.idx, d.account))
elif d.party_type and d.party:
frappe.throw(_("Row{0}: Party Type and Party is only applicable against Receivable / Payable account {1}").format(d.idx, d.account))
frappe.throw(_("Row{0}: Party Type and Party is only applicable against Receivable / Payable account").format(d.idx))
def check_credit_limit(self):
customers = list(set([d.party for d in self.get("entries") if d.party_type=="Customer" and flt(d.debit) > 0]))

View File

@ -89,7 +89,12 @@ class TestJournalVoucher(unittest.TestCase):
set_perpetual_inventory()
jv = frappe.copy_doc(test_records[0])
jv.get("entries")[0].account = "_Test Warehouse - _TC"
jv.get("entries")[0].update({
"account": "_Test Warehouse - _TC",
"party_type": None,
"party": None
})
jv.insert()
from erpnext.accounts.general_ledger import StockAccountInvalidTransaction
@ -152,9 +157,13 @@ class TestJournalVoucher(unittest.TestCase):
self.clear_account_balance()
jv = frappe.copy_doc(test_records[0])
jv.get("entries")[0].account = "_Test Account Cost for Goods Sold - _TC"
jv.get("entries")[0].cost_center = "_Test Cost Center - _TC"
jv.get("entries")[0].credit = 30000.0
jv.get("entries")[0].update({
"account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"party_type": None,
"party": None,
"credit": 30000.0
})
jv.get("entries")[1].debit = 30000.0
jv.submit()

View File

@ -23,7 +23,7 @@ def get_fiscal_years(date=None, fiscal_year=None, label="Date", verbose=1, compa
cond = "name = '%s'" % fiscal_year.replace("'", "\'")
elif company:
cond = """('%s' in (select company from `tabFiscal Year Company`
where `tabFiscal Year Company`.parent = `tabFiscal Year`.name))
where `tabFiscal Year Company`.parent = `tabFiscal Year`.name))
and '%s' >= year_start_date and '%s' <= year_end_date """ %(company.replace("'", "\'"), date, date)
else:
cond = "'%s' >= year_start_date and '%s' <= year_end_date" %(date, date)
@ -233,7 +233,7 @@ def get_company_default(company, fieldname):
value = frappe.db.get_value("Company", company, fieldname)
if not value:
throw(_("Please set default value {0} in Company {0}").format(frappe.get_meta("Company").get_label(fieldname), company))
throw(_("Please set default value {0} in Company {1}").format(frappe.get_meta("Company").get_label(fieldname), company))
return value

View File

@ -34,8 +34,7 @@ class TestPurchaseOrder(unittest.TestCase):
po = frappe.copy_doc(test_records[0]).insert()
self.assertRaises(frappe.ValidationError, make_purchase_receipt,
po.name)
self.assertRaises(frappe.ValidationError, make_purchase_receipt, po.name)
po = frappe.get_doc("Purchase Order", po.name)
po.is_subcontracted = "No"

View File

@ -93,3 +93,5 @@ erpnext.patches.v4_4.make_email_accounts
erpnext.patches.v5_0.update_frozen_accounts_permission_role
erpnext.patches.v5_0.update_dn_against_doc_fields
execute:frappe.db.sql("update `tabMaterial Request` set material_request_type = 'Material Transfer' where material_request_type = 'Transfer'")
execute:frappe.reload_doc('stock', 'doctype', 'item')
execute:frappe.db.sql("update `tabItem` i set apply_warehouse_wise_reorder_level=1, re_order_level=0, re_order_qty=0 where exists(select name from `tabItem Reorder` where parent=i.name)")

View File

@ -6,8 +6,8 @@ import frappe
import json
def execute():
existing_allow_negative_stock = frappe.db.get_default("allow_negative_stock")
frappe.db.set_default("allow_negative_stock", 1)
existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock")
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
head_row = ["Item Code", "Warehouse", "Quantity", "Valuation Rate"]
stock_reco_to_be_reposted = []
@ -28,4 +28,4 @@ def execute():
reco.validate()
reco.on_submit()
frappe.db.set_default("allow_negative_stock", existing_allow_negative_stock)
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)

View File

@ -116,7 +116,7 @@ class TestSalesOrder(unittest.TestCase):
if next_doc == "Sales Invoice":
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
next_doc = make_sales_invoice(so.name)
return next_doc
def create_so(self, so_doc = None):
@ -182,7 +182,7 @@ class TestSalesOrder(unittest.TestCase):
so = self.create_so()
# allow negative stock
frappe.db.set_default("allow_negative_stock", 1)
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
# submit dn
dn = self.create_dn_against_so(so)
@ -212,7 +212,7 @@ class TestSalesOrder(unittest.TestCase):
so = self.create_so()
# allow negative stock
frappe.db.set_default("allow_negative_stock", 1)
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
# set over-delivery tolerance
frappe.db.set_value('Item', so.get("sales_order_details")[0].item_code, 'tolerance', 50)
@ -268,7 +268,7 @@ class TestSalesOrder(unittest.TestCase):
so = self.create_so(test_record)
# allow negative stock
frappe.db.set_default("allow_negative_stock", 1)
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
# submit dn
dn = self.create_dn_against_so(so)
@ -317,7 +317,7 @@ class TestSalesOrder(unittest.TestCase):
so = self.create_so(test_record)
# allow negative stock
frappe.db.set_default("allow_negative_stock", 1)
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
# set over-delivery tolerance
frappe.db.set_value('Item', so.get("sales_order_details")[0].item_code, 'tolerance', 50)

View File

@ -5,7 +5,8 @@
"country": "India",
"default_currency": "INR",
"doctype": "Company",
"domain": "Manufacturing"
"domain": "Manufacturing",
"chart_of_accounts": "Standard"
},
{
"abbr": "_TC1",
@ -13,7 +14,8 @@
"country": "United States",
"default_currency": "USD",
"doctype": "Company",
"domain": "Retail"
"domain": "Retail",
"chart_of_accounts": "Standard"
},
{
"abbr": "_TC2",
@ -21,6 +23,7 @@
"default_currency": "EUR",
"country": "Germany",
"doctype": "Company",
"domain": "Retail"
"domain": "Retail",
"chart_of_accounts": "Standard"
}
]

View File

@ -47,7 +47,8 @@ def before_tests():
"language" :"english",
"company_tagline" :"Testing",
"email" :"test@erpnext.com",
"password" :"test"
"password" :"test",
"chart_of_accounts" : "Standard"
})
frappe.db.sql("delete from `tabLeave Allocation`")

View File

@ -357,7 +357,8 @@
"read_only": 0
},
{
"description": "Auto-raise Material Request if quantity goes below re-order level in a warehouse",
"depends_on": "eval:doc.is_stock_item==\"Yes\"",
"description": "Auto-raise Material Request if quantity goes below re-order level in default warehouse",
"fieldname": "reorder_section",
"fieldtype": "Section Break",
"label": "Re-order",
@ -366,7 +367,7 @@
"read_only": 0
},
{
"depends_on": "eval:doc.is_stock_item==\"Yes\"",
"depends_on": "eval:(doc.is_stock_item==\"Yes\" && !doc.apply_warehouse_wise_reorder_level)",
"fieldname": "re_order_level",
"fieldtype": "Float",
"label": "Re-Order Level",
@ -376,7 +377,7 @@
"read_only": 0
},
{
"depends_on": "eval:doc.is_stock_item==\"Yes\"",
"depends_on": "eval:(doc.is_stock_item==\"Yes\" && !doc.apply_warehouse_wise_reorder_level)",
"fieldname": "re_order_qty",
"fieldtype": "Float",
"label": "Re-Order Qty",
@ -384,12 +385,22 @@
"read_only": 0
},
{
"depends_on": "eval:doc.is_stock_item==\"Yes\"",
"fieldname": "apply_warehouse_wise_reorder_level",
"fieldtype": "Check",
"label": "Apply Warehouse-wise Reorder Level",
"permlevel": 0,
"precision": ""
},
{
"depends_on": "eval:(doc.is_stock_item==\"Yes\" && doc.apply_warehouse_wise_reorder_level)",
"fieldname": "section_break_31",
"fieldtype": "Section Break",
"permlevel": 0,
"read_only": 0
},
{
"depends_on": "eval:(doc.is_stock_item==\"Yes\" && doc.apply_warehouse_wise_reorder_level)",
"description": "Will also apply for variants unless overrridden",
"fieldname": "item_reorder",
"fieldtype": "Table",
@ -865,7 +876,7 @@
"icon": "icon-tag",
"idx": 1,
"max_attachments": 1,
"modified": "2014-11-25 18:39:56.226084",
"modified": "2014-11-26 15:05:38.116026",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item",

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe import msgprint, _
from frappe.utils import cstr, flt, getdate, now_datetime, formatdate
from frappe.utils import cstr, flt, cint, getdate, now_datetime, formatdate
from frappe.website.website_generator import WebsiteGenerator
from erpnext.setup.doctype.item_group.item_group import invalidate_cache_for, get_parent_item_groups
from frappe.website.render import clear_cache
@ -54,7 +54,7 @@ class Item(WebsiteGenerator):
self.check_item_tax()
self.validate_barcode()
self.cant_change()
self.validate_item_type_for_reorder()
self.validate_reorder_level()
self.validate_warehouse_for_reorder()
self.validate_variants()
@ -340,10 +340,15 @@ class Item(WebsiteGenerator):
if self.check_if_sle_exists() == "exists":
frappe.throw(_("As there are existing stock transactions for this item, you can not change the values of 'Has Serial No', 'Has Batch No', 'Is Stock Item' and 'Valuation Method'"))
def validate_item_type_for_reorder(self):
def validate_reorder_level(self):
if cint(self.apply_warehouse_wise_reorder_level):
self.re_order_level, self.re_order_qty = 0, 0
else:
self.set("item_reorder", [])
if self.re_order_level or len(self.get("item_reorder", {"material_request_type": "Purchase"})):
if not self.is_purchase_item:
frappe.throw(_("""To set reorder level, item must be Purchase Item"""))
frappe.throw(_("""To set reorder level, item must be a Purchase Item"""))
def validate_warehouse_for_reorder(self):
warehouse = []
@ -411,13 +416,13 @@ class Item(WebsiteGenerator):
def recalculate_bin_qty(self, newdn):
from erpnext.utilities.repost_stock import repost_stock
frappe.db.auto_commit_on_many_writes = 1
frappe.db.set_default("allow_negative_stock", 1)
existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock")
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
for warehouse in frappe.db.sql("select name from `tabWarehouse`"):
repost_stock(newdn, warehouse[0])
frappe.db.set_default("allow_negative_stock",
frappe.db.get_value("Stock Settings", None, "allow_negative_stock"))
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)
frappe.db.auto_commit_on_many_writes = 0
def copy_specification_from_item_group(self):

View File

@ -34,7 +34,7 @@ class TestItem(unittest.TestCase):
se.purpose = "Material Receipt"
se.append("mtn_details", {
"item_code": item.name,
"t_warehouse": "Stores - WP",
"t_warehouse": "Stores - _TC",
"qty": 1,
"incoming_rate": 1
})
@ -73,7 +73,7 @@ class TestItem(unittest.TestCase):
se.purpose = "Material Receipt"
se.append("mtn_details", {
"item_code": item.name,
"t_warehouse": "Stores - WP",
"t_warehouse": "Stores - _TC",
"qty": 1,
"incoming_rate": 1
})

View File

@ -399,7 +399,7 @@ class TestMaterialRequest(unittest.TestCase):
self.assertEquals(se.doctype, "Stock Entry")
self.assertEquals(len(se.get("mtn_details")), len(mr.get("indent_details")))
def test_compleated_qty_for_issue(self):
def test_completed_qty_for_issue(self):
def _get_requested_qty():
return flt(frappe.db.get_value("Bin", {"item_code": "_Test Item Home Desktop 100",
"warehouse": "_Test Warehouse - _TC"}, "indented_qty"))
@ -412,7 +412,7 @@ class TestMaterialRequest(unittest.TestCase):
mr.material_request_type = "Material Issue"
mr.submit()
#testing bin value after material request is submitted
#testing bin value after material request is submitted
self.assertEquals(_get_requested_qty(), existing_requested_qty + 54.0)
# receive items to allow issue
@ -431,7 +431,7 @@ class TestMaterialRequest(unittest.TestCase):
self.assertEquals(mr.get("indent_details")[0].ordered_qty, 60.0)
self.assertEquals(mr.get("indent_details")[1].ordered_qty, 3.0)
#testing bin requested qty after issuing stock against material request
#testing bin requested qty after issuing stock against material request
self.assertEquals(_get_requested_qty(), existing_requested_qty)
test_dependencies = ["Currency Exchange"]

View File

@ -103,7 +103,8 @@ class StockEntry(StockController):
for f in ("uom", "stock_uom", "description", "item_name", "expense_account",
"cost_center", "conversion_factor"):
item.set(f, item_details.get(f))
if not item.get(f):
item.set(f, item_details.get(f))
if not item.transfer_qty:
item.transfer_qty = item.qty * item.conversion_factor

View File

@ -24,9 +24,9 @@ def make_zero(item_code, warehouse):
sle = get_sle(item_code = item_code, warehouse = warehouse)
qty = sle[0].qty_after_transaction if sle else 0
if qty < 0:
make_stock_entry(item_code, None, warehouse, abs(qty), incoming_rate=10)
make_stock_entry(item_code=item_code, target=warehouse, qty=abs(qty), incoming_rate=10)
elif qty > 0:
make_stock_entry(item_code, warehouse, None, qty, incoming_rate=10)
make_stock_entry(item_code=item_code, source=warehouse, qty=qty, incoming_rate=10)
class TestStockEntry(unittest.TestCase):
def tearDown(self):
@ -36,31 +36,31 @@ class TestStockEntry(unittest.TestCase):
frappe.db.set_default("company", self.old_default_company)
def test_fifo(self):
frappe.db.set_default("allow_negative_stock", 1)
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
item_code = "_Test Item 2"
warehouse = "_Test Warehouse - _TC"
make_zero(item_code, warehouse)
make_stock_entry(item_code, None, warehouse, 1, incoming_rate=10)
make_stock_entry(item_code=item_code, target=warehouse, qty=1, incoming_rate=10)
sle = get_sle(item_code = item_code, warehouse = warehouse)[0]
self.assertEqual([[1, 10]], eval(sle.stock_queue))
# negative qty
make_zero(item_code, warehouse)
make_stock_entry(item_code, warehouse, None, 1, incoming_rate=10)
make_stock_entry(item_code=item_code, source=warehouse, qty=1, incoming_rate=10)
sle = get_sle(item_code = item_code, warehouse = warehouse)[0]
self.assertEqual([[-1, 10]], eval(sle.stock_queue))
# further negative
make_stock_entry(item_code, warehouse, None, 1)
make_stock_entry(item_code=item_code, source=warehouse, qty=1)
sle = get_sle(item_code = item_code, warehouse = warehouse)[0]
self.assertEqual([[-2, 10]], eval(sle.stock_queue))
# move stock to positive
make_stock_entry(item_code, None, warehouse, 3, incoming_rate=10)
make_stock_entry(item_code=item_code, target=warehouse, qty=3, incoming_rate=10)
sle = get_sle(item_code = item_code, warehouse = warehouse)[0]
self.assertEqual([[1, 10]], eval(sle.stock_queue))
@ -84,7 +84,7 @@ class TestStockEntry(unittest.TestCase):
warehouse = "_Test Warehouse - _TC"
# stock entry reqd for auto-reorder
make_stock_entry(item_code=item_code, target="_Test Warehouse 1 - _TC", qty=1, incoming_rate=1)
make_stock_entry(item_code=item_code, target="_Test Warehouse - _TC", qty=1, incoming_rate=1)
frappe.db.set_value("Stock Settings", None, "auto_indent", 1)
projected_qty = frappe.db.get_value("Bin", {"item_code": item_code,

View File

@ -195,7 +195,7 @@ class TestStockReconciliation(unittest.TestCase):
def insert_existing_sle(self, valuation_method):
frappe.db.set_value("Item", "_Test Item", "valuation_method", valuation_method)
frappe.db.set_default("allow_negative_stock", 1)
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
stock_entry = {
"company": "_Test Company",

View File

@ -142,7 +142,8 @@ class Warehouse(Document):
def recalculate_bin_qty(self, newdn):
from erpnext.utilities.repost_stock import repost_stock
frappe.db.auto_commit_on_many_writes = 1
frappe.db.set_default("allow_negative_stock", 1)
existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock")
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
for item in frappe.db.sql("""select distinct item_code from (
select name as item_code from `tabItem` where ifnull(is_stock_item, 'Yes')='Yes'
@ -150,6 +151,5 @@ class Warehouse(Document):
select distinct item_code from tabBin) a"""):
repost_stock(item[0], newdn)
frappe.db.set_default("allow_negative_stock",
frappe.db.get_value("Stock Settings", None, "allow_negative_stock"))
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)
frappe.db.auto_commit_on_many_writes = 0

View File

@ -2,7 +2,6 @@
# License: GNU General Public License v3. See license.txt
import frappe
from frappe import _
from frappe.utils import flt, cstr, nowdate, add_days, cint
from erpnext.accounts.utils import get_fiscal_year, FiscalYearError
@ -23,8 +22,7 @@ def _reorder_item():
item_warehouse_projected_qty = get_item_warehouse_projected_qty()
warehouse_company = frappe._dict(frappe.db.sql("""select name, company
from `tabWarehouse`"""))
warehouse_company = frappe._dict(frappe.db.sql("""select name, company from `tabWarehouse`"""))
default_company = (frappe.defaults.get_defaults().get("company") or
frappe.db.sql("""select name from tabCompany limit 1""")[0][0])

View File

@ -16,7 +16,8 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False)
frappe.db.auto_commit_on_many_writes = 1
if allow_negative_stock:
frappe.db.set_default("allow_negative_stock", 1)
existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock")
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
for d in frappe.db.sql("""select distinct item_code, warehouse from
(select item_code, warehouse from tabBin
@ -29,8 +30,7 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False)
frappe.db.rollback()
if allow_negative_stock:
frappe.db.set_default("allow_negative_stock",
frappe.db.get_value("Stock Settings", None, "allow_negative_stock"))
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)
frappe.db.auto_commit_on_many_writes = 0
def repost_stock(item_code, warehouse, allow_zero_rate=False, only_actual=False):