Skip to content
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
124 changes: 120 additions & 4 deletions POS/src/components/sale/CreateCustomerDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,41 @@
</option>
</select>
</div>

<!-- Governorate -->
<div>
<label class="block text-start text-sm font-medium text-gray-700 mb-2">
{{ __("Governorate") }}
</label>
<select
v-model="customerData.custom_governorate"
class="w-full px-8 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
>
<option value="">{{ __("Select Governorate") }}</option>
<option v-for="gov in governorates" :key="gov" :value="gov">
{{ gov }}
</option>
</select>
</div>

<!-- District (filtered by selected Governorate) -->
<div>
<label class="block text-start text-sm font-medium text-gray-700 mb-2">
{{ __("District") }}
</label>
<select
v-model="customerData.custom_district"
:disabled="!customerData.custom_governorate"
class="w-full px-8 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed"
>
<option value="">
{{ customerData.custom_governorate ? __("Select District") : __("Select a governorate first") }}
</option>
<option v-for="district in districts" :key="district.name" :value="district.name">
{{ district.district }}
</option>
</select>
</div>
</div>
</template>

Expand Down Expand Up @@ -280,13 +315,18 @@ const countrySearchRef = ref(null);

const customerGroups = ref([]);
const territories = ref([]);
const governorates = ref([]);
const districts = ref([]);


const customerData = ref({
customer_name: "",
mobile_no: "",
email_id: "",
customer_group: "",
territory: "",
custom_governorate: "",
custom_district: "",
});

// =============================================================================
Expand Down Expand Up @@ -398,6 +438,8 @@ const createCustomerResource = createResource({
email_id: customerData.value.email_id || "",
customer_group: customerData.value.customer_group || "",
territory: customerData.value.territory || "",
custom_governorate: customerData.value.custom_governorate || "",
custom_district: customerData.value.custom_district || "",
pos_profile: props.posProfile,
}),
onSuccess: (data) => {
Expand All @@ -422,6 +464,8 @@ const updateCustomerResource = createResource({
territory: customerData.value.territory || "",
mobile_no: customerData.value.mobile_no || "",
email_id: customerData.value.email_id || "",
custom_governorate: customerData.value.custom_governorate || "",
custom_district: customerData.value.custom_district || "",
},
}),
onSuccess: (data) => {
Expand Down Expand Up @@ -484,6 +528,50 @@ const territoriesResource = createListResource("Territory", (names) => {
}
});

const governoratesResource = createListResource("Governorate", (names) => {
governorates.value = names
})


const customerLocationResource = createResource({
url: "frappe.client.get_value",
makeParams: () => ({
doctype: "Customer",
filters: { name: props.customer?.name },
fieldname: ["custom_governorate", "custom_district"],
}),
auto: false,
onSuccess: (data) => {
customerData.value.custom_governorate = data?.custom_governorate || ""
customerData.value.custom_district = data?.custom_district || ""
},
onError: (err) => log.error("Error loading customer location", err),
})


const districtsResource = createResource({
url: "frappe.client.get_list",
makeParams: () => ({
doctype: "District",
fields: ["name", "district"],
filters: { governorate: customerData.value.custom_governorate },
limit_page_length: 0,
order_by: "district asc",
}),
auto: false,
onSuccess: (data) => {
districts.value = data || []
// Drop the selected district if it no longer belongs to the governorate
if (
customerData.value.custom_district &&
!districts.value.some((d) => d.name === customerData.value.custom_district)
) {
customerData.value.custom_district = ""
}
},
onError: (err) => log.error("Error loading Districts", err),
})

