<?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.3.xsd">

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

  <entity name="Opportunity" lang="java">
    
    <string name="name" title="Name" required="true"/>
    <many-to-one name="partner" ref="com.axelor.apps.base.db.Partner" title="Customer"/>
    <many-to-one name="currency" ref="com.axelor.apps.base.db.Currency" title="Currency"/>
   	<date name="expectedCloseDate" title="Expected close date"/>
    <decimal name="amount" title="Amount"/>
    <many-to-one name="opportunityType" ref="com.axelor.apps.crm.db.OpportunityType" title="Type of need"/>
    <decimal name="bestCase" title="Best case"/>
    <decimal name="worstCase" title="Worst case"/>
    <integer name="salesStageSelect" title="Sales stage" selection="crm.opportunity.sales.stage.select"/>
    <decimal name="probability" title="Probability (%)"/>
    <string name="nextStep" title="Next step"/>
    <string name="description" large="true" title="Description"/>
    <string name="customerDescription" large="true" title="Customer Description"/>
   	<many-to-one name="source" ref="com.axelor.apps.base.db.Source" title="Source"/>
   	<many-to-one name="company" ref="com.axelor.apps.base.db.Company" title="Company"/>
   	<integer name="orderByState"/>
   	<string name="memo" large="true"/>
    
    <many-to-one name="lead" ref="com.axelor.apps.crm.db.Lead" title="Lead"/>
    
  	<many-to-one name="user" column="user_id" ref="com.axelor.auth.db.User" title="Assigned to"/>
  	<many-to-one name="team" ref="com.axelor.team.db.Team" title="Team"/>
  	
  	<many-to-one name="lostReason" ref="LostReason" title="Lost reason" />
    <string name="lostReasonStr" title="Lost reason" large="true"/>
	  <many-to-one name="tradingName" ref="com.axelor.apps.base.db.TradingName"/>
	  <string name="opportunitySeq" title="Reference" readonly="true" unique="true"/>

	<extra-code>
		<![CDATA[
		// Stage SELECT
			public static final int SALES_STAGE_NEW = 1;
			public static final int SALES_STAGE_QUALIFICATION = 2;
			public static final int SALES_STAGE_PROPOSITION = 3;
			public static final int SALES_STAGE_NEGOTIATION = 4;
			public static final int SALES_STAGE_CLOSED_WON = 5;
			public static final int SALES_STAGE_CLOSED_LOST = 6;
		]]>
	</extra-code>


	<track>
	   <field name="name"/>
	   <message if="true" on="CREATE">Opportunity created</message>
	   <message if="salesStageSelect == 5" fields="salesStageSelect" tag="success">Opportunity won</message>
	   <message if="salesStageSelect == 6" fields="salesStageSelect" tag="warning">Opportunity lost</message>
	 </track>
	 
  </entity>

</domain-models>
