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

  <entity name="PurchaseRequest" lang="java" cacheable="true">
	
    <many-to-one name="company" ref="com.axelor.apps.base.db.Company" title="Company"/>
    <many-to-one name="supplierUser" ref="com.axelor.apps.base.db.Partner" title="Supplier" />
    <string name="description" title="Description" large="true"/>
    <many-to-one name="purchaseOrder" ref="com.axelor.apps.purchase.db.PurchaseOrder" title="Purchase order" />
    <integer name="statusSelect" title="Status" selection="purchase.request.status.select" default="1"/>
  	<many-to-many name="purchaseOrderSet" ref="com.axelor.apps.purchase.db.PurchaseOrder" title="Purchase orders"/>
    <string name="purchaseRequestSeq" title="Ref." namecolumn="true" />
	<one-to-many ref="com.axelor.apps.purchase.db.PurchaseRequestLine" name="purchaseRequestLineList" title="Purchase Request Lines" mappedBy="purchaseRequest"/>
    <many-to-one name="familleProduit" ref="com.axelor.apps.base.db.FamilleProduit" title="famille article" />
	
	<many-to-one name="acceptedByUser" ref="com.axelor.auth.db.User" readonly="true" title="Accepted by"/> 
  	<date name="acceptanceDate" title="Acceptance date" readonly="true"/>
	
	<many-to-one name="validatedByUser" ref="com.axelor.auth.db.User" readonly="true" title="Validated by"/> 
  	<date name="validationDate" title="Validation date" readonly="true"/>
	
	<many-to-one name="approvedByUser" ref="com.axelor.auth.db.User" readonly="true" title="Approved by"/> 
  	<date name="approvalDate" title="approval date" readonly="true"/>
	
	<date name="requestDate" title="request Date" />
	<date name="requestedDelay" title="requested Delay"/>
	
	<many-to-one name="assignedToUser" title="Buyer" ref="com.axelor.auth.db.User"/>
	
	<many-to-one name="printingSettings" ref="com.axelor.apps.base.db.PrintingSettings"/>

	<integer name="purchaseType" title="Purchase Type" selection="purchase.request.project.select"/>

   	<integer name="orderByState"/>

    <unique-constraint columns="purchaseRequestSeq"/>

    <extra-code>
    	<![CDATA[
    		// STATUS
			public static final int STATUS_DRAFT = 1;
			public static final int STATUS_REQUESTED = 2;
			public static final int STATUS_ACCEPTED = 3;
			public static final int STATUS_PURCHASED = 4;
			public static final int STATUS_PARTIAL_DELIVERY = 5;
			public static final int STATUS_RECEIVED = 6;
			public static final int STATUS_REFUSED = 7;
			public static final int STATUS_CANCELED = 8;
		]]>
	</extra-code>

	<track>
		<field name="supplierUser"/>
		<field name="purchaseRequestSeq" />
	</track>
  	
  </entity>
  
</domain-models>
