diff --git a/.travis.yml b/.travis.yml index fd26535dab..1e78cebc63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,12 +19,12 @@ install: script: cd ./test_sites/ && - frappe --reinstall test_site && - frappe --install_app erpnext test_site --verbose && - frappe --request '?cmd=erpnext.setup.page.setup_wizard.setup_wizard.setup_account¤cy=USD&first_name=Test&last_name=User&company_name=Wind+Power+LLC&timezone=America/New_York&company_abbr=WP&industry=Manufacturing&country=United States&fy_start_date=2014-01-01&fy_end_date=2014-12-31&language=english&company_tagline=Testing&email=test@erpnext.com&password=test' test_site && - frappe --verbose --run_tests test_site --app erpnext + frappe --use test_site && + frappe --reinstall && + frappe --install_app erpnext --verbose && + frappe --verbose --run_tests --app erpnext before_script: - - mysql -e 'create database travis' && - - echo "USE mysql;\nUPDATE user SET password=PASSWORD('travis') WHERE user='travis';\nFLUSH PRIVILEGES;\n" | mysql -u root + - mysql -e 'create database test_site' && + - echo "USE mysql;\nUPDATE user SET password=PASSWORD('test_site') WHERE user='test_site';\nFLUSH PRIVILEGES;\n" | mysql -u root diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index e72c27e91c..3c73d1f2fc 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -33,7 +33,6 @@ class Account(Document): def validate(self): self.validate_master_name() self.validate_parent() - self.validate_duplicate_account() self.validate_root_details() self.validate_mandatory() self.validate_warehouse_account() @@ -61,12 +60,6 @@ class Account(Document): if par["report_type"]: self.report_type = par["report_type"] - def validate_duplicate_account(self): - if self.get('__islocal') or not self.name: - company_abbr = frappe.db.get_value("Company", self.company, "abbr") - if frappe.db.exists("Account", (self.account_name + " - " + company_abbr)): - throw(_("Account {0} already exists").format(self.account_name)) - def validate_root_details(self): #does not exists parent if frappe.db.exists("Account", self.name): diff --git a/erpnext/accounts/doctype/cost_center/cost_center.py b/erpnext/accounts/doctype/cost_center/cost_center.py index b20cbe9caf..0cc99188a3 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.py +++ b/erpnext/accounts/doctype/cost_center/cost_center.py @@ -61,15 +61,6 @@ class CostCenter(NestedSet): check_acc_list.append([d.account, d.fiscal_year]) def validate(self): - """ - Cost Center name must be unique - """ - if ((self.get("__islocal") or not self.name) and - frappe.db.sql("select name from `tabCost Center` where cost_center_name=%s and company=%s", - (self.cost_center_name, self.company)) - ): - msgprint(_("Cost Center Name already exists"), raise_exception=1) - self.validate_mandatory() self.validate_budget_details() diff --git a/erpnext/accounts/doctype/pos_setting/test_records.json b/erpnext/accounts/doctype/pos_setting/test_records.json index f5071629e1..0d382a716a 100644 --- a/erpnext/accounts/doctype/pos_setting/test_records.json +++ b/erpnext/accounts/doctype/pos_setting/test_records.json @@ -1,16 +1,16 @@ [ { - "cash_bank_account": "_Test Account Bank Account - _TC", - "company": "_Test Company", - "cost_center": "_Test Cost Center - _TC", - "currency": "INR", - "doctype": "POS Setting", - "expense_account": "_Test Account Cost for Goods Sold - _TC", - "income_account": "Sales - _TC", - "name": "_Test POS Setting", - "naming_series": "_T-Sales Invoice-", - "selling_price_list": "_Test Price List", - "territory": "_Test Territory", + "cash_bank_account": "_Test Account Bank Account - _TC", + "company": "_Test Company", + "cost_center": "_Test Cost Center - _TC", + "currency": "INR", + "doctype": "POS Setting", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "income_account": "Sales - _TC", + "name": "_Test POS Setting", + "naming_series": "_T-POS Setting-", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory", "warehouse": "_Test Warehouse - _TC" } -] \ No newline at end of file +] diff --git a/erpnext/hooks.txt b/erpnext/hooks.txt index d84b369fef..b4e6b8e6cc 100644 --- a/erpnext/hooks.txt +++ b/erpnext/hooks.txt @@ -21,6 +21,7 @@ update_website_context = erpnext.startup.webutils.update_website_context mail_footer = erpnext.startup.mail_footer on_session_creation = erpnext.startup.event_handlers.on_session_creation +before_tests = erpnext.setup.utils.before_tests # Bean Events # ------------------------- diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.js b/erpnext/hr/doctype/leave_allocation/leave_allocation.js index 1e376dacf5..577fcf49df 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.js +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.js @@ -1,62 +1,37 @@ // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -// ****************************************** onload ******************************************************** cur_frm.cscript.onload = function(doc, dt, dn) { if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()}); } -// ************************************** client triggers *************************************************** -// --------- -// employee -// --------- cur_frm.add_fetch('employee','employee_name','employee_name'); cur_frm.cscript.employee = function(doc, dt, dn) { calculate_total_leaves_allocated(doc, dt, dn); } -// ----------- -// leave type -// ----------- cur_frm.cscript.leave_type = function(doc, dt, dn) { calculate_total_leaves_allocated(doc, dt, dn); } -// ------------ -// fiscal year -// ------------ cur_frm.cscript.fiscal_year = function(doc, dt, dn) { calculate_total_leaves_allocated(doc, dt, dn); } -// ------------------------------- -// include previous leave balance -// ------------------------------- cur_frm.cscript.carry_forward = function(doc, dt, dn) { calculate_total_leaves_allocated(doc, dt, dn); } -// ----------------------- -// previous balance leaves -// ----------------------- cur_frm.cscript.carry_forwarded_leaves = function(doc, dt, dn) { set_multiple(dt,dn,{total_leaves_allocated : flt(doc.carry_forwarded_leaves)+flt(doc.new_leaves_allocated)}); } -// --------------------- -// new leaves allocated -// --------------------- cur_frm.cscript.new_leaves_allocated = function(doc, dt, dn) { set_multiple(dt,dn,{total_leaves_allocated : flt(doc.carry_forwarded_leaves)+flt(doc.new_leaves_allocated)}); } - -// ****************************************** utilities ****************************************************** -// --------------------------------- -// calculate total leaves allocated -// --------------------------------- calculate_total_leaves_allocated = function(doc, dt, dn) { if(cint(doc.carry_forward) == 1 && doc.leave_type && doc.fiscal_year && doc.employee){ return get_server_fields('get_carry_forwarded_leaves','','', doc, dt, dn, 1); @@ -69,5 +44,5 @@ calculate_total_leaves_allocated = function(doc, dt, dn) { cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { return{ query: "erpnext.controllers.queries.employee_query" - } -} \ No newline at end of file + } +} diff --git a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py new file mode 100644 index 0000000000..2c7332346c --- /dev/null +++ b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py @@ -0,0 +1,3 @@ +import frappe + +test_records = frappe.get_test_records('Leave Allocation') diff --git a/erpnext/hr/doctype/leave_allocation/test_records.json b/erpnext/hr/doctype/leave_allocation/test_records.json new file mode 100644 index 0000000000..036dc499bb --- /dev/null +++ b/erpnext/hr/doctype/leave_allocation/test_records.json @@ -0,0 +1,18 @@ +[ + { + "docstatus": 1, + "doctype": "Leave Allocation", + "employee": "_T-Employee-0001", + "fiscal_year": "_Test Fiscal Year 2013", + "leave_type": "_Test Leave Type", + "new_leaves_allocated": 15 + }, + { + "docstatus": 1, + "doctype": "Leave Allocation", + "employee": "_T-Employee-0002", + "fiscal_year": "_Test Fiscal Year 2013", + "leave_type": "_Test Leave Type", + "new_leaves_allocated": 15 + } +] diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index 89c98332fb..91fd583a87 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -6,20 +6,56 @@ import unittest from erpnext.hr.doctype.leave_application.leave_application import LeaveDayBlockedError, OverlapError +test_dependencies = ["Leave Allocation", "Leave Block List"] + +_test_records = [ + { + "company": "_Test Company", + "doctype": "Leave Application", + "employee": "_T-Employee-0001", + "fiscal_year": "_Test Fiscal Year 2013", + "from_date": "2013-05-01", + "leave_type": "_Test Leave Type", + "posting_date": "2013-01-02", + "to_date": "2013-05-05" + }, + { + "company": "_Test Company", + "doctype": "Leave Application", + "employee": "_T-Employee-0002", + "fiscal_year": "_Test Fiscal Year 2013", + "from_date": "2013-05-01", + "leave_type": "_Test Leave Type", + "posting_date": "2013-01-02", + "to_date": "2013-05-05" + }, + { + "company": "_Test Company", + "doctype": "Leave Application", + "employee": "_T-Employee-0001", + "fiscal_year": "_Test Fiscal Year 2013", + "from_date": "2013-01-15", + "leave_type": "_Test Leave Type LWP", + "posting_date": "2013-01-02", + "to_date": "2013-01-15" + } +] + + class TestLeaveApplication(unittest.TestCase): def tearDown(self): frappe.set_user("Administrator") - + # so that this test doesn't affect other tests frappe.db.sql("""delete from `tabEmployee Leave Approver`""") - + def _clear_roles(self): - frappe.db.sql("""delete from `tabUserRole` where parent in + frappe.db.sql("""delete from `tabUserRole` where parent in ("test@example.com", "test1@example.com", "test2@example.com")""") - + def _clear_applications(self): frappe.db.sql("""delete from `tabLeave Application`""") - + def _add_employee_leave_approver(self, employee, leave_approver): temp_session_user = frappe.session.user frappe.set_user("Administrator") @@ -30,7 +66,7 @@ class TestLeaveApplication(unittest.TestCase): }) employee.save() frappe.set_user(temp_session_user) - + def get_application(self, doc): application = frappe.copy_doc(doc) application.from_date = "2013-01-01" @@ -39,144 +75,145 @@ class TestLeaveApplication(unittest.TestCase): def test_block_list(self): self._clear_roles() - + from frappe.utils.user import add_role add_role("test1@example.com", "HR User") - - frappe.db.set_value("Department", "_Test Department", + + frappe.db.set_value("Department", "_Test Department", "leave_block_list", "_Test Leave Block List") - - application = self.get_application(test_records[1]) + + application = self.get_application(_test_records[0]) application.insert() application.status = "Approved" self.assertRaises(LeaveDayBlockedError, application.submit) - + frappe.set_user("test1@example.com") # clear other applications frappe.db.sql("delete from `tabLeave Application`") - - application = self.get_application(test_records[1]) + + application = self.get_application(_test_records[0]) self.assertTrue(application.insert()) - + def test_overlap(self): self._clear_roles() self._clear_applications() - + from frappe.utils.user import add_role add_role("test@example.com", "Employee") add_role("test2@example.com", "Leave Approver") - + frappe.set_user("test@example.com") - application = self.get_application(test_records[1]) + application = self.get_application(_test_records[0]) application.leave_approver = "test2@example.com" application.insert() - - application = self.get_application(test_records[1]) + + application = self.get_application(_test_records[0]) application.leave_approver = "test2@example.com" self.assertRaises(OverlapError, application.insert) - + def test_global_block_list(self): self._clear_roles() from frappe.utils.user import add_role add_role("test1@example.com", "Employee") add_role("test@example.com", "Leave Approver") - - application = self.get_application(test_records[3]) + add_role("test@example.com", "HR Manager") + + application = self.get_application(_test_records[1]) application.leave_approver = "test@example.com" - - frappe.db.set_value("Leave Block List", "_Test Leave Block List", + + frappe.db.set_value("Leave Block List", "_Test Leave Block List", "applies_to_all_departments", 1) - frappe.db.set_value("Employee", "_T-Employee-0002", "department", + frappe.db.set_value("Employee", "_T-Employee-0002", "department", "_Test Department") - + frappe.set_user("test1@example.com") application.insert() - + frappe.set_user("test@example.com") application.status = "Approved" self.assertRaises(LeaveDayBlockedError, application.submit) - - frappe.db.set_value("Leave Block List", "_Test Leave Block List", + + frappe.db.set_value("Leave Block List", "_Test Leave Block List", "applies_to_all_departments", 0) - + def test_leave_approval(self): self._clear_roles() - + from frappe.utils.user import add_role add_role("test@example.com", "Employee") add_role("test1@example.com", "Leave Approver") add_role("test2@example.com", "Leave Approver") - + self._test_leave_approval_basic_case() self._test_leave_approval_invalid_leave_approver_insert() self._test_leave_approval_invalid_leave_approver_submit() self._test_leave_approval_valid_leave_approver_insert() - + def _test_leave_approval_basic_case(self): self._clear_applications() - + # create leave application as Employee frappe.set_user("test@example.com") - application = self.get_application(test_records[1]) + application = self.get_application(_test_records[0]) application.leave_approver = "test1@example.com" application.insert() - + # submit leave application by Leave Approver frappe.set_user("test1@example.com") application.status = "Approved" application.submit() self.assertEqual(frappe.db.get_value("Leave Application", application.name, "docstatus"), 1) - + def _test_leave_approval_invalid_leave_approver_insert(self): from erpnext.hr.doctype.leave_application.leave_application import InvalidLeaveApproverError - + self._clear_applications() - + # add a different leave approver in the employee's list # should raise exception if not a valid leave approver self._add_employee_leave_approver("_T-Employee-0001", "test2@example.com") - + # TODO - add test2@example.com leave approver in employee's leave approvers list - application = self.get_application(test_records[1]) + application = self.get_application(_test_records[0]) frappe.set_user("test@example.com") - + application.leave_approver = "test1@example.com" self.assertRaises(InvalidLeaveApproverError, application.insert) - + frappe.db.sql("""delete from `tabEmployee Leave Approver` where parent=%s""", "_T-Employee-0001") - + def _test_leave_approval_invalid_leave_approver_submit(self): self._clear_applications() self._add_employee_leave_approver("_T-Employee-0001", "test2@example.com") - + # create leave application as employee # but submit as invalid leave approver - should raise exception frappe.set_user("test@example.com") - application = self.get_application(test_records[1]) + application = self.get_application(_test_records[0]) application.leave_approver = "test2@example.com" application.insert() frappe.set_user("test1@example.com") application.status = "Approved" - + from erpnext.hr.doctype.leave_application.leave_application import LeaveApproverIdentityError self.assertRaises(LeaveApproverIdentityError, application.submit) frappe.db.sql("""delete from `tabEmployee Leave Approver` where parent=%s""", "_T-Employee-0001") - + def _test_leave_approval_valid_leave_approver_insert(self): self._clear_applications() self._add_employee_leave_approver("_T-Employee-0001", "test2@example.com") - + original_department = frappe.db.get_value("Employee", "_T-Employee-0001", "department") frappe.db.set_value("Employee", "_T-Employee-0001", "department", None) - + frappe.set_user("test@example.com") - application = self.get_application(test_records[1]) + application = self.get_application(_test_records[0]) application.leave_approver = "test2@example.com" application.insert() @@ -186,12 +223,8 @@ class TestLeaveApplication(unittest.TestCase): application.submit() self.assertEqual(frappe.db.get_value("Leave Application", application.name, "docstatus"), 1) - + frappe.db.sql("""delete from `tabEmployee Leave Approver` where parent=%s""", "_T-Employee-0001") - - frappe.db.set_value("Employee", "_T-Employee-0001", "department", original_department) - -test_dependencies = ["Leave Block List"] -test_records = frappe.get_test_records('Leave Application') \ No newline at end of file + frappe.db.set_value("Employee", "_T-Employee-0001", "department", original_department) diff --git a/erpnext/hr/doctype/leave_application/test_records.json b/erpnext/hr/doctype/leave_application/test_records.json deleted file mode 100644 index aac41fb235..0000000000 --- a/erpnext/hr/doctype/leave_application/test_records.json +++ /dev/null @@ -1,48 +0,0 @@ -[ - { - "docstatus": 1, - "doctype": "Leave Allocation", - "employee": "_T-Employee-0001", - "fiscal_year": "_Test Fiscal Year 2013", - "leave_type": "_Test Leave Type", - "new_leaves_allocated": 15 - }, - { - "company": "_Test Company", - "doctype": "Leave Application", - "employee": "_T-Employee-0001", - "fiscal_year": "_Test Fiscal Year 2013", - "from_date": "2013-05-01", - "leave_type": "_Test Leave Type", - "posting_date": "2013-01-02", - "to_date": "2013-05-05" - }, - { - "docstatus": 1, - "doctype": "Leave Allocation", - "employee": "_T-Employee-0002", - "fiscal_year": "_Test Fiscal Year 2013", - "leave_type": "_Test Leave Type", - "new_leaves_allocated": 15 - }, - { - "company": "_Test Company", - "doctype": "Leave Application", - "employee": "_T-Employee-0002", - "fiscal_year": "_Test Fiscal Year 2013", - "from_date": "2013-05-01", - "leave_type": "_Test Leave Type", - "posting_date": "2013-01-02", - "to_date": "2013-05-05" - }, - { - "company": "_Test Company", - "doctype": "Leave Application", - "employee": "_T-Employee-0001", - "fiscal_year": "_Test Fiscal Year 2013", - "from_date": "2013-01-15", - "leave_type": "_Test Leave Type LWP", - "posting_date": "2013-01-02", - "to_date": "2013-01-15" - } -] \ No newline at end of file diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py index e8c978e639..28a9f3fb69 100644 --- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py @@ -9,14 +9,14 @@ class TestSalarySlip(unittest.TestCase): frappe.db.sql("""delete from `tabLeave Application`""") frappe.db.sql("""delete from `tabSalary Slip`""") from erpnext.hr.doctype.leave_application.test_leave_application import test_records as leave_applications - la = frappe.copy_doc(leave_applications[4]) + la = frappe.copy_doc(leave_applications[2]) la.insert() la.status = "Approved" la.submit() - + def tearDown(self): frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 0) - + def test_salary_slip_with_holidays_included(self): frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 1) ss = frappe.copy_doc(test_records[0]) @@ -29,7 +29,7 @@ class TestSalarySlip(unittest.TestCase): self.assertEquals(ss.deduction_details[1].d_modified_amount, 48.39) self.assertEquals(ss.gross_pay, 15016.13) self.assertEquals(ss.net_pay, 14867.74) - + def test_salary_slip_with_holidays_excluded(self): ss = frappe.copy_doc(test_records[0]) ss.insert() @@ -44,4 +44,4 @@ class TestSalarySlip(unittest.TestCase): test_dependencies = ["Leave Application"] -test_records = frappe.get_test_records('Salary Slip') \ No newline at end of file +test_records = frappe.get_test_records('Salary Slip') diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index efbc12f6f8..a734ffd127 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -3,8 +3,7 @@ from __future__ import unicode_literals import frappe -from frappe import _, msgprint, throw -import json +from frappe import _, throw def get_company_currency(company): currency = frappe.db.get_value("Company", company, "default_currency") @@ -38,3 +37,30 @@ def get_price_list_currency(price_list): throw(_("Price List {0} is disabled").format(price_list)) else: return {"price_list_currency": price_list_currency} + +def before_tests(): + # complete setup if missing + from erpnext.setup.page.setup_wizard.setup_wizard import setup_account + if not frappe.get_list("Item Group"): + setup_account({ + "currency" :"USD", + "first_name" :"Test", + "last_name" :"User", + "company_name" :"Wind Power LLC", + "timezone" :"America/New_York", + "company_abbr" :"WP", + "industry" :"Manufacturing", + "country" :"United States", + "fy_start_date" :"2014-01-01", + "fy_end_date" :"2014-12-31", + "language" :"english", + "company_tagline" :"Testing", + "email" :"test@erpnext.com", + "password" :"test" + }) + + frappe.db.sql("delete from `tabLeave Allocation`") + frappe.db.sql("delete from `tabLeave Application`") + frappe.db.sql("delete from `tabSalary Slip`") + frappe.db.sql("delete from `tabItem Price`") + frappe.db.commit() diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index a894ac1aab..c4ca77fff2 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -27,6 +27,8 @@ class Item(WebsiteGenerator): def validate(self): if not self.stock_uom: msgprint(_("Please enter default Unit of Measure"), raise_exception=1) + if self.image and not self.website_image: + self.website_image = self.image self.check_warehouse_is_set_for_stock_item() self.check_stock_uom_with_bin() @@ -131,6 +133,7 @@ class Item(WebsiteGenerator): bom = frappe.db.sql("""select name from `tabBOM` where item = %s and is_active = 1""", (self.name,)) if bom and bom[0][0]: + print self.name frappe.throw(_("""Allow Bill of Materials should be 'Yes'. Because one or many active BOMs present for this item""")) def fill_customer_code(self): diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 37886ce1a1..183e3e51d2 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -190,6 +190,7 @@ class TestStockReconciliation(unittest.TestCase): }) stock_reco.insert() stock_reco.submit() + frappe.db.commit() return stock_reco def insert_existing_sle(self, valuation_method): diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 8cb920b3a3..81e028ed84 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -56,7 +56,7 @@ class Warehouse(Document): ac_doc.ignore_permissions = True ac_doc.insert() - msgprint(_("Account head {0} created")) + msgprint(_("Account head {0} created").format(ac_doc.name)) def validate_parent_account(self): if not self.create_account_under: diff --git a/erpnext/templates/includes/product_in_grid.html b/erpnext/templates/includes/product_in_grid.html index 7edd0ded1a..4c4be713c7 100644 --- a/erpnext/templates/includes/product_in_grid.html +++ b/erpnext/templates/includes/product_in_grid.html @@ -1,6 +1,6 @@