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
4 changes: 2 additions & 2 deletions rmax_custom/api/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _get_default_territory():
def create_customer_with_address(
customer_name,
mobile_no=None,
customer_type="Individual",
customer_type="Company",
email_id=None,
country=None,
default_currency=None,
Expand Down Expand Up @@ -67,7 +67,7 @@ def create_customer_with_address(
customer = frappe.get_doc({
"doctype": "Customer",
"customer_name": customer_name,
"customer_type": customer_type or "Individual",
"customer_type": customer_type or "Company",
"customer_group": _get_default_customer_group(),
"territory": _get_default_territory(),
"default_currency": default_currency,
Expand Down
8 changes: 7 additions & 1 deletion rmax_custom/public/js/create_customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ function open_create_customer_dialog(frm) {
],
primary_action_label: "Create Customer",
primary_action(values) {

function count_digits(val) {
if (!val) return 0;
return val.replace(/\D/g, "").length;
}
if (count_digits(values.mobile_no) < 10) {
frappe.throw("Mobile number must have at least 10 digits.");
}
frappe.call({
method: "rmax_custom.api.customer.create_customer_with_address",
args: {
Expand Down
122 changes: 35 additions & 87 deletions rmax_custom/public/js/vat_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,104 +15,52 @@ frappe.ui.form.on('Customer', {
}
set_customer_type_filter(frm);
},
validate: async function(frm) {

// validate: async function(frm) {

// let vat = frm.doc.custom_vat_registration_number;

// // ---------------- VAT VALIDATION ----------------
// if (vat) {
// if (vat.length > 15) {
// frappe.throw("VAT cannot exceed 15 digits");
// }

// await frappe.call({
// method: "rmax_custom.api.customer.validate_vat_customer",
// args: {
// vat: vat,
// customer_type: frm.doc.customer_type,
// name: frm.doc.name || null
// }
// });
// }

// if (frm.doc.customer_primary_contact) {

// let r = await frappe.call({
// method: "frappe.client.get",
// args: {
// doctype: "Contact",
// name: frm.doc.customer_primary_contact
// }
// });

// let contact = r.message;

// function count_digits(val) {
// if (!val) return 0;
// return val.replace(/\D/g, "").length;
// }

// (contact.phone_nos || []).forEach(row => {

// if (row.phone && count_digits(row.phone) < 10) {

// if (row.is_primary_mobile) {
// frappe.throw("Mobile number must have at least 10 digits.");
// } else {
// frappe.throw("Phone number must have at least 10 digits.");
// }

// }
let vat = frm.doc.custom_vat_registration_number;
if (vat && vat.length !== 15) {
frappe.throw("VAT must be exactly 15 digits");
}
if (vat) {
await frappe.call({
method: "rmax_custom.api.customer.validate_vat_customer",
args: {
vat: vat,
customer_type: frm.doc.customer_type,
name: frm.doc.name || null
}
});
}
if (frm.doc.customer_primary_contact) {

// });
// }
validate: async function(frm) {
let r = await frappe.call({
method: "frappe.client.get",
args: {
doctype: "Contact",
name: frm.doc.customer_primary_contact
}
});

let vat = frm.doc.custom_vat_registration_number;
if (vat && vat.length !== 15) {
frappe.throw("VAT must be exactly 15 digits");
}
if (vat) {
await frappe.call({
method: "rmax_custom.api.customer.validate_vat_customer",
args: {
vat: vat,
customer_type: frm.doc.customer_type,
name: frm.doc.name || null
}
});
}
if (frm.doc.customer_primary_contact) {
let contact = r.message;

let r = await frappe.call({
method: "frappe.client.get",
args: {
doctype: "Contact",
name: frm.doc.customer_primary_contact
function count_digits(val) {
if (!val) return 0;
return val.replace(/\D/g, "").length;
}
});

let contact = r.message;

function count_digits(val) {
if (!val) return 0;
return val.replace(/\D/g, "").length;
}

for (let row of (contact.phone_nos || [])) {
for (let row of (contact.phone_nos || [])) {

if (row.phone && count_digits(row.phone) < 10) {
if (row.phone && count_digits(row.phone) < 10) {

if (row.is_primary_mobile) {
frappe.throw("Mobile number must have at least 10 digits.");
} else {
frappe.throw("Phone number must have at least 10 digits.");
if (row.is_primary_mobile) {
frappe.throw("Mobile number must have at least 10 digits.");
} else {
frappe.throw("Phone number must have at least 10 digits.");
}
}
}
}
}
},
},
onload: function(frm) {
set_customer_type_filter(frm);
}
Expand Down
Loading