fix: displayings mandatory address field in Lead form

This commit is contained in:
Anupam 2020-10-13 15:35:10 +05:30
parent ed779a416c
commit 3245eaaeb0
2 changed files with 10 additions and 14 deletions

View File

@ -241,6 +241,7 @@
}, },
{ {
"depends_on": "eval: doc.__islocal", "depends_on": "eval: doc.__islocal",
"description": "Home, Work, etc.",
"fieldname": "address_title", "fieldname": "address_title",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Address Title" "label": "Address Title"
@ -249,7 +250,8 @@
"depends_on": "eval: doc.__islocal", "depends_on": "eval: doc.__islocal",
"fieldname": "address_line1", "fieldname": "address_line1",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Address Line 1" "label": "Address Line 1",
"mandatory_depends_on": "eval: doc.address_title && doc.address_type"
}, },
{ {
"depends_on": "eval: doc.__islocal", "depends_on": "eval: doc.__islocal",
@ -261,7 +263,8 @@
"depends_on": "eval: doc.__islocal", "depends_on": "eval: doc.__islocal",
"fieldname": "city", "fieldname": "city",
"fieldtype": "Data", "fieldtype": "Data",
"label": "City/Town" "label": "City/Town",
"mandatory_depends_on": "eval: doc.address_title && doc.address_type"
}, },
{ {
"depends_on": "eval: doc.__islocal", "depends_on": "eval: doc.__islocal",
@ -280,6 +283,7 @@
"fieldname": "country", "fieldname": "country",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Country", "label": "Country",
"mandatory_depends_on": "eval: doc.address_title && doc.address_type",
"options": "Country" "options": "Country"
}, },
{ {
@ -449,7 +453,7 @@
"idx": 5, "idx": 5,
"image_field": "image", "image_field": "image",
"links": [], "links": [],
"modified": "2020-06-18 14:39:41.835416", "modified": "2020-10-13 15:24:00.094811",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "CRM", "module": "CRM",
"name": "Lead", "name": "Lead",

View File

@ -22,7 +22,8 @@ class Lead(SellingController):
load_address_and_contact(self) load_address_and_contact(self)
def before_insert(self): def before_insert(self):
self.address_doc = self.create_address() if self.address_type and self.address_title and self.address_line1 and self.city and self.country:
self.address_doc = self.create_address()
self.contact_doc = self.create_contact() self.contact_doc = self.create_contact()
def after_insert(self): def after_insert(self):
@ -133,15 +134,6 @@ class Lead(SellingController):
# skipping country since the system auto-sets it from system defaults # skipping country since the system auto-sets it from system defaults
address = frappe.new_doc("Address") address = frappe.new_doc("Address")
mandatory_fields = [ df.fieldname for df in address.meta.fields if df.reqd ]
if not all([self.get(field) for field in mandatory_fields]):
frappe.msgprint(_('Missing mandatory fields in address. \
{0} to create address' ).format("<a href='desk#Form/Address/New Address 1' \
> Click here </a>"),
alert=True, indicator='yellow')
return
address.update({addr_field: self.get(addr_field) for addr_field in address_fields}) address.update({addr_field: self.get(addr_field) for addr_field in address_fields})
address.update({info_field: self.get(info_field) for info_field in info_fields}) address.update({info_field: self.get(info_field) for info_field in info_fields})
address.insert() address.insert()
@ -190,7 +182,7 @@ class Lead(SellingController):
def update_links(self): def update_links(self):
# update address links # update address links
if self.address_doc: if hasattr(self, 'address_doc'):
self.address_doc.append("links", { self.address_doc.append("links", {
"link_doctype": "Lead", "link_doctype": "Lead",
"link_name": self.name, "link_name": self.name,