[Fixes] Address and Contact fixes
This commit is contained in:
parent
8271b4c564
commit
83f4780f74
@ -61,14 +61,6 @@ class Supplier(TransactionBase):
|
||||
validate_party_accounts(self)
|
||||
self.status = get_party_status(self)
|
||||
|
||||
def get_contacts(self,nm):
|
||||
if nm:
|
||||
contact_details =frappe.db.convert_to_lists(frappe.db.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = %s", nm))
|
||||
|
||||
return contact_details
|
||||
else:
|
||||
return ''
|
||||
|
||||
def on_trash(self):
|
||||
delete_contact_and_address('Supplier', self.name)
|
||||
|
||||
|
@ -127,7 +127,7 @@ def _make_customer(source_name, target_doc=None, ignore_permissions=False):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_opportunity(source_name, target_doc=None):
|
||||
target_doc = get_mapped_doc("Lead", source_name,
|
||||
target_doc = get_mapped_doc("Lead", source_name,
|
||||
{"Lead": {
|
||||
"doctype": "Opportunity",
|
||||
"field_map": {
|
||||
|
@ -106,30 +106,6 @@ class Opportunity(TransactionBase):
|
||||
lead_name, company_name = frappe.db.get_value("Lead", self.lead, ["lead_name", "company_name"])
|
||||
self.customer_name = company_name or lead_name
|
||||
|
||||
def get_cust_address(self,name):
|
||||
details = frappe.db.sql("""select customer_name, address, territory, customer_group
|
||||
from `tabCustomer` where name = %s and docstatus != 2""", (name), as_dict = 1)
|
||||
if details:
|
||||
ret = {
|
||||
'customer_name': details and details[0]['customer_name'] or '',
|
||||
'address' : details and details[0]['address'] or '',
|
||||
'territory' : details and details[0]['territory'] or '',
|
||||
'customer_group' : details and details[0]['customer_group'] or ''
|
||||
}
|
||||
# ********** get primary contact details (this is done separately coz. , in case there is no primary contact thn it would not be able to fetch customer details in case of join query)
|
||||
|
||||
contact_det = frappe.db.sql("""select contact_name, contact_no, email_id
|
||||
from `tabContact` where customer = %s and is_customer = 1
|
||||
and is_primary_contact = 'Yes' and docstatus != 2""", name, as_dict = 1)
|
||||
|
||||
ret['contact_person'] = contact_det and contact_det[0]['contact_name'] or ''
|
||||
ret['contact_no'] = contact_det and contact_det[0]['contact_no'] or ''
|
||||
ret['email_id'] = contact_det and contact_det[0]['email_id'] or ''
|
||||
|
||||
return ret
|
||||
else:
|
||||
frappe.throw(_("Customer {0} does not exist").format(name), frappe.DoesNotExistError)
|
||||
|
||||
def on_update(self):
|
||||
self.add_calendar_event()
|
||||
|
||||
|
@ -95,9 +95,14 @@ class Customer(TransactionBase):
|
||||
def create_lead_address_contact(self):
|
||||
if self.lead_name:
|
||||
# assign lead address to customer (if already not set)
|
||||
address_name = frappe.get_value('Dynamic Link', dict(parenttype='Address', link_doctype='Lead', link_name=self.name))
|
||||
if address_name:
|
||||
address = frappe.get_doc('Address', address_name)
|
||||
address_names = frappe.db.get_values('Dynamic Link', dict(
|
||||
parenttype='Address',
|
||||
link_doctype='Lead',
|
||||
link_name=self.lead_name
|
||||
), 'parent as name', as_dict=True)
|
||||
|
||||
for address_name in address_names:
|
||||
address = frappe.get_doc('Address', address_name.get('name'))
|
||||
if not address.has_link('Customer', self.name):
|
||||
address.append('links', dict(link_doctype='Customer', link_name=self.name))
|
||||
address.save()
|
||||
@ -105,17 +110,17 @@ class Customer(TransactionBase):
|
||||
lead = frappe.db.get_value("Lead", self.lead_name, ["lead_name", "email_id", "phone", "mobile_no"], as_dict=True)
|
||||
|
||||
# create contact from lead
|
||||
c = frappe.new_doc('Contact')
|
||||
c.first_name = lead.lead_name
|
||||
c.email_id = lead.email_id
|
||||
c.phone = lead.phone
|
||||
c.mobile_no = lead.mobile_no
|
||||
c.is_primary_contact = 1
|
||||
c.append('links', dict(link_doctype='Customer', link_name=self.name))
|
||||
c.flags.ignore_permissions = self.flags.ignore_permissions
|
||||
c.autoname()
|
||||
if not frappe.db.exists("Contact", c.name):
|
||||
c.insert()
|
||||
contact = frappe.new_doc('Contact')
|
||||
contact.first_name = lead.lead_name
|
||||
contact.email_id = lead.email_id
|
||||
contact.phone = lead.phone
|
||||
contact.mobile_no = lead.mobile_no
|
||||
contact.is_primary_contact = 1
|
||||
contact.append('links', dict(link_doctype='Customer', link_name=self.name))
|
||||
contact.flags.ignore_permissions = self.flags.ignore_permissions
|
||||
contact.autoname()
|
||||
if not frappe.db.exists("Contact", contact.name):
|
||||
contact.insert()
|
||||
|
||||
def validate_name_with_customer_group(self):
|
||||
if frappe.db.exists("Customer Group", self.name):
|
||||
|
@ -12,9 +12,9 @@ def get_funnel_data(from_date, to_date):
|
||||
where (date(`modified`) between %s and %s)
|
||||
and status != "Do Not Contact" """, (from_date, to_date))[0][0]
|
||||
|
||||
active_leads += frappe.db.sql("""select count(distinct customer) from `tabContact`
|
||||
where (date(`modified`) between %s and %s)
|
||||
and status != "Passive" """, (from_date, to_date))[0][0]
|
||||
active_leads += frappe.db.sql("""select count(distinct contact.name) from `tabContact` contact
|
||||
left join `tabDynamic Link` dl on (dl.parent=contact.name) where dl.link_doctype='Customer'
|
||||
and (date(contact.modified) between %s and %s) and status != "Passive" """, (from_date, to_date))[0][0]
|
||||
|
||||
opportunities = frappe.db.sql("""select count(*) from `tabOpportunity`
|
||||
where (date(`creation`) between %s and %s)
|
||||
|
@ -28,15 +28,6 @@ class SalesPartner(WebsiteGenerator):
|
||||
if self.partner_website and not self.partner_website.startswith("http"):
|
||||
self.partner_website = "http://" + self.partner_website
|
||||
|
||||
def get_contacts(self, nm):
|
||||
if nm:
|
||||
return frappe.db.convert_to_lists(frappe.db.sql("""
|
||||
select name, CONCAT(IFNULL(first_name,''),
|
||||
' ',IFNULL(last_name,'')),contact_no,email_id
|
||||
from `tabContact` where sales_partner = %s""", nm))
|
||||
else:
|
||||
return ''
|
||||
|
||||
def get_context(self, context):
|
||||
address = frappe.db.get_value("Address",
|
||||
{"sales_partner": self.name, "is_primary_address": 1},
|
||||
|
Loading…
Reference in New Issue
Block a user