<?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="BillOfMaterial" lang="java">

	<string name="name" title="Label"/>
  	<many-to-one name="product" ref="com.axelor.apps.base.db.Product" title="Product" required="true"/>
  	<decimal name="qty" title="Qty" precision="20" scale="10"/>
  	<integer name="priority" title="Priority"/>
    <boolean name="defineSubBillOfMaterial" title="Define sub bill of material"/>
    <many-to-one name="unit" ref="com.axelor.apps.base.db.Unit" title="Unit"/>
    <many-to-one name="prodProcess" ref="com.axelor.apps.production.db.ProdProcess" title="Production process"/>
  	<many-to-many name="billOfMaterialSet" ref="com.axelor.apps.production.db.BillOfMaterial" title="BOMs" orderBy="priority"/>
  	<one-to-many name="prodResidualProductList" ref="com.axelor.apps.production.db.ProdResidualProduct" title="Residual products"/>
  	<decimal name="costPrice" title="Cost price" precision="20" scale="10"/>
    <many-to-one name="company" ref="com.axelor.apps.base.db.Company" title="Company"/>
    <boolean name="hasNoManageStock" title="Not manage stock"/>
    <boolean name="personalized" title="Personalized"/>
   	<decimal name="wasteRate" title="Waste rate (%)"/>
    <integer name="statusSelect" title="Status" readonly="true" selection="production.bill.of.material.status.select" default="1"/>
		<many-to-one name="workshopStockLocation" ref="com.axelor.apps.stock.db.StockLocation" title="Workshop"/>

  	<one-to-many name="costSheetList" ref="com.axelor.apps.production.db.CostSheet" title="Cost sheets" mappedBy="billOfMaterial"/>

	<string name="fullName" namecolumn="true" title="Label"/>
	<integer name="versionNumber" title="Version number" default="1"/>
	<many-to-one name="originalBillOfMaterial" ref="com.axelor.apps.production.db.BillOfMaterial" title="Original bill of material" />
	<one-to-many name="bomChildTreeList" ref="TempBomTree" mappedBy="parentBom"/>
	<one-to-many name="bomTreeList" ref="TempBomTree" mappedBy="bom"/>
     	
    <string name="note" large="true"/>

    <extra-code><![CDATA[

    	// STATUS SELECT
    	public static final int STATUS_DRAFT = 1;
    	public static final int STATUS_VALIDATED = 2;
    	public static final int STATUS_APPLICABLE = 3;
    	public static final int STATUS_OBSOLETE = 4;

    ]]></extra-code>

    <track>
    	<field name="name"/>
    	<field name="product"/>
    	<field name="qty"/>
    	<field name="priority"/>
    	<field name="defineSubBillOfMaterial"/>
    	<field name="unit"/>
    	<field name="prodProcess"/>
    	<field name="costPrice"/>
    	<field name="company"/>
    	<field name="hasNoManageStock"/>
    	<field name="personalized"/>
    	<field name="wasteRate"/>
    	<field name="statusSelect"/>
    	<field name="workshopStockLocation"/>
    	<field name="fullName"/>
    	<field name="versionNumber"/>
    	<field name="originalBillOfMaterial"/>
    	<field name="note"/>
    </track>
  </entity>
</domain-models>
