Skip to content

Commit

Permalink
fix: cannot delete a project if linked with sales order (#27536) (#27689
Browse files Browse the repository at this point in the history
)
  • Loading branch information
frappe-pr-bot authored Sep 28, 2021
1 parent fbae3c7 commit 2124922
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit 2124922

Please sign in to comment.