From 86880ef206c1914fcfda2f2b277850460586f9fc Mon Sep 17 00:00:00 2001 From: meichthys Date: Sun, 15 Feb 2026 02:53:33 +0000 Subject: [PATCH] Fix #98 --- .../doctype/church_person/church_person.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/church/church_people/doctype/church_person/church_person.py b/church/church_people/doctype/church_person/church_person.py index b5f4b0a..e54cbc1 100644 --- a/church/church_people/doctype/church_person/church_person.py +++ b/church/church_people/doctype/church_person/church_person.py @@ -106,6 +106,22 @@ class ChurchPerson(Document): @frappe.whitelist() def new_family_from_person(self): + # Check if a family with this person's name already exists + existing_family = frappe.db.exists( + "Church Family", {"family_name": f"{self.last_name} - {self.first_name}"} + ) + + if existing_family: + # Set this person's family to the existing one + self.family = existing_family + self.is_head_of_household = False # Not head of household in an existing family + self.save() + frappe.msgprint( + f"⚠️ The {self.last_name} - {self.first_name} family already exists. This person has been added to that family." + ) + + return # Don't create a new family + doc = frappe.new_doc("Church Family") doc.family_name = f"{self.last_name} - {self.first_name}" doc.save()