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

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

  	<many-to-one name="productionOrder" ref="com.axelor.apps.production.db.ProductionOrder" title="Production order"/>
  	
  	<one-to-many name="operationOrderList" ref="com.axelor.apps.production.db.OperationOrder" mappedBy="manufOrder" title="Operation orders" orderBy="priority"/>
  
  	<decimal name="qty" title="Qty" initParam="true"/>
  
  	<many-to-one name="company" ref="com.axelor.apps.base.db.Company" title="Company" initParam="true"/>
  	<many-to-one name="clientPartner" ref="com.axelor.apps.base.db.Partner" title="Customer" />
	<many-to-one name="saleOrder" ref="com.axelor.apps.sale.db.SaleOrder" title="Sale order" />

    <string name="manufOrderSeq" title="MO" namecolumn="true" initParam="true"/>
    <integer name="prioritySelect" title="Priority" selection="production.order.priority.select" default="2" initParam="true"/><boolean name="isPermanent"/> <!-- Permanent manuf orders are used to log time and have a planned quantity set to 0 -->
    
    
    <one-to-many name="toConsumeProdProductList" ref="com.axelor.apps.production.db.ProdProduct" mappedBy="toConsumeManufOrder" title="Products to consume"/>
  	<one-to-many name="consumedStockMoveLineList" ref="com.axelor.apps.stock.db.StockMoveLine" mappedBy="consumedManufOrder" title="Consumed products" orphanRemoval="false"/>
  	<one-to-many name="diffConsumeProdProductList" ref="com.axelor.apps.production.db.ProdProduct" mappedBy="diffConsumeManufOrder" title="Difference"/>
  
  
  	<one-to-many name="toProduceProdProductList" ref="com.axelor.apps.production.db.ProdProduct" mappedBy="toProduceManufOrder" title="Products to produce"/>
  	<one-to-many name="producedStockMoveLineList" ref="com.axelor.apps.stock.db.StockMoveLine" mappedBy="producedManufOrder" title="Produced products" orphanRemoval="false"/>
  	<one-to-many name="wasteProdProductList" ref="com.axelor.apps.production.db.ProdProduct" mappedBy="wasteManufOrder" title="Waste"/>
    
    
    <boolean name="isConsProOnOperation" title="Manage consumed products on operations" initParam="true"/>
    
    <many-to-one name="unit" ref="com.axelor.apps.base.db.Unit" title="Unit"/>
    <many-to-one name="billOfMaterial" ref="com.axelor.apps.production.db.BillOfMaterial" title="BoM" initParam="true"/>
    <many-to-one name="product" ref="com.axelor.apps.base.db.Product" title="Product" initParam="true"/>
    <one-to-many name="costSheetList" ref="com.axelor.apps.production.db.CostSheet" title="Cost sheet" mappedBy="manufOrder"/>
    <decimal name="costPrice" title="Cost price" precision="20" scale="10"/>

<!--     Champ pointé ? -->
    <many-to-one name="prodProcess" ref="com.axelor.apps.production.db.ProdProcess" title="Production process" initParam="true" required="true"/> 
  
    <datetime name="plannedStartDateT" title="Planned start date" initParam="true"/>
  	<datetime name="plannedEndDateT" title="Planned end date" initParam="true"/>

    <many-to-one name="workshopStockLocation" ref="com.axelor.apps.stock.db.StockLocation" title="Workshop"/>

 	<datetime name="realStartDateT" title="Real start date"/>
  	<datetime name="realEndDateT" title="Real end date"/>
  	<decimal name="endTimeDifference" title="Time difference (Minutes)"/>
    
    <one-to-many name="inStockMoveList" ref="com.axelor.apps.stock.db.StockMove" title="Stock moves in" mappedBy="inManufOrder"/>
    <one-to-many name="outStockMoveList" ref="com.axelor.apps.stock.db.StockMove" title="Stock moves out" mappedBy="outManufOrder"/>
    
    <many-to-one name="wasteStockMove" ref="com.axelor.apps.stock.db.StockMove" title="Waste stock move"/>
    
    <string name="wasteProdDescription" title="Waste description" large="true"/>
    
    <integer name="statusSelect" title="Status" selection="production.manuf.order.status.select" initParam="true"/>
    
    <string name="note" large="true"/>
    <many-to-one name="cancelReason" title="Cancel reason" ref="com.axelor.apps.base.db.CancelReason"/>
    <string name="cancelReasonStr" title="Cancel Reason" large="true"/>
    
    <unique-constraint columns="manufOrderSeq,company"/>

	<extra-code><![CDATA[
		// STATUS SELECT
		public static final int STATUS_DRAFT = 1;
		public static final int STATUS_CANCELED = 2;
		public static final int STATUS_PLANNED = 3;
		public static final int STATUS_IN_PROGRESS = 4;
		public static final int STATUS_STANDBY = 5;
		public static final int STATUS_FINISHED = 6;
	]]></extra-code>
    
    <track>
	  <field name="qty" />
	  <field name="prioritySelect" />
	  <field name="plannedStartDateT" />
	  <field name="plannedEndDateT" />
	  <field name="clientPartner" />
	  <field name="saleOrder" />
	  <field name="statusSelect" />
	  <field name="cancelReasonStr"/>
	</track>
    
  </entity>
</domain-models>