Merge pull request #20826 from saurabh6790/lead-address-fixes

fix: if mandatory fields are missing do not create address against lead
This commit is contained in:
rohitwaghchaure 2020-03-31 17:38:06 +05:30 committed by GitHub
commit a19aa0431a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -135,10 +135,17 @@ class Lead(SellingController):
# do not create an address if no fields are available,
# skipping country since the system auto-sets it from system defaults
if not any([self.get(field) for field in address_fields if field != "country"]):
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 = frappe.new_doc("Address")
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.insert()