diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index 97b60365f88..8702a82cd6b 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -522,8 +522,13 @@ frappe.ui.form.on("Purchase Invoice", { }, onload: function(frm) { - if(frm.doc.__onload && !frm.doc.__onload.supplier_tds) { - me.frm.set_df_property("apply_tds", "read_only", 1); + if(frm.doc.__onload) { + if(frm.doc.supplier) { + frm.doc.apply_tds = frm.doc.__onload.supplier_tds ? 1 : 0; + } + if(!frm.doc.__onload.supplier_tds) { + frm.set_df_property("apply_tds", "read_only", 1); + } } erpnext.queries.setup_queries(frm, "Warehouse", function() { diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 34bbe7b9994..e775263b6df 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -30,8 +30,9 @@ class AccountsController(TransactionBase): return self.__company_currency def onload(self): - self.get("__onload").make_payment_via_journal_entry \ - = frappe.db.get_single_value('Accounts Settings', 'make_payment_via_journal_entry') + if self.get("__onload"): + self.get("__onload").make_payment_via_journal_entry \ + = frappe.db.get_single_value('Accounts Settings', 'make_payment_via_journal_entry') if self.is_new(): relevant_docs = ("Quotation", "Purchase Order", "Sales Order", diff --git a/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py b/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py index ec640fc22b5..09bbcba0e4e 100644 --- a/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py +++ b/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py @@ -39,6 +39,7 @@ class TestEmployeeOnboarding(unittest.TestCase): # complete the task project = frappe.get_doc('Project', onboarding.project) + project.load_tasks() project.tasks[0].status = 'Closed' project.save() diff --git a/erpnext/hr/doctype/employee_separation/test_employee_separation.py b/erpnext/hr/doctype/employee_separation/test_employee_separation.py index 4c3e5667132..2fa114d3452 100644 --- a/erpnext/hr/doctype/employee_separation/test_employee_separation.py +++ b/erpnext/hr/doctype/employee_separation/test_employee_separation.py @@ -10,9 +10,9 @@ test_dependencies = ["Employee Onboarding"] class TestEmployeeSeparation(unittest.TestCase): def test_employee_separation(self): - employee = get_employee() + employee = frappe.db.get_value("Employee", {"status": "Active"}) separation = frappe.new_doc('Employee Separation') - separation.employee = employee.name + separation.employee = employee separation.company = '_Test Company' separation.append('activities', { 'activity_name': 'Deactivate Employee', @@ -23,7 +23,4 @@ class TestEmployeeSeparation(unittest.TestCase): separation.submit() self.assertEqual(separation.docstatus, 1) separation.cancel() - self.assertEqual(separation.project, "") - -def get_employee(): - return frappe.get_doc('Employee', {'employee_name': 'Test Researcher'}) \ No newline at end of file + self.assertEqual(separation.project, "") \ No newline at end of file diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index 09cdd547f5d..44879abf053 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -18,7 +18,7 @@ class ExpenseApproverIdentityError(frappe.ValidationError): pass class ExpenseClaim(AccountsController): def onload(self): - self.get("__onload").make_payment_via_journal_entry = frappe.db.get_single_value('Accounts Settings', + self.get("__onload").make_payment_via_journal_entry = frappe.db.get_single_value('Accounts Settings', 'make_payment_via_journal_entry') def validate(self): @@ -103,7 +103,7 @@ class ExpenseClaim(AccountsController): self.validate_account_details() payable_amount = flt(self.total_sanctioned_amount) - flt(self.total_advance_amount) - + # payable entry if payable_amount: gl_entry.append( @@ -233,7 +233,7 @@ class ExpenseClaim(AccountsController): expense.default_account = get_expense_claim_account(expense.expense_type, self.company)["account"] def update_reimbursed_amount(doc): - amt = frappe.db.sql("""select ifnull(sum(debit_in_account_currency), 0) as amt + amt = frappe.db.sql("""select ifnull(sum(debit_in_account_currency), 0) as amt from `tabGL Entry` where against_voucher_type = 'Expense Claim' and against_voucher = %s and party = %s """, (doc.name, doc.employee) ,as_dict=1)[0].amt @@ -288,7 +288,7 @@ def get_expense_claim_account(expense_claim_type, company): if not account: frappe.throw(_("Please set default account in Expense Claim Type {0}") .format(expense_claim_type)) - + return { "account": account } @@ -301,9 +301,9 @@ def get_advances(employee, advance_id=None): condition = 'name="{0}"'.format(frappe.db.escape(advance_id)) return frappe.db.sql(""" - select + select name, posting_date, paid_amount, claimed_amount, advance_account - from + from `tabEmployee Advance` where {0} """.format(condition), as_dict=1) diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py index 075bc63345d..dcf0e68400d 100644 --- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py @@ -13,19 +13,23 @@ test_dependencies = ['Employee'] class TestExpenseClaim(unittest.TestCase): def test_total_expense_claim_for_project(self): frappe.db.sql("""delete from `tabTask` where project = "_Test Project 1" """) + frappe.db.sql("""delete from `tabProject Task` where parent = "_Test Project 1" """) frappe.db.sql("""delete from `tabProject` where name = "_Test Project 1" """) - + frappe.db.sql("delete from `tabExpense Claim` where project='_Test Project 1'") frappe.get_doc({ "project_name": "_Test Project 1", "doctype": "Project", - "tasks" : - [{ "title": "_Test Project Task 1", "status": "Open" }] + }).save() + + task = frappe.get_doc({ + "doctype": "Task", + "subject": "_Test Project Task 1", + "project": "_Test Project 1" }).save() task_name = frappe.db.get_value("Task", {"project": "_Test Project 1"}) payable_account = get_payable_account("Wind Power LLC") - make_expense_claim(payable_account, 300, 200, "Wind Power LLC","Travel Expenses - WP", "_Test Project 1", task_name) self.assertEqual(frappe.db.get_value("Task", task_name, "total_expense_claim"), 200) @@ -103,9 +107,10 @@ def get_payable_account(company): return frappe.get_cached_value('Company', company, 'default_payable_account') def make_expense_claim(payable_account,claim_amount, sanctioned_amount, company, account, project=None, task_name=None): + employee = frappe.db.get_value("Employee", {"status": "Active"}) expense_claim = frappe.get_doc({ "doctype": "Expense Claim", - "employee": "_T-Employee-00001", + "employee": employee, "payable_account": payable_account, "approval_status": "Approved", "company": company, diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index ebb15997962..f52d8fde35c 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -241,7 +241,7 @@ class Project(Document): from_expense_claim = frappe.db.sql("""select sum(total_sanctioned_amount) as total_sanctioned_amount from `tabExpense Claim` where project = %s - and docstatus = 1""", self.name, as_dict=1)[0] + and docstatus = 1""", self.name, as_dict=1, debug=1)[0] self.actual_start_date = from_time_sheet.start_date self.actual_end_date = from_time_sheet.end_date diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index 83d3b7de5ec..12302789a9b 100755 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -99,7 +99,7 @@ class Task(NestedSet): def update_project(self): if self.project and not self.flags.from_project: - frappe.get_doc("Project", self.project).update_percent_complete() + frappe.get_doc("Project", self.project).update_project() def check_recursion(self): if self.flags.ignore_recursion_check: return diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index ed7f2ca4323..bcef940b344 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -419,6 +419,7 @@ def make_purchase_invoice(source_name, target_doc=None): doc = frappe.get_doc(target) doc.ignore_pricing_rule = 1 + doc.run_method("onload") doc.run_method("set_missing_values") doc.run_method("calculate_taxes_and_totals")