From e1d59d6dde31c14642418cd026c73d2068e6f4f6 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 9 Sep 2016 16:53:11 +0530 Subject: [PATCH] test cases and minor changes --- .../doctype/sales_invoice/sales_invoice.py | 24 ++++++++++++------- .../doctype/timesheet/test_timesheet.py | 19 +++++++++++---- .../projects/doctype/timesheet/timesheet.js | 8 +++++++ .../projects/doctype/timesheet/timesheet.py | 2 +- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index f75a9af8ab2..2e38927c7dc 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -85,7 +85,7 @@ class SalesInvoice(SellingController): self.validate_multiple_billing("Delivery Note", "dn_detail", "amount", "items") self.update_packing_list() self.set_billing_hours_and_amount() - self.calculate_billing_amount_from_timesheet() + self.update_timesheet_billing_for_project() def before_save(self): set_account_for_mode_of_payment(self) @@ -467,13 +467,11 @@ class SalesInvoice(SellingController): if not timesheet.billing_amount and ts_doc.total_billing_amount: timesheet.billing_amount = ts_doc.total_billing_amount - def calculate_billing_amount_from_timesheet(self): - total_billing_amount = 0.0 - for data in self.timesheets: - if data.billing_amount: - total_billing_amount += data.billing_amount - - self.total_billing_amount = total_billing_amount + def update_timesheet_billing_for_project(self): + if not self.timesheets and self.project: + self.add_timesheet_data() + else: + self.calculate_billing_amount_for_timesheet() def add_timesheet_data(self): self.set('timesheets', []) @@ -486,7 +484,15 @@ class SalesInvoice(SellingController): 'timesheet_detail': data.name }) - self.calculate_billing_amount_from_timesheet() + self.calculate_billing_amount_for_timesheet() + + def calculate_billing_amount_for_timesheet(self): + total_billing_amount = 0.0 + for data in self.timesheets: + if data.billing_amount: + total_billing_amount += data.billing_amount + + self.total_billing_amount = total_billing_amount def get_warehouse(self): user_pos_profile = frappe.db.sql("""select name, warehouse from `tabPOS Profile` diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index 8e7e562442c..1e7be41d59b 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -9,11 +9,12 @@ import datetime from frappe.utils import now_datetime, nowdate from erpnext.projects.doctype.timesheet.timesheet import OverlapError from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice +from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice class TestTimesheet(unittest.TestCase): def test_timesheet_billing_amount(self): salary_structure = make_salary_structure("_T-Employee-0001") - timesheet = make_timesheet("_T-Employee-0001", True) + timesheet = make_timesheet("_T-Employee-0001", simulate = True, billable=1) self.assertEquals(timesheet.total_hours, 2) self.assertEquals(timesheet.total_billing_hours, 2) @@ -22,7 +23,7 @@ class TestTimesheet(unittest.TestCase): def test_salary_slip_from_timesheet(self): salary_structure = make_salary_structure("_T-Employee-0001") - timesheet = make_timesheet("_T-Employee-0001", simulate = True) + timesheet = make_timesheet("_T-Employee-0001", simulate = True, billable=1) salary_slip = make_salary_slip(timesheet.name) salary_slip.submit() @@ -51,11 +52,20 @@ class TestTimesheet(unittest.TestCase): item.rate = 100 sales_invoice.submit() - timesheet = frappe.get_doc('Timesheet', timesheet.name) self.assertEquals(sales_invoice.total_billing_amount, 100) self.assertEquals(timesheet.status, 'Billed') + def test_timesheet_billing_based_on_project(self): + timesheet = make_timesheet("_T-Employee-0001", simulate=True, billable=1, project = '_Test Project', company='_Test Company') + sales_invoice = create_sales_invoice(do_not_save=True) + sales_invoice.project = '_Test Project' + sales_invoice.submit() + + ts = frappe.get_doc('Timesheet', timesheet.name) + self.assertEquals(ts.per_billed, 100) + self.assertEquals(ts.time_logs[0].sales_invoice, sales_invoice.name) + def make_salary_structure(employee): name = frappe.db.get_value('Salary Structure Employee', {'employee': employee}, 'parent') if name: @@ -93,7 +103,7 @@ def make_salary_structure(employee): return salary_structure -def make_timesheet(employee, simulate=False, billable = 0, activity_type="_Test Activity Type", project=None, task=None): +def make_timesheet(employee, simulate=False, billable = 0, activity_type="_Test Activity Type", project=None, task=None, company=None): update_activity_type(activity_type) timesheet = frappe.new_doc("Timesheet") timesheet.employee = employee @@ -105,6 +115,7 @@ def make_timesheet(employee, simulate=False, billable = 0, activity_type="_Test timesheet_detail.to_time = timesheet_detail.from_time + datetime.timedelta(hours= timesheet_detail.hours) timesheet_detail.project = project timesheet_detail.task = task + timesheet_detail.company = company or '_Test Company' for data in timesheet.get('time_logs'): if simulate: diff --git a/erpnext/projects/doctype/timesheet/timesheet.js b/erpnext/projects/doctype/timesheet/timesheet.js index c4f92f3b630..c591ccb54b9 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.js +++ b/erpnext/projects/doctype/timesheet/timesheet.js @@ -21,6 +21,14 @@ frappe.ui.form.on("Timesheet", { } } } + + frm.fields_dict['time_logs'].grid.get_field('project').get_query = function() { + return{ + filters: { + 'status': frm.doc.company + } + } + } }, onload: function(frm){ diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index df87ed1bb7d..9d0371e3da2 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -255,7 +255,7 @@ class Timesheet(Document): data.billing_amount = data.billing_rate * hours data.costing_amount = data.costing_rate * hours -@frappe.whitelist() +@frappe.whitelist() def get_projectwise_timesheet_data(project, parent=None): cond = '' if parent: