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

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

		<string name="name" title="Name" required="true" initParam="true"
			translatable="true" />
		<string name="serialNumber" title="Serial Nbr"/>
		<string name="code" title="Code" initParam="true" unique="true"/>

		<string name="description" large="true" title="Description"
			initParam="true" translatable="true" />
		<string name="internalDescription" large="true" title="Internal description"
			initParam="true" />
		<many-to-one name="picture" ref="com.axelor.meta.db.MetaFile"
			initParam="true" />
			
		<many-to-one name="familleProduit" ref="FamilleProduit"
			title="Product category"  massUpdate="true" /><!--sophal-->
		<many-to-one name="sousFamilleProduit" ref="FamilleProduit"
			title="Product category"  massUpdate="true" /><!--sophal-->
		<many-to-one name="sousSousFamilleProduit" ref="FamilleProduit"
			title="Product category"  massUpdate="true" /><!--sophal-->
			
		<many-to-one name="productCategory" ref="ProductCategory"
			title="Product category" initParam="true" massUpdate="true" />
		
		<string name="unitCodeSelect" title="Unit Code"
			selection="product.unit.code.select"  massUpdate="true"/><!--sophal-->
		<boolean name="codeCreated" title="code Created By Systeme" default="true"/><!--sophal-->
		<many-to-one name="productFamily" ref="ProductFamily"
			title="Accounting family" initParam="true" massUpdate="true"/>
		<many-to-one name="unit" ref="Unit" title="Unit"
			initParam="true" massUpdate="true" />

		<integer name="saleSupplySelect" title="Sale supply default method on sale order"
			selection="product.sale.supply.select" initParam="true" massUpdate="true"/>

		<string name="productTypeSelect" title="Type" required="true"
			selection="product.product.type.select" initParam="true" massUpdate="true"/>
		<string name="procurementMethodSelect" title="Procurement method"
			selection="product.procurement.method.select" initParam="true" />
		<boolean name="isPrototype" title="Prototype" />
		<boolean name="isUnrenewed" title="Unrenewed"/>
		<integer name="productSubTypeSelect" title="Product Subtype"
			selection="product.sub.type.product.select" />
		<integer name="inventoryTypeSelect" title="Inventory type"
			selection="product.inventory.type.select" />

		<decimal name="salePrice" title="Sale price W.T." precision="20"
			scale="10" massUpdate="true" />
		<many-to-one name="saleCurrency" ref="com.axelor.apps.base.db.Currency"
			title="Sale currency" initParam="true" />
		<decimal name="purchasePrice" title="Purchase price W.T."
			precision="20" scale="10" massUpdate="true" />
		<many-to-one name="purchaseCurrency" ref="com.axelor.apps.base.db.Currency"
			title="Purchase / Cost currency" initParam="true" />
		<boolean name="autoUpdateSalePrice" default="false"
			title="Update sale price from cost price" />

		<decimal name="costPrice" title="Cost price" precision="20"
			scale="10" massUpdate="true" />

		<decimal name="managPriceCoef" title="Management coef." />
		<decimal name="shippingCoef" title="Shipping Coef." />
		<boolean name="defShipCoefByPartner" title="Define the shipping coef by partner" />

		<date name="startDate" title="Product launch Date" initParam="true" />
		<date name="endDate" title="Product pulled off market Date"
			initParam="true" />

		<boolean name="hasWarranty" title="Warranty" />
		<boolean name="isPerishable" title="Perishable" />
		<integer name="warrantyNbrOfMonths" title="Warranty length (in months)" />
		<integer name="perishableNbrOfMonths" title="Time before expiry (in months)" />
		<boolean name="checkExpirationDateAtStockMoveRealization" />

		<many-to-one name="productVariantConfig"
			ref="com.axelor.apps.base.db.ProductVariantConfig" />
		<many-to-one name="productVariant" ref="com.axelor.apps.base.db.ProductVariant" />
		<many-to-one name="parentProduct" ref="com.axelor.apps.base.db.Product"
			title="Parent product" />
		<boolean name="isModel" title="Is model" />
		<boolean name="manageVariantPrice" default="false"
			title="Manage prices for product variants" />

		<many-to-one name="defaultSupplierPartner" ref="com.axelor.apps.base.db.Partner"
			title="Default supplier" />

		<one-to-many name="accountManagementList"
			ref="com.axelor.apps.account.db.AccountManagement" mappedBy="product"
			title="Accounts configuration" />

		<integer name="versionSelect" title="Version"
			selection="base.product.version.select" />

		<boolean name="sellable" title="Sellable" default="true" />
		<boolean name="purchasable" title="Purchasable" default="true" />
		<boolean name="inAti" title="In ATI" />

		<integer name="costTypeSelect" title="Cost type"
			selection="base.product.cost.type.select" default="1" />

		<integer name="supplierDeliveryTime" title="Supplier delivery time (days)" />

		<many-to-one name="barCode" title="Barcode"
			ref="com.axelor.meta.db.MetaFile" />
		<many-to-one name="barcodeTypeConfig" title="Barcode Type" ref="com.axelor.apps.base.db.BarcodeTypeConfig"/>
		<string name="fullName" title="Full name" namecolumn="true" translatable="true" />


		<many-to-one name="massUnit" ref="com.axelor.apps.base.db.Unit"
			title="Unit of mass" />
		<decimal name="grossMass" title="Gross mass" precision="20" scale="3" />
		<decimal name="netMass" title="Net mass" precision="20" scale="3" />

		<many-to-one name="lengthUnit" ref="com.axelor.apps.base.db.Unit"
			title="Unit of length" />
		<decimal name="length" title="Length" default="0" />
		<decimal name="width" title="Width" default="0" />
		<decimal name="height" title="Height" default="0" />
		<decimal name="diameter" title="Diameter" />
		<decimal name="articleVolume" title="Article volume" />
		<decimal name="economicManufOrderQty" title="Economic manuf. qty"/>
		
		<boolean name="isShippingCostsProduct" title="Is shipping costs product"/>

		<one-to-many name="saleProductMultipleQtyList"
			ref="com.axelor.apps.base.db.ProductMultipleQty" mappedBy="saleProduct"
			title="Multiple quantities" orderBy="multipleQty"/>
		
		<boolean name="allowToForceSaleQty" title="Allow to force sales quantities"/>
		
		<one-to-many name="purchaseProductMultipleQtyList"
			ref="com.axelor.apps.base.db.ProductMultipleQty" mappedBy="purchaseProduct"
			title="Multiple quantities" orderBy="multipleQty" />
			
		<boolean name="allowToForcePurchaseQty" title="Allow to force purchases quantities"/>
		
		<decimal name="ppa" title="PPA" />
		<decimal name="shp" title="SHP" />
		<decimal name="pvg" title="PVG" />
		<decimal name="stklim" title="Stklim" />
		<decimal name="ug" title="UG" />

		<extra-code>
	   		<![CDATA[
				// PRODUCT TYPE SELECT
				public static final String PRODUCT_TYPE_SERVICE = "service";
				public static final String PRODUCT_TYPE_STORABLE = "storable";
				public static final String PRODUCT_TYPE_PACK = "pack";
				
				// SALE SUPPLY SELECT
				public static final int SALE_SUPPLY_FROM_STOCK = 1;
				public static final int SALE_SUPPLY_PURCHASE = 2;
				public static final int SALE_SUPPLY_PRODUCE = 3;
				
				public static final String PROCUREMENT_METHOD_BUY = "buy";
				public static final String PROCUREMENT_METHOD_PRODUCE = "produce";
				public static final String PROCUREMENT_METHOD_BUYANDPRODUCE = "buyAndProduce";
				
				public static final int COST_TYPE_STANDARD = 1;
				public static final int COST_TYPE_LAST_PURCHASE_PRICE = 2;
				public static final int COST_TYPE_AVERAGE_PRICE = 3;
				public static final int COST_TYPE_LAST_PRODUCTION_PRICE = 4;
				
				// PRODUCT SUB-TYPE SELECT
				public static final int PRODUCT_SUB_TYPE_FINISHED_PRODUCT = 1;
				public static final int PRODUCT_SUB_TYPE_SEMI_FINISHED_PRODUCT = 2;
				public static final int PRODUCT_SUB_TYPE_COMPONENT = 3;
	   		]]>
	   	</extra-code>

		<track on="UPDATE">
			<field name="productCategory" />
			<field name="productFamily" />
			<field name="saleSupplySelect" />
			<field name="sellable" />
			<field name="salePrice" />
			<field name="saleCurrency" />
			<field name="unit" />
			<field name="startDate" />
			<field name="endDate" />
			<field name="purchasable" />
			<field name="purchasePrice" />
			<field name="defaultSupplierPartner" />
			<field name="purchaseCurrency" />
			<field name="supplierDeliveryTime" />
			<field name="costPrice" />
			<field name="managPriceCoef" />
			<field name="costTypeSelect" />
			<field name="hasWarranty" />
			<field name="warrantyNbrOfMonths" />
			<field name="isPerishable" />
			<field name="perishableNbrOfMonths" />
			<field name="ppa" />
			<field name="pvg" />
			<field name="shp" />
			<field name="stklim" />
			<field name="ug" />
			<message if="true" on="UPDATE">Product updated</message>
		</track>
	</entity>

</domain-models>
