test cases and minor changes
This commit is contained in:
parent
1d0e8ea9c6
commit
e1d59d6dde
@ -85,7 +85,7 @@ class SalesInvoice(SellingController):
|
|||||||
self.validate_multiple_billing("Delivery Note", "dn_detail", "amount", "items")
|
self.validate_multiple_billing("Delivery Note", "dn_detail", "amount", "items")
|
||||||
self.update_packing_list()
|
self.update_packing_list()
|
||||||
self.set_billing_hours_and_amount()
|
self.set_billing_hours_and_amount()
|
||||||
self.calculate_billing_amount_from_timesheet()
|
self.update_timesheet_billing_for_project()
|
||||||
|
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
set_account_for_mode_of_payment(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:
|
if not timesheet.billing_amount and ts_doc.total_billing_amount:
|
||||||
timesheet.billing_amount = ts_doc.total_billing_amount
|
timesheet.billing_amount = ts_doc.total_billing_amount
|
||||||
|
|
||||||
def calculate_billing_amount_from_timesheet(self):
|
def update_timesheet_billing_for_project(self):
|
||||||
total_billing_amount = 0.0
|
if not self.timesheets and self.project:
|
||||||
for data in self.timesheets:
|
self.add_timesheet_data()
|
||||||
if data.billing_amount:
|
else:
|
||||||
total_billing_amount += data.billing_amount
|
self.calculate_billing_amount_for_timesheet()
|
||||||
|
|
||||||
self.total_billing_amount = total_billing_amount
|
|
||||||
|
|
||||||
def add_timesheet_data(self):
|
def add_timesheet_data(self):
|
||||||
self.set('timesheets', [])
|
self.set('timesheets', [])
|
||||||
@ -486,7 +484,15 @@ class SalesInvoice(SellingController):
|
|||||||
'timesheet_detail': data.name
|
'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):
|
def get_warehouse(self):
|
||||||
user_pos_profile = frappe.db.sql("""select name, warehouse from `tabPOS Profile`
|
user_pos_profile = frappe.db.sql("""select name, warehouse from `tabPOS Profile`
|
||||||
|
@ -9,11 +9,12 @@ import datetime
|
|||||||
from frappe.utils import now_datetime, nowdate
|
from frappe.utils import now_datetime, nowdate
|
||||||
from erpnext.projects.doctype.timesheet.timesheet import OverlapError
|
from erpnext.projects.doctype.timesheet.timesheet import OverlapError
|
||||||
from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice
|
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):
|
class TestTimesheet(unittest.TestCase):
|
||||||
def test_timesheet_billing_amount(self):
|
def test_timesheet_billing_amount(self):
|
||||||
salary_structure = make_salary_structure("_T-Employee-0001")
|
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_hours, 2)
|
||||||
self.assertEquals(timesheet.total_billing_hours, 2)
|
self.assertEquals(timesheet.total_billing_hours, 2)
|
||||||
@ -22,7 +23,7 @@ class TestTimesheet(unittest.TestCase):
|
|||||||
|
|
||||||
def test_salary_slip_from_timesheet(self):
|
def test_salary_slip_from_timesheet(self):
|
||||||
salary_structure = make_salary_structure("_T-Employee-0001")
|
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 = make_salary_slip(timesheet.name)
|
||||||
salary_slip.submit()
|
salary_slip.submit()
|
||||||
|
|
||||||
@ -51,11 +52,20 @@ class TestTimesheet(unittest.TestCase):
|
|||||||
item.rate = 100
|
item.rate = 100
|
||||||
|
|
||||||
sales_invoice.submit()
|
sales_invoice.submit()
|
||||||
|
|
||||||
timesheet = frappe.get_doc('Timesheet', timesheet.name)
|
timesheet = frappe.get_doc('Timesheet', timesheet.name)
|
||||||
self.assertEquals(sales_invoice.total_billing_amount, 100)
|
self.assertEquals(sales_invoice.total_billing_amount, 100)
|
||||||
self.assertEquals(timesheet.status, 'Billed')
|
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):
|
def make_salary_structure(employee):
|
||||||
name = frappe.db.get_value('Salary Structure Employee', {'employee': employee}, 'parent')
|
name = frappe.db.get_value('Salary Structure Employee', {'employee': employee}, 'parent')
|
||||||
if name:
|
if name:
|
||||||
@ -93,7 +103,7 @@ def make_salary_structure(employee):
|
|||||||
|
|
||||||
return salary_structure
|
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)
|
update_activity_type(activity_type)
|
||||||
timesheet = frappe.new_doc("Timesheet")
|
timesheet = frappe.new_doc("Timesheet")
|
||||||
timesheet.employee = employee
|
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.to_time = timesheet_detail.from_time + datetime.timedelta(hours= timesheet_detail.hours)
|
||||||
timesheet_detail.project = project
|
timesheet_detail.project = project
|
||||||
timesheet_detail.task = task
|
timesheet_detail.task = task
|
||||||
|
timesheet_detail.company = company or '_Test Company'
|
||||||
|
|
||||||
for data in timesheet.get('time_logs'):
|
for data in timesheet.get('time_logs'):
|
||||||
if simulate:
|
if simulate:
|
||||||
|
@ -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){
|
onload: function(frm){
|
||||||
|
@ -255,7 +255,7 @@ class Timesheet(Document):
|
|||||||
data.billing_amount = data.billing_rate * hours
|
data.billing_amount = data.billing_rate * hours
|
||||||
data.costing_amount = data.costing_rate * hours
|
data.costing_amount = data.costing_rate * hours
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_projectwise_timesheet_data(project, parent=None):
|
def get_projectwise_timesheet_data(project, parent=None):
|
||||||
cond = ''
|
cond = ''
|
||||||
if parent:
|
if parent:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user