Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cannot delete a project if linked with sales order #27689

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions erpnext/projects/doctype/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def after_insert(self):
if self.sales_order:
frappe.db.set_value("Sales Order", self.sales_order, "project", self.name)

def on_trash(self):
frappe.db.set_value("Sales Order", {"project": self.name}, "project", "")

def update_percent_complete(self):
if self.percent_complete_method == "Manual":
if self.status == "Completed":
Expand Down
17 changes: 17 additions & 0 deletions erpnext/projects/doctype/project/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from erpnext.projects.doctype.project_template.test_project_template import make_project_template
from erpnext.projects.doctype.task.test_task import create_task
from erpnext.selling.doctype.sales_order.sales_order import make_project as make_project_from_so
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order

test_records = frappe.get_test_records('Project')
test_ignore = ["Sales Order"]
Expand Down Expand Up @@ -96,6 +98,21 @@ def test_project_template_having_dependent_tasks(self):

self.assertEqual(len(tasks), 2)

def test_project_linking_with_sales_order(self):
so = make_sales_order()
project = make_project_from_so(so.name)

project.save()
self.assertEqual(project.sales_order, so.name)

so.reload()
self.assertEqual(so.project, project.name)

project.delete()

so.reload()
self.assertFalse(so.project)

def get_project(name, template):

project = frappe.get_doc(dict(
Expand Down