Skip to content

Commit

Permalink
fix: cannot delete a project if linked with sales order
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Sep 28, 2021
1 parent 4fdff12 commit 788177a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions erpnext/projects/doctype/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def after_insert(self):
if self.sales_order:
frappe.db.set_value("Sales Order", self.sales_order, "project", self.name)

def on_trash(self):
for so in frappe.get_all("Sales Order", {"project": self.name}, ["name"], as_dict=1):
frappe.db.set_value("Sales Order", so.name, "project", "")

def update_percent_complete(self):
if self.percent_complete_method == "Manual":
if self.status == "Completed":
Expand Down
22 changes: 19 additions & 3 deletions erpnext/projects/doctype/project/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
test_records = frappe.get_test_records('Project')
test_ignore = ["Sales Order"]

from erpnext.projects.doctype.project_template.test_project_template import get_project_template, make_project_template
from erpnext.projects.doctype.project.project import set_project_status
from erpnext.projects.doctype.project_template.test_project_template import get_project_template
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

from frappe.utils import getdate

Expand All @@ -32,7 +33,22 @@ def test_project_with_template(self):
self.assertEqual(task4.subject, 'Task 4')
self.assertEqual(getdate(task4.exp_end_date), getdate('2019-01-06'))

def get_project(name):
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):
template = get_project_template()

project = frappe.get_doc(dict(
Expand Down

0 comments on commit 788177a

Please sign in to comment.