mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-29 18:04:46 +00:00
Merge pull request #45908 from aerele/autofetch-timesheet
fix(projects settings): add checkbox to auto fetch timesheet in sales invoice
This commit is contained in:
@@ -895,8 +895,12 @@ frappe.ui.form.on("Sales Invoice", {
|
|||||||
|
|
||||||
project: function (frm) {
|
project: function (frm) {
|
||||||
if (frm.doc.project) {
|
if (frm.doc.project) {
|
||||||
frm.events.add_timesheet_data(frm, {
|
frappe.db.get_value("Projects Settings", {}, "fetch_timesheet_in_sales_invoice", (r) => {
|
||||||
project: frm.doc.project,
|
if (cint(r.fetch_timesheet_in_sales_invoice)) {
|
||||||
|
frm.events.add_timesheet_data(frm, {
|
||||||
|
project: frm.doc.project,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1096,16 +1096,17 @@ class SalesInvoice(SellingController):
|
|||||||
timesheet.billing_amount = ts_doc.total_billable_amount
|
timesheet.billing_amount = ts_doc.total_billable_amount
|
||||||
|
|
||||||
def update_timesheet_billing_for_project(self):
|
def update_timesheet_billing_for_project(self):
|
||||||
if self.timesheets:
|
if (
|
||||||
|
not self.timesheets
|
||||||
|
and self.project
|
||||||
|
and frappe.db.get_single_value("Projects Settings", "fetch_timesheet_in_sales_invoice")
|
||||||
|
):
|
||||||
|
self.add_timesheet_data()
|
||||||
|
else:
|
||||||
self.calculate_billing_amount_for_timesheet()
|
self.calculate_billing_amount_for_timesheet()
|
||||||
|
|
||||||
@frappe.whitelist(methods=["PUT"])
|
@frappe.whitelist()
|
||||||
def add_timesheet_data(self):
|
def add_timesheet_data(self):
|
||||||
if not self.timesheets and self.project:
|
|
||||||
self._add_timesheet_data()
|
|
||||||
self.save()
|
|
||||||
|
|
||||||
def _add_timesheet_data(self):
|
|
||||||
self.set("timesheets", [])
|
self.set("timesheets", [])
|
||||||
if self.project:
|
if self.project:
|
||||||
for data in get_projectwise_timesheet_data(self.project):
|
for data in get_projectwise_timesheet_data(self.project):
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
"timesheet_sb",
|
"timesheet_sb",
|
||||||
"ignore_workstation_time_overlap",
|
"ignore_workstation_time_overlap",
|
||||||
"ignore_user_time_overlap",
|
"ignore_user_time_overlap",
|
||||||
"ignore_employee_time_overlap"
|
"ignore_employee_time_overlap",
|
||||||
|
"fetch_timesheet_in_sales_invoice"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -33,11 +34,18 @@
|
|||||||
"fieldname": "ignore_employee_time_overlap",
|
"fieldname": "ignore_employee_time_overlap",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Ignore Employee Time Overlap"
|
"label": "Ignore Employee Time Overlap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"description": "Enabling the check box will fetch timesheet on select of a Project in Sales Invoice",
|
||||||
|
"fieldname": "fetch_timesheet_in_sales_invoice",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Fetch Timesheet in Sales Invoice"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-03-27 13:10:21.984404",
|
"modified": "2025-02-13 23:01:27.321902",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Projects",
|
"module": "Projects",
|
||||||
"name": "Projects Settings",
|
"name": "Projects Settings",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class ProjectsSettings(Document):
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from frappe.types import DF
|
from frappe.types import DF
|
||||||
|
|
||||||
|
fetch_timesheet_in_sales_invoice: DF.Check
|
||||||
ignore_employee_time_overlap: DF.Check
|
ignore_employee_time_overlap: DF.Check
|
||||||
ignore_user_time_overlap: DF.Check
|
ignore_user_time_overlap: DF.Check
|
||||||
ignore_workstation_time_overlap: DF.Check
|
ignore_workstation_time_overlap: DF.Check
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class TestTimesheet(IntegrationTestCase):
|
|||||||
self.assertEqual(item.qty, 2.00)
|
self.assertEqual(item.qty, 2.00)
|
||||||
self.assertEqual(item.rate, 50.00)
|
self.assertEqual(item.rate, 50.00)
|
||||||
|
|
||||||
|
@IntegrationTestCase.change_settings("Projects Settings", {"fetch_timesheet_in_sales_invoice": 1})
|
||||||
def test_timesheet_billing_based_on_project(self):
|
def test_timesheet_billing_based_on_project(self):
|
||||||
emp = make_employee("test_employee_6@salary.com")
|
emp = make_employee("test_employee_6@salary.com")
|
||||||
project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
||||||
@@ -62,7 +63,7 @@ class TestTimesheet(IntegrationTestCase):
|
|||||||
)
|
)
|
||||||
sales_invoice = create_sales_invoice(do_not_save=True)
|
sales_invoice = create_sales_invoice(do_not_save=True)
|
||||||
sales_invoice.project = project
|
sales_invoice.project = project
|
||||||
sales_invoice._add_timesheet_data()
|
sales_invoice.add_timesheet_data()
|
||||||
sales_invoice.submit()
|
sales_invoice.submit()
|
||||||
|
|
||||||
ts = frappe.get_doc("Timesheet", timesheet.name)
|
ts = frappe.get_doc("Timesheet", timesheet.name)
|
||||||
|
|||||||
Reference in New Issue
Block a user