<?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="stock" package="com.axelor.apps.stock.db"/>

  <entity name="StockMove" lang="java">

	<string name="stockMoveSeq" namecolumn="true" title="Ref." readonly="true"/>
    <string name="name" title="Name"/>
    <many-to-one name="fromStockLocation" ref="com.axelor.apps.stock.db.StockLocation" required="true" title="From stock location"/>
    <many-to-one name="toStockLocation" ref="com.axelor.apps.stock.db.StockLocation" required="true" title="To stock location"/>
    
    <date name="estimatedDate" title="Estimated date"/>
    <date name="realDate" title="Move date" readonly="true"/>

	<date name="supplierShipmentDate" title="Supplier Shipment Date"/>
	<string name="supplierShipmentRef" title="Supplier Shipment Ref"/>

    <integer name="statusSelect" title="Status" selection="stock.move.status.select" required="true" readonly="true" default="1"/>
    <integer name="typeSelect" title="Type Status" required="true" selection="stock.move.type.select"/>
    <integer name="availableStatusSelect" title="Available status" transient="true" selection="stock.stock.move.available.status.select"/>
    
    <many-to-one name="fromAddress" ref="com.axelor.apps.base.db.Address" title="From address"/>
    <many-to-one name="toAddress" ref="com.axelor.apps.base.db.Address" title="To address"/>

    <string name="fromAddressStr" title="From address" large="true" multiline="true"/>
    <string name="toAddressStr" title="To address" large="true" multiline="true"/>

    <many-to-one name="company" ref="com.axelor.apps.base.db.Company" title="Company" required="true"/>
    <many-to-one name="partner" ref="com.axelor.apps.base.db.Partner" title="Partner"/>
  	
    <many-to-one name="payerPartner" ref="com.axelor.apps.base.db.Partner" title="Payer Supplier"/>
    <many-to-one name="deliveryPartner" ref="com.axelor.apps.base.db.Partner" title="Delivery Supplier"/>


    <one-to-many name="stockMoveLineList" ref="com.axelor.apps.stock.db.StockMoveLine" mappedBy="stockMove" orderBy="sequence" title="Stock move content"/>
    <one-to-many name="plannedStockMoveLineList" ref="com.axelor.apps.stock.db.StockMoveLine" mappedBy="plannedStockMove" orderBy="sequence"/>

    <boolean name="isWithReturnSurplus" title="Return surplus"/>
    <boolean name="isWithBackorder" title="Manage backorder" default="false"/>
    
    <string name="trackingNumber" title="Tracking Number"/>
    <integer name="numOfPackages" title="Number Of Packages"/>
    <integer name="numOfPalettes" title="Number Of Palettes"/>
    <decimal name="grossMass" title="Gross Mass"/>
    
    <decimal name="exTaxTotal" title="Total W.T." precision="20" scale="2"/>
    
    <many-to-one name="shipmentMode" ref="com.axelor.apps.stock.db.ShipmentMode"/>
    <many-to-one name="freightCarrierMode" ref="com.axelor.apps.stock.db.FreightCarrierMode"/>
   
    <many-to-one name="carrierPartner" ref="com.axelor.apps.base.db.Partner" title="Carrier" />
   	<many-to-one name="forwarderPartner" ref="com.axelor.apps.base.db.Partner" title="Forwarder" />
	<many-to-one name="incoterm" ref="com.axelor.apps.stock.db.Incoterm" />
    
    <integer name="conformitySelect" title="Conformity" selection="stock.move.line.conformity.select"/>

    <boolean name="fullySpreadOverLogisticalFormsFlag" default="false" title="Fully spread over logistical forms" />

    <many-to-one name="cancelReason" title="Cancel reason" ref="com.axelor.apps.base.db.CancelReason"/>
    <boolean name="plannedStockMoveAutomaticMail" title="Send email when planning stock move" default="false"/>
    <many-to-one name="plannedStockMoveMessageTemplate" title="Message template" ref="com.axelor.apps.message.db.Template"/>
    <boolean name="realStockMoveAutomaticMail" title="Send email on stock move realization" default="false"/>
    <many-to-one name="realStockMoveMessageTemplate" title="Message template" ref="com.axelor.apps.message.db.Template"/>

    <many-to-one name="tradingName" ref="com.axelor.apps.base.db.TradingName"/>
    <many-to-one name="printingSettings" ref="com.axelor.apps.base.db.PrintingSettings"/>

    <boolean name="isIspmRequired" title="Is ISPM15 required"/>
    <boolean name="isReversion" readonly="true" />

    <boolean name="isNeedingConformityCertificate" title="Certificate of conformity"/>
    <boolean name="isConformityCertifSigned" title="Is certificate of conformity signed"/>
    <many-to-one name="electronicSignature" ref="com.axelor.meta.db.MetaFile" title="Electronic signature"/>
    <many-to-one name="signatoryUser" ref="com.axelor.auth.db.User" title="Signatory user"/>
    <long name="backorderId" title="Backorder Id"/>
    <many-to-one name="stockMoveOrigin" ref="com.axelor.apps.stock.db.StockMove" title="Stock Move Origin"/>

    <string name="originTypeSelect" title="Origin Type" selection="stockmove.origin.select"/>
    <long name="originId" title="Origin Id" />
    <string name="origin" readonly="true" title="Origin"/>
	<boolean name="availabilityRequest" title="Availability request"/>

    <many-to-one name="stockCorrectionReason" ref="com.axelor.apps.stock.db.StockCorrectionReason" title="Correction Reason"/>

	<boolean name="pickingIsEdited" title="Picking order is edited"/>
	<date name="pickingEditDate" title="Picking order edit date"/>
    <enum name="modeOfTransport" ref="com.axelor.apps.stock.db.ModeOfTransport"/>
    
    <string name="note" title="Notes" large="true"/>
  
    <boolean name="filterOnAvailableProducts" title="Filter on available products" default="true" transient="true"/>

    <many-to-one name="reversionOriginStockMove" title="Origin stock move" ref="com.axelor.apps.stock.db.StockMove"/>
    
    <string name="pickingOrderComments" title="Comment to display on picking order" large="true"/>

    <decimal name="stamp" title="stamp" scale="2" precision="20" />
    <decimal name="fixTax" title="fix Tax" scale="2" precision="20" />

    <unique-constraint columns="stockMoveSeq,company"/>
    
    <extra-code><![CDATA[
	
	   	// STATUS SELECT
		public static final int STATUS_DRAFT = 1;
		public static final int STATUS_PLANNED = 2;
		public static final int STATUS_REALIZED = 3;
		public static final int STATUS_CANCELED = 4;
		
		// AVAILABLE STATUS SELECT
		public static final int STATUS_AVAILABLE = 1;
		public static final int STATUS_PARTIALLY_AVAILABLE = 2;
		public static final int STATUS_UNAVAILABLE = 3;

		// USER TYPE
		public static final String USER_TYPE_SENDER = "Sender";
		public static final String USER_TYPE_SALESPERSON = "Salesperson";
		
		// TYPE SELECT
		public static final int TYPE_INTERNAL = 1;
		public static final int TYPE_OUTGOING = 2;
		public static final int TYPE_INCOMING = 3;
    // client return 
    public static final int TYPE_INCOMING_CLIENT = 4;
    // client delivery
    public static final int TYPE_OUTGOING_CLIENT = 5;
    // internal delivery
    public static final int TYPE_INTERNAL_OUTGOING_CLIENT = 6;
    // supplier return
    public static final int TYPE_SUPPLIER_OUTGOING_CLIENT = 7;

		// CONFORMITY SELECT
		public static final int CONFORMITY_NONE = 1;
		public static final int CONFORMITY_COMPLIANT = 2;
		public static final int CONFORMITY_NON_COMPLIANT = 3;
	
		public static final String ORIGIN_INVENTORY = "com.axelor.apps.stock.db.Inventory";
		public static final String ORIGIN_STOCK_CORRECTION = "com.axelor.apps.stock.db.StockCorrection";
	]]></extra-code>
	
	<track>
      <field name="stockMoveSeq" />
      <field name="typeSelect" />
      <field name="partner" />
      <field name="statusSelect" />
      <field name="fromStockLocation" />
      <field name="toStockLocation" />
      <field name="estimatedDate" />
      <field name="cancelReason" />
      <field name="realDate" if="statusSelect == 3" />
      <field name="pickingIsEdited" />
      <field name="availabilityRequest" />
      <message if="true" on="CREATE">Move created</message>
      <message if="statusSelect == 1" tag="important">Draft move</message>
      <message if="statusSelect == 2" tag="info">Planned move</message>
      <message if="statusSelect == 3" tag="success">Move realized</message>
      <message if="statusSelect == 4" tag="warning">Move canceled</message>
    </track>

  </entity>

  <enum name="ModeOfTransport" numeric="true">
    <item name="TRANSPORT_BY_SEA" value="1"/>
    <item name="TRANSPORT_BY_RAIL" value="2"/>
    <item name="TRANSPORT_BY_ROAD" value="3"/>
    <item name="TRANSPORT_BY_AIR" value="4"/>
    <item name="CONSIGNMENTS_BY_POST" value="5"/>
    <item name="FIXED_TRANSPORT_INSTALLATIONS" value="7"/>
    <item name="TRANSPORT_BY_INLAND_WATERWAY" value="8"/>
    <item name="OWN_PROPULSION" value="9"/>
  </enum>

</domain-models>