const posProfileResource = createResource({
url: "frappe.client.get_value",
makeParams: () => ({
Expand Down Expand Up @@ -515,7 +603,17 @@ const loadDialogData = async () => {
}

// Load form options
await Promise.all([territoriesResource.reload(), customerGroupsResource.reload()]);
await Promise.all([
territoriesResource.reload(),
customerGroupsResource.reload(),
governoratesResource.reload(),
])
if (isEditMode.value && props.customer?.name) {
await customerLocationResource.reload();
}
if (customerData.value.custom_governorate) {
await districtsResource.reload();
}
checkPermissions();

// Set country from POS Profile
Expand Down Expand Up @@ -559,10 +657,13 @@ const resetForm = () => {
territory: pickDefault(settings.territory, territories.value, (list) =>
list.find((n) => n === "All Territories")
),
custom_governorate: "",
custom_district: "",
});
districts.value = [];
selectedCountryCode.value = "";
phoneNumber.value = "";
};
}

// =============================================================================
// Watchers
Expand All @@ -585,8 +686,10 @@ watch(
customerData.value.territory =
customer.territory ||
territories.value.find((n) => n === "All Territories") ||
territories.value[0] ||
"";
territories.value[0] || "";

customerData.value.custom_governorate = customer.custom_governorate || "";
customerData.value.custom_district = customer.custom_district || "";
// Handle mobile_no with country code
if (customer.mobile_no) {
customerData.value.mobile_no = customer.mobile_no;
Expand Down Expand Up @@ -620,6 +723,19 @@ watch(selectedCountryCode, async (newVal, oldVal) => {
updateTerritoryFromCountry();
});


watch(
() => customerData.value.custom_governorate,
(governorate) => {
if (governorate) {
districtsResource.reload()
} else {
districts.value = []
customerData.value.custom_district = ""
}
}
)

watch(showCountryDropdown, async (isOpen) => {
if (isOpen) {
await nextTick();
Expand Down
6 changes: 6 additions & 0 deletions pos_next/api/customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def create_customer(
territory=None,
company=None,
pos_profile=None,
custom_governorate=None,
custom_district=None,
):
"""
Create a new customer from POS.
Expand All @@ -93,6 +95,8 @@ def create_customer(
territory (str): Territory (default: from Selling Settings)
company (str): Company (optional, used to auto-assign loyalty program)
pos_profile (str): POS Profile (optional, preferred for context-aware loyalty assignment)
custom_governorate (str): Governorate (optional)
custom_district (str): District (optional, must belong to the governorate)

Returns:
dict: Created customer document
Expand Down Expand Up @@ -136,6 +140,8 @@ def create_customer(
"mobile_no": mobile_no or "",
"email_id": email_id or "",
"loyalty_program": loyalty_program,
"custom_governorate": custom_governorate or None,
"custom_district": custom_district or None,
}
)

Expand Down
2 changes: 1 addition & 1 deletion pos_next/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# page_js = {"page" : "public/js/file.js"}

# include js in doctype views
# doctype_js = {"doctype" : "public/js/doctype.js"}
doctype_js = {"Customer": "public/js/customer.js"}
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
# doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"}
# doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"}
Expand Down
137 changes: 137 additions & 0 deletions pos_next/pos_next/custom/customer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"custom_fields": [
{
"_assign": null,
"_comments": null,
"_liked_by": null,
"_user_tags": null,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"creation": "2026-06-09 11:35:04.696593",
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"dt": "Customer",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_district",
"fieldtype": "Link",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"idx": 47,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_preview": 1,
"in_standard_filter": 0,
"insert_after": "custom_governorate",
"is_system_generated": 0,
"is_virtual": 0,
"label": "District",
"length": 0,
"link_filters": null,
"mandatory_depends_on": null,
"modified": "2026-06-09 11:35:04.696593",
"modified_by": "Administrator",
"module": null,
"name": "Customer-custom_district",
"no_copy": 0,
"non_negative": 0,
"options": "District",
"owner": "Administrator",
"permlevel": 0,
"placeholder": null,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"show_dashboard": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
},
{
"_assign": null,
"_comments": null,
"_liked_by": null,
"_user_tags": null,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"creation": "2026-06-09 10:57:06.280375",
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"dt": "Customer",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_governorate",
"fieldtype": "Link",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"idx": 47,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_preview": 1,
"in_standard_filter": 0,
"insert_after": "primary_address",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Governorate",
"length": 0,
"link_filters": null,
"mandatory_depends_on": null,
"modified": "2026-06-09 10:57:06.280375",
"modified_by": "Administrator",
"module": null,
"name": "Customer-custom_governorate",
"no_copy": 0,
"non_negative": 0,
"options": "Governorate",
"owner": "Administrator",
"permlevel": 0,
"placeholder": null,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"show_dashboard": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
}
],
"custom_perms": [],
"doctype": "Customer",
"links": [],
"property_setters": [],
"sync_on_migrate": 1
}
Empty file.
8 changes: 8 additions & 0 deletions pos_next/pos_next/doctype/district/district.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2026, BrainWise and contributors
// For license information, please see license.txt

// frappe.ui.form.on("District", {
// refresh(frm) {

// },
// });
Loading
Loading