<?xml version="1.0" encoding="UTF-8"?>
<domain-models xmlns="http://axelor.com/xml/ns/domain-models"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://axelor.com/xml/ns/domain-models http://axelor.com/xml/ns/domain-models/domain-models_5.2.xsd">

  <module name="crm" package="com.axelor.apps.crm.db"/>

  <entity name="Lead" lang="java">
  
 	<string name="titleSelect" title="Title" selection="partner.title.type.select"/>
    <string name="name" required="true" title="Last name"/>
    <string name="firstName" title="First name"/>
    <string name="enterpriseName" title="Enterprise"/>
    <string name="officeName" title="Office name"/>
    <many-to-one name="jobTitleFunction" title="Job Title" ref="com.axelor.apps.base.db.Function"/>
    <string name="mobilePhone" title="Mobile N°"/>
    <string name="fixedPhone" title="Fixed Phone"/>
  	<string name="department" title="Dep./Div."/>
  	<string name="fax" title="Fax"/>
  	<string name="webSite" title="Website"/>
  	
<!--   Primary address group -->
	<string name="primaryAddress" title="Address"/>
	<string name="primaryCity" title="City"/>
	<string name="primaryState" title="Region"/>
	<string name="primaryPostalCode" title="Postal code"/>
  	<many-to-one name="primaryCountry" ref="com.axelor.apps.base.db.Country" title="Country"/>
  
    <one-to-one name="emailAddress" ref="com.axelor.apps.message.db.EmailAddress" title="Email"/>
	<binary name="picture" title="Picture" />
	
	<string name="description" title="Description" large="true"/>
	<date name="contactDate" title="Contact date" />
	
	<integer name="statusSelect" title="Status" selection="crm.lead.status.select" default="1" required="true" massUpdate="true"/>
	<boolean name="isRecycled" title="Recycled"/>
	<many-to-one name="source" ref="com.axelor.apps.base.db.Source" title="Source"/>
  	<string name="statusDescription" title="Status description" large="true"/>
    <decimal name="estimatedBudget" title="Estimated budget"/>
 	<string name="sourceDescription" title="Source description" large="true"/>
    <string name="referredBy" title="Referred by"/>
    <boolean name="isDoNotCall" title="Rejection of calls"/>
    <boolean name="isDoNotSendEmail" title="Rejection of e-mails"/>
    
    <many-to-one name="partner" ref="com.axelor.apps.base.db.Partner" title="Contact" readonly="true"/>
    
    
    <many-to-one name="user" column="user_id" ref="com.axelor.auth.db.User" title="Assigned to" massUpdate="true"/>
  	<many-to-one name="team" ref="com.axelor.team.db.Team" title="Team"  massUpdate="true" />
  	<many-to-one name="industrySector" title="Industry sector" ref="com.axelor.apps.base.db.IndustrySector" massUpdate="true"/>

  	<one-to-many name="eventList" ref="com.axelor.apps.crm.db.Event" title="Events" mappedBy="lead"/>
  	<one-to-many name="opportunitiesList" ref="com.axelor.apps.crm.db.Opportunity" title="Opportunities" mappedBy="lead"/>
  	<many-to-one name="lostReason" ref="LostReason" title="Lost reason" />

    <string name="lostReasonStr" title="Lost reason" large="true"/>
    <string name="fullName" title="Contact name" namecolumn="true" />

    <extra-code>
    <![CDATA[
    	public static final int LEAD_STATUS_NEW = 1;
    	public static final int LEAD_STATUS_ASSIGNED = 2;
    	public static final int LEAD_STATUS_IN_PROCESS = 3;
    	public static final int LEAD_STATUS_CONVERTED = 4;
    	public static final int LEAD_STATUS_LOST = 5;
    	
    	public static final int CONVERT_LEAD_CREATE_PARTNER = 1;
    	public static final int CONVERT_LEAD_SELECT_PARTNER = 2;
    	public static final int CONVERT_LEAD_CREATE_CONTACT = 1;
    	public static final int CONVERT_LEAD_SELECT_CONTACT = 2;
    	
    ]]>
    </extra-code>

    <track>
      <field name="name" />
      <field name="statusSelect" on="UPDATE"/>
      <message if="true" on="CREATE">Lead created</message>
      <message if="statusSelect == 2" tag="important">Lead Assigned</message>
      <message if="statusSelect == 5" tag="success">Lead Converted</message>
    </track>
    
  </entity>

</domain-models>
