From b3c1df8561985988b43e1f08c17543c3a0e85d16 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Thu, 13 Feb 2025 23:05:34 +0530 Subject: [PATCH 1/5] fix(project settings): add checkbox to auto fetch timesheet in sales invoice (cherry picked from commit 876082ea2ffba15a631ed9ff484a38bbbe79dc14) # Conflicts: # erpnext/projects/doctype/projects_settings/projects_settings.json --- .../projects_settings/projects_settings.json | 38 +++++++++++++++++++ .../projects_settings/projects_settings.py | 1 + 2 files changed, 39 insertions(+) diff --git a/erpnext/projects/doctype/projects_settings/projects_settings.json b/erpnext/projects/doctype/projects_settings/projects_settings.json index 7fa1558a76f..2b8a03bb055 100644 --- a/erpnext/projects/doctype/projects_settings/projects_settings.json +++ b/erpnext/projects/doctype/projects_settings/projects_settings.json @@ -1,4 +1,5 @@ { +<<<<<<< HEAD "allow_copy": 0, "allow_guest_to_view": 0, "allow_import": 0, @@ -11,6 +12,20 @@ "document_type": "", "editable_grid": 1, "engine": "InnoDB", +======= + "actions": [], + "creation": "2018-02-21 16:42:13.882879", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "timesheet_sb", + "ignore_workstation_time_overlap", + "ignore_user_time_overlap", + "ignore_employee_time_overlap", + "fetch_timesheet_in_sales_invoice" + ], +>>>>>>> 876082ea2f (fix(project settings): add checkbox to auto fetch timesheet in sales invoice) "fields": [ { "allow_bulk_edit": 0, @@ -108,6 +123,7 @@ "unique": 0 }, { +<<<<<<< HEAD "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, @@ -156,6 +172,28 @@ "name": "Projects Settings", "name_case": "", "owner": "Administrator", +======= + "default": "0", + "fieldname": "ignore_employee_time_overlap", + "fieldtype": "Check", + "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, + "links": [], + "modified": "2025-02-13 23:01:27.321902", + "modified_by": "Administrator", + "module": "Projects", + "name": "Projects Settings", + "owner": "Administrator", +>>>>>>> 876082ea2f (fix(project settings): add checkbox to auto fetch timesheet in sales invoice) "permissions": [ { "amend": 0, diff --git a/erpnext/projects/doctype/projects_settings/projects_settings.py b/erpnext/projects/doctype/projects_settings/projects_settings.py index 9d940184d98..4b1530fee8e 100644 --- a/erpnext/projects/doctype/projects_settings/projects_settings.py +++ b/erpnext/projects/doctype/projects_settings/projects_settings.py @@ -14,6 +14,7 @@ class ProjectsSettings(Document): if TYPE_CHECKING: from frappe.types import DF + fetch_timesheet_in_sales_invoice: DF.Check ignore_employee_time_overlap: DF.Check ignore_user_time_overlap: DF.Check ignore_workstation_time_overlap: DF.Check From b1095bb91ba1d352792bec7f7d81810d41f9ef9f Mon Sep 17 00:00:00 2001 From: venkat102 Date: Thu, 13 Feb 2025 23:07:45 +0530 Subject: [PATCH 2/5] fix(sales invoice): check fetch_timesheet_in_sales_invoice enabled before fetching the timesheet (cherry picked from commit 914ad357fd4172e4f34c0b61ace65f04a1430ffb) # Conflicts: # erpnext/accounts/doctype/sales_invoice/sales_invoice.py --- erpnext/accounts/doctype/sales_invoice/sales_invoice.js | 8 ++++++-- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index a074c9b1c0a..36351bb3d12 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -897,8 +897,12 @@ frappe.ui.form.on("Sales Invoice", { project: function (frm) { if (frm.doc.project) { - frm.events.add_timesheet_data(frm, { - project: frm.doc.project, + frappe.db.get_value("Projects Settings", {}, "fetch_timesheet_in_sales_invoice", (r) => { + if (r.fetch_timesheet_in_sales_invoice) { + frm.events.add_timesheet_data(frm, { + project: frm.doc.project, + }); + } }); } }, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 7345a5ef78d..49bdd34bb43 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1090,7 +1090,15 @@ class SalesInvoice(SellingController): timesheet.billing_amount = ts_doc.total_billable_amount def update_timesheet_billing_for_project(self): +<<<<<<< HEAD if not self.timesheets and self.project: +======= + if ( + not self.timesheets + and self.project + and frappe.db.get_single_value("Projects Settings", "fetch_timesheet_in_sales_invoice") + ): +>>>>>>> 914ad357fd (fix(sales invoice): check fetch_timesheet_in_sales_invoice enabled before fetching the timesheet) self.add_timesheet_data() else: self.calculate_billing_amount_for_timesheet() From 97d3e8648b4b8027e4981fe14089742aadb6f495 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Thu, 13 Feb 2025 23:24:05 +0530 Subject: [PATCH 3/5] fix: check value as int (cherry picked from commit 43b13b91be8649addd9339de1b2257dd530e1f2f) --- erpnext/accounts/doctype/sales_invoice/sales_invoice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 36351bb3d12..d1c295eaf5f 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -898,7 +898,7 @@ frappe.ui.form.on("Sales Invoice", { project: function (frm) { if (frm.doc.project) { frappe.db.get_value("Projects Settings", {}, "fetch_timesheet_in_sales_invoice", (r) => { - if (r.fetch_timesheet_in_sales_invoice) { + if (cint(r.fetch_timesheet_in_sales_invoice)) { frm.events.add_timesheet_data(frm, { project: frm.doc.project, }); From feb64cb9b5e28ba2c8471fee975e42cff37d0acf Mon Sep 17 00:00:00 2001 From: venkat102 Date: Mon, 17 Feb 2025 14:49:32 +0530 Subject: [PATCH 4/5] fix: enable fetch_timesheet_in_sales_invoice in test (cherry picked from commit 5880f1d5c6b542328c288fdb2ad27bf251c0a6fe) # Conflicts: # erpnext/projects/doctype/timesheet/test_timesheet.py --- erpnext/projects/doctype/timesheet/test_timesheet.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index da042f36aef..85b4e9349c2 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -53,6 +53,7 @@ class TestTimesheet(unittest.TestCase): self.assertEqual(item.qty, 2.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): emp = make_employee("test_employee_6@salary.com") project = frappe.get_value("Project", {"project_name": "_Test Project"}) @@ -62,6 +63,10 @@ class TestTimesheet(unittest.TestCase): ) sales_invoice = create_sales_invoice(do_not_save=True) sales_invoice.project = project +<<<<<<< HEAD +======= + sales_invoice.add_timesheet_data() +>>>>>>> 5880f1d5c6 (fix: enable fetch_timesheet_in_sales_invoice in test) sales_invoice.submit() ts = frappe.get_doc("Timesheet", timesheet.name) From feec16b682925b541a003f83f0f02b7767d7aa74 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 25 Feb 2025 22:53:14 +0530 Subject: [PATCH 5/5] chore: resolve conflicts --- .../doctype/sales_invoice/sales_invoice.py | 4 - .../projects_settings/projects_settings.json | 214 +++--------------- .../doctype/timesheet/test_timesheet.py | 6 +- 3 files changed, 30 insertions(+), 194 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 49bdd34bb43..3c0689a7da9 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1090,15 +1090,11 @@ class SalesInvoice(SellingController): timesheet.billing_amount = ts_doc.total_billable_amount def update_timesheet_billing_for_project(self): -<<<<<<< HEAD - if not self.timesheets and self.project: -======= if ( not self.timesheets and self.project and frappe.db.get_single_value("Projects Settings", "fetch_timesheet_in_sales_invoice") ): ->>>>>>> 914ad357fd (fix(sales invoice): check fetch_timesheet_in_sales_invoice enabled before fetching the timesheet) self.add_timesheet_data() else: self.calculate_billing_amount_for_timesheet() diff --git a/erpnext/projects/doctype/projects_settings/projects_settings.json b/erpnext/projects/doctype/projects_settings/projects_settings.json index 2b8a03bb055..2a840b4275c 100644 --- a/erpnext/projects/doctype/projects_settings/projects_settings.json +++ b/erpnext/projects/doctype/projects_settings/projects_settings.json @@ -1,18 +1,4 @@ { -<<<<<<< HEAD - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 0, - "creation": "2018-02-21 16:42:13.882879", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", -======= "actions": [], "creation": "2018-02-21 16:42:13.882879", "doctype": "DocType", @@ -25,154 +11,25 @@ "ignore_employee_time_overlap", "fetch_timesheet_in_sales_invoice" ], ->>>>>>> 876082ea2f (fix(project settings): add checkbox to auto fetch timesheet in sales invoice) "fields": [ { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "timesheet_sb", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Timesheets", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "timesheet_sb", + "fieldtype": "Section Break", + "label": "Timesheets" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "default": "0", - "fieldname": "ignore_workstation_time_overlap", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Ignore Workstation Time Overlap", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "default": "0", + "fieldname": "ignore_workstation_time_overlap", + "fieldtype": "Check", + "label": "Ignore Workstation Time Overlap" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "default": "0", - "fieldname": "ignore_user_time_overlap", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Ignore User Time Overlap", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "default": "0", + "fieldname": "ignore_user_time_overlap", + "fieldtype": "Check", + "label": "Ignore User Time Overlap" + }, { -<<<<<<< HEAD - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "default": "0", - "fieldname": "ignore_employee_time_overlap", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Ignore Employee Time Overlap", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 1, - "istable": 0, - "max_attachments": 0, - "modified": "2018-02-21 16:42:42.357209", - "modified_by": "Administrator", - "module": "Projects", - "name": "Projects Settings", - "name_case": "", - "owner": "Administrator", -======= "default": "0", "fieldname": "ignore_employee_time_overlap", "fieldtype": "Check", @@ -180,7 +37,6 @@ }, { "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" @@ -188,40 +44,26 @@ ], "issingle": 1, "links": [], - "modified": "2025-02-13 23:01:27.321902", + "modified": "2025-02-25 22:48:03.164862", "modified_by": "Administrator", "module": "Projects", "name": "Projects Settings", "owner": "Administrator", ->>>>>>> 876082ea2f (fix(project settings): add checkbox to auto fetch timesheet in sales invoice) "permissions": [ { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 0, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 0, - "role": "System Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "System Manager", + "share": 1, "write": 1 } - ], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 + ], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index 85b4e9349c2..1e2688daf4d 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -5,6 +5,7 @@ import datetime import unittest import frappe +from frappe.tests.utils import change_settings from frappe.utils import add_to_date, now_datetime, nowdate from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice @@ -53,7 +54,7 @@ class TestTimesheet(unittest.TestCase): self.assertEqual(item.qty, 2.00) self.assertEqual(item.rate, 50.00) - @IntegrationTestCase.change_settings("Projects Settings", {"fetch_timesheet_in_sales_invoice": 1}) + @change_settings("Projects Settings", {"fetch_timesheet_in_sales_invoice": 1}) def test_timesheet_billing_based_on_project(self): emp = make_employee("test_employee_6@salary.com") project = frappe.get_value("Project", {"project_name": "_Test Project"}) @@ -63,10 +64,7 @@ class TestTimesheet(unittest.TestCase): ) sales_invoice = create_sales_invoice(do_not_save=True) sales_invoice.project = project -<<<<<<< HEAD -======= sales_invoice.add_timesheet_data() ->>>>>>> 5880f1d5c6 (fix: enable fetch_timesheet_in_sales_invoice in test) sales_invoice.submit() ts = frappe.get_doc("Timesheet", timesheet.name)