Merge branch 'edge' of github.com:webnotes/erpnext into webshop

Conflicts:
	stock/doctype/item/item.txt
This commit is contained in:
Anand Doshi
2013-05-06 12:07:30 +05:30
77 changed files with 1376 additions and 370 deletions

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-03-01 19:09:43",
"creation": "2013-03-05 14:50:38",
"docstatus": 0,
"modified": "2013-03-01 08:22:16",
"modified": "2013-05-01 15:49:47",
"modified_by": "Administrator",
"owner": "harshada@webnotestech.com"
},
@@ -24,14 +24,19 @@
"permlevel": 0
},
{
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"name": "__common__",
"parent": "Batch",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"report": 1,
"role": "Material Master Manager",
"submit": 0
"submit": 0,
"write": 1
},
{
"doctype": "DocType",
@@ -94,28 +99,6 @@
"oldfieldtype": "Date"
},
{
"doctype": "DocField",
"fieldname": "trash_reason",
"fieldtype": "Small Text",
"label": "Trash Reason",
"oldfieldname": "trash_reason",
"oldfieldtype": "Small Text",
"read_only": 1
},
{
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"report": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"match": "",
"permlevel": 1
"doctype": "DocPerm"
}
]

View File

@@ -14,11 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.add_fetch("price_list_name", "currency", "ref_currency")
cur_frm.cscript.refresh = function(doc) {
// make sensitive fields(has_serial_no, is_stock_item, valuation_method)
// read only if any stock ledger entry exists
cur_frm.toggle_enable("item_code", doc.__islocal);
cur_frm.toggle_display("naming_series", sys_defaults.item_naming_by=="Naming Series"
&& doc.__islocal)
cur_frm.toggle_display("item_code", sys_defaults.item_naming_by!="Naming Series"
&& doc.__islocal)
if ((!doc.__islocal) && (doc.is_stock_item == 'Yes')) {
var callback = function(r, rt) {

View File

@@ -23,7 +23,17 @@ from webnotes.model.bean import getlist
from webnotes import msgprint, _
from webnotes.model.controller import DocListController
class PriceListCurrencyMismatch(Exception): pass
class DocType(DocListController):
def autoname(self):
if webnotes.conn.get_default("item_naming_by")=="Naming Series":
from webnotes.model.doc import make_autoname
self.doc.item_code = make_autoname(self.doc.naming_series+'.#####')
self.doc.name = self.doc.item_code
def validate(self):
if not self.doc.stock_uom:
msgprint(_("Please enter Default Unit of Measure"), raise_exception=1)
@@ -33,7 +43,7 @@ class DocType(DocListController):
self.add_default_uom_in_conversion_factor_table()
self.valiadte_item_type()
self.check_for_active_boms()
self.check_ref_rate_detail()
self.validate_price_lists()
self.fill_customer_code()
self.check_item_tax()
self.validate_barcode()
@@ -121,16 +131,21 @@ class DocType(DocListController):
if cstr(self.doc.fields.get(d)) != 'Yes':
_check_for_active_boms(fl[d])
def check_ref_rate_detail(self):
check_list=[]
def validate_price_lists(self):
price_lists=[]
for d in getlist(self.doclist,'ref_rate_details'):
if [cstr(d.price_list_name), cstr(d.ref_currency),
cint(d.selling), cint(d.buying)] in check_list:
msgprint("Ref Rate is entered twice for Price List : '%s' and Currency : '%s'." %
(d.price_list_name,d.ref_currency), raise_exception=1)
if d.price_list_name in price_lists:
msgprint(_("Cannot have two prices for same Price List") + ": " + d.price_list_name,
raise_exception= webnotes.DuplicateEntryError)
else:
check_list.append([cstr(d.price_list_name),cstr(d.ref_currency)])
price_list_currency = webnotes.conn.get_value("Price List", d.price_list_name, "currency")
if price_list_currency and d.ref_currency != price_list_currency:
msgprint(_("Currency does not match Price List Currency for Price List") \
+ ": " + d.price_list_name, raise_exception=PriceListCurrencyMismatch)
price_lists.append(d.price_list_name)
def fill_customer_code(self):
""" Append all the customer codes and insert into "customer_code" field of item table """
cust_code=[]

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-03-28 15:56:38",
"creation": "2013-04-25 10:56:55",
"docstatus": 0,
"modified": "2013-04-23 11:44:50",
"modified": "2013-05-02 15:10:00",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -34,7 +34,6 @@
"parent": "Item",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"submit": 0
},
@@ -51,6 +50,13 @@
"oldfieldtype": "Section Break",
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "naming_series",
"fieldtype": "Select",
"label": "Naming Series",
"options": "\nITEM"
},
{
"description": "Item will be saved by this name in the data base.",
"doctype": "DocField",
@@ -881,24 +887,27 @@
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"role": "Material Master Manager",
"write": 1,
"report": 1
},
{
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 0,
"report": 1,
"role": "Material Manager",
"write": 0,
"report": 1
"write": 1
},
{
"cancel": 0,
"create": 0,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"report": 1,
"role": "Material User",
"write": 0,
"report": 1
"write": 1
},
{
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"report": 1,
"role": "Material Master Manager",
"write": 1
}
]

View File

@@ -20,6 +20,22 @@ import webnotes
test_ignore = ["BOM"]
class TestItem(unittest.TestCase):
def test_duplicate_price_list(self):
item = webnotes.bean(copy=test_records[0])
item.doc.item_code = "_Test Item 10"
item_price = item.doclist.get({"doctype": "Item Price"})[0]
item.doclist.append(webnotes.doc(item_price.fields.copy()))
self.assertRaises(webnotes.DuplicateEntryError, item.insert)
def test_price_list_mismatch(self):
from stock.doctype.item.item import PriceListCurrencyMismatch
item = webnotes.bean(copy=test_records[0])
item.doc.item_code = "_Test Item 11"
item_price = item.doclist.get({"doctype": "Item Price"})[0].ref_currency="USD"
self.assertRaises(PriceListCurrencyMismatch, item.insert)
test_records = [
[{
"doctype": "Item",
@@ -45,7 +61,14 @@ test_records = [
"warehouse": "_Test Warehouse",
"warehouse_reorder_level": 20,
"warehouse_reorder_qty": 20
}],
}, {
"doctype": "Item Price",
"parentfield": "ref_rate_details",
"price_list_name": "_Test Price List",
"ref_rate": 100,
"ref_currency": "INR"
}
],
[{
"doctype": "Item",
"item_code": "_Test Item Home Desktop 100",

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-03-08 15:37:16",
"creation": "2013-04-29 15:18:04",
"docstatus": 0,
"modified": "2013-03-21 17:29:15",
"modified": "2013-04-29 19:16:45",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -68,13 +68,13 @@
"doctype": "DocField",
"fieldname": "selling",
"fieldtype": "Check",
"label": "For Selling"
"label": "Valid For Selling"
},
{
"description": "Allow this price in purchase related forms",
"doctype": "DocField",
"fieldname": "buying",
"fieldtype": "Check",
"label": "For Buying"
"label": "Valid For Buying"
}
]

View File

@@ -263,6 +263,12 @@ class TestMaterialRequest(unittest.TestCase):
se = webnotes.bean(copy=se_doclist)
self.assertRaises(webnotes.MappingMismatchError, se.insert)
def test_warehouse_company_validation(self):
from controllers.buying_controller import WrongWarehouseCompany
mr = webnotes.bean(copy=test_records[0])
mr.doc.company = "_Test Company 1"
self.assertRaises(WrongWarehouseCompany, mr.insert)
test_records = [
[
{

View File

@@ -25,6 +25,8 @@ class TestStockEntry(unittest.TestCase):
where item_code='_Test Item'""")
self.assertTrue(mr_name)
webnotes.conn.set_default("company", self.old_default_company)
def test_warehouse_company_validation(self):
from stock.doctype.stock_ledger_entry.stock_ledger_entry import InvalidWarehouseCompany
@@ -71,7 +73,7 @@ class TestStockEntry(unittest.TestCase):
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
def test_material_issue_gl_entry(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
self._clear_stock()
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
mr = webnotes.bean(copy=test_records[0])
@@ -111,9 +113,10 @@ class TestStockEntry(unittest.TestCase):
)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
webnotes.conn.set_default("company", self.old_default_company)
def test_material_transfer_gl_entry(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
self._clear_stock()
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
mr = webnotes.bean(copy=test_records[0])
@@ -145,6 +148,7 @@ class TestStockEntry(unittest.TestCase):
self.assertFalse(gl_entries)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
webnotes.conn.set_default("company", self.old_default_company)
def check_stock_ledger_entries(self, voucher_type, voucher_no, expected_sle):
# check stock ledger entries
@@ -173,6 +177,9 @@ class TestStockEntry(unittest.TestCase):
def _clear_stock(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
webnotes.conn.sql("""delete from `tabBin`""")
self.old_default_company = webnotes.conn.get_default("company")
webnotes.conn.set_default("company", "_Test Company")
def _insert_material_receipt(self):
self._clear_stock()
@@ -185,6 +192,8 @@ class TestStockEntry(unittest.TestCase):
se2.insert()
se2.submit()
webnotes.conn.set_default("company", self.old_default_company)
def _get_actual_qty(self):
return flt(webnotes.conn.get_value("Bin", {"item_code": "_Test Item",
"warehouse": "_Test Warehouse"}, "actual_qty"))
@@ -463,6 +472,8 @@ class TestStockEntry(unittest.TestCase):
self.assertEquals(actual_qty_1 - 5, actual_qty_2)
webnotes.conn.set_default("company", self.old_default_company)
return se, pr.doc.name
def test_over_stock_return(self):
@@ -563,6 +574,8 @@ class TestStockEntry(unittest.TestCase):
self.assertEquals(actual_qty_1 - 5, actual_qty_2)
webnotes.conn.set_default("company", self.old_default_company)
return se, pr.doc.name
test_records = [

View File

@@ -114,7 +114,8 @@ class DocType:
def update_serial_purchase_details(self, obj, d, serial_no, is_submit, purpose = '', rejected=None):
exists = webnotes.conn.sql("select name, status, docstatus from `tabSerial No` where name = '%s'" % (serial_no))
if is_submit:
if exists and exists[0][2] != 2 and purpose not in ['Material Transfer', 'Sales Return']:
if exists and exists[0][2] != 2 and \
purpose not in ['Material Transfer', "Material Receipt", 'Sales Return']:
msgprint("Serial No: %s already %s" % (serial_no, exists and exists[0][1]), raise_exception = 1)
elif exists:
s = Document('Serial No', exists and exists[0][0])

View File

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