Merge branch 'master' of github.com:webnotes/erpnext
This commit is contained in:
commit
02bc8bfe7e
@ -81,7 +81,7 @@ class DocType(DocTypeNestedSet):
|
||||
"""
|
||||
Cost Center name must be unique
|
||||
"""
|
||||
if (self.doc.__islocal or not self.doc.name) and webnotes.conn.sql("select name from `tabCost Center` where cost_center_name = %s and company_name=%s", (self.doc.cost_center_name, self.doc.company_name)):
|
||||
if (self.doc.fields.get("__islocal") or not self.doc.name) and webnotes.conn.sql("select name from `tabCost Center` where cost_center_name = %s and company_name=%s", (self.doc.cost_center_name, self.doc.company_name)):
|
||||
msgprint("Cost Center Name already exists, please rename", raise_exception=1)
|
||||
|
||||
self.validate_mandatory()
|
||||
|
@ -27,6 +27,12 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
po.insert()
|
||||
self.assertEquals(len(po.doclist.get({"parentfield": "po_raw_material_details"})), 2)
|
||||
|
||||
def test_warehouse_company_validation(self):
|
||||
from controllers.buying_controller import WrongWarehouseCompany
|
||||
po = webnotes.bean(copy=test_records[0])
|
||||
po.doc.company = "_Test Company 1"
|
||||
self.assertRaises(WrongWarehouseCompany, po.insert)
|
||||
|
||||
|
||||
test_dependencies = ["BOM"]
|
||||
|
||||
|
@ -26,10 +26,13 @@ from webnotes.model.utils import round_floats_in_doc
|
||||
|
||||
from controllers.stock_controller import StockController
|
||||
|
||||
class WrongWarehouseCompany(Exception): pass
|
||||
|
||||
class BuyingController(StockController):
|
||||
def validate(self):
|
||||
super(BuyingController, self).validate()
|
||||
self.validate_stock_or_nonstock_items()
|
||||
self.validate_warehouse_belongs_to_company()
|
||||
if self.meta.get_field("currency"):
|
||||
self.company_currency = get_company_currency(self.doc.company)
|
||||
self.validate_conversion_rate("currency", "conversion_rate")
|
||||
@ -43,6 +46,14 @@ class BuyingController(StockController):
|
||||
# set total in words
|
||||
self.set_total_in_words()
|
||||
|
||||
def validate_warehouse_belongs_to_company(self):
|
||||
for d in self.doclist.get({"warehouse": True}):
|
||||
warehouse_company = webnotes.conn.get_value("Warehouse", d.warehouse, "company")
|
||||
if warehouse_company and warehouse_company != self.doc.company:
|
||||
webnotes.msgprint(_("Warehouse must belong to company") + \
|
||||
(": %s (%s, %s)" % (d.warehouse, warehouse_company, self.doc.company)),
|
||||
raise_exception=WrongWarehouseCompany)
|
||||
|
||||
def validate_stock_or_nonstock_items(self):
|
||||
items = [d.item_code for d in self.doclist.get({"parentfield": self.fname})]
|
||||
if self.stock_items:
|
||||
|
@ -5,4 +5,4 @@ import webnotes
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_time_log_list(doctype, txt, searchfield, start, page_len, filters):
|
||||
return webnotes.conn.get_values("Time Log", filters, ["name", "activity_type", "owner"], debug=True)
|
||||
return webnotes.conn.get_values("Time Log", filters, ["name", "activity_type", "owner"])
|
@ -85,6 +85,7 @@ def backup_to_dropbox():
|
||||
os.path.basename(backup.backup_path_db))
|
||||
upload_file_to_dropbox(filename, "/database", dropbox_client)
|
||||
|
||||
webnotes.conn.close()
|
||||
response = dropbox_client.metadata("/files")
|
||||
|
||||
# upload files to files folder
|
||||
@ -108,6 +109,7 @@ def backup_to_dropbox():
|
||||
did_not_upload.append(filename)
|
||||
error_log.append(cstr(e))
|
||||
|
||||
webnotes.connect()
|
||||
return did_not_upload, list(set(error_log))
|
||||
|
||||
def get_dropbox_session():
|
||||
|
@ -34,7 +34,6 @@ def get_gdrive_authorize_url():
|
||||
"authorize_url": authorize_url,
|
||||
}
|
||||
|
||||
@webnotes.whitelist()
|
||||
def upload_files(name, mimetype, service, folder_id):
|
||||
if not webnotes.conn:
|
||||
webnotes.connect()
|
||||
@ -78,6 +77,9 @@ def backup_to_gdrive():
|
||||
did_not_upload = []
|
||||
error_log = []
|
||||
|
||||
files_folder_id = webnotes.conn.get_value("Backup Manager", None, "files_folder_id")
|
||||
|
||||
webnotes.conn.close()
|
||||
path = os.path.join(get_base_path(), "public", "files")
|
||||
for filename in os.listdir(path):
|
||||
found = False
|
||||
@ -91,9 +93,7 @@ def backup_to_gdrive():
|
||||
|
||||
#Compare Local File with Server File
|
||||
param = {}
|
||||
children = drive_service.children().list(
|
||||
folderId=webnotes.conn.get_value("Backup Manager", None, "files_folder_id"),
|
||||
**param).execute()
|
||||
children = drive_service.children().list(folderId=files_folder_id, **param).execute()
|
||||
for child in children.get('items', []):
|
||||
file = drive_service.files().get(fileId=child['id']).execute()
|
||||
if filename == file['title'] and size == int(file['fileSize']):
|
||||
@ -101,12 +101,12 @@ def backup_to_gdrive():
|
||||
break
|
||||
if not found:
|
||||
try:
|
||||
upload_files(filepath, mimetype, drive_service,
|
||||
webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
|
||||
upload_files(filepath, mimetype, drive_service, files_folder_id)
|
||||
except Exception, e:
|
||||
did_not_upload.append(filename)
|
||||
error_log.append(cstr(e))
|
||||
|
||||
webnotes.connect()
|
||||
return did_not_upload, list(set(error_log))
|
||||
|
||||
def get_gdrive_flow():
|
||||
|
@ -55,7 +55,7 @@ class DocType(DocListController):
|
||||
ch.conversion_factor = 1
|
||||
|
||||
def check_stock_uom_with_bin(self):
|
||||
if not self.doc.__islocal:
|
||||
if not self.doc.fields.get("__islocal"):
|
||||
bin = webnotes.conn.sql("select stock_uom from `tabBin` where item_code = %s",
|
||||
self.doc.name)
|
||||
if self.doc.stock_uom and bin and cstr(bin[0][0]) \
|
||||
|
@ -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 = [
|
||||
[
|
||||
{
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user