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