test cases and minor changes

This commit is contained in:
Rohit Waghchaure 2016-09-09 16:53:11 +05:30
parent 1d0e8ea9c6
commit e1d59d6dde
4 changed files with 39 additions and 14 deletions

View File

@ -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`

View File

@ -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:

View File

@ -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){

View File

@ -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: