Value for Customer: Territory Missing when importing Students

When importing student data using the Data Import tool, I get the following error stating “Error: Value missing for Customer: Territory”. Student DocType doesn’t have a field name called “Customer Territory”

It seems like this is a bug. I had to do some modifications to get it working.

Reason for the Error:

When Creating a single student(Not Bulk uploading, this is the normal single entry method), a customer will be created by default, When a customer is added by Default Territory will be selected and it is a mandatory field in the Customer DocType. Which means the normal student-adding method works fine.

However, when bulk uploading students, the customer-creating method in Student.py, there is no code for entering the Territory for the customer.

Solution:

Edit the Student.py file. with the below lines of code

def create_customer(self):
    # Fetch the default territory from Selling Settings or use a fallback
    default_territory = frappe.db.get_single_value("Selling Settings", "territory") or "Default Territory"
   
    customer = frappe.get_doc(
        {
            "doctype": "Customer",
            "customer_name": self.student_name,
            "customer_group": self.customer_group
            or frappe.db.get_single_value("Selling Settings", "customer_group"),
            "customer_type": "Individual",
            "image": self.image,
            "territory": default_territory,  # Ensure the mandatory field is set
        }
    ).insert()