<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<object-views xmlns="http://axelor.com/xml/ns/object-views"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://axelor.com/xml/ns/object-views http://axelor.com/xml/ns/object-views/object-views_5.2.xsd">
	
	
    <grid name="price-list-line-grid" title="Price list lines" model="com.axelor.apps.base.db.PriceListLine" > 
       	<field name="product" form-view="product-form" grid-view="product-grid"/> 
    	<field name="productCategory" form-view="product-category-form" grid-view="product-category-grid"/>
   	 	<field name="typeSelect"/>
    	<field name="amountTypeSelect"/>
    	<field name="amount" x-scale="2"/>
    	<field name="minQty"/>
	</grid>
    
	<form name="price-list-line-form" title="Price list line" model="com.axelor.apps.base.db.PriceListLine"
	onNew="action-group-base-pricelistline-onnew"
	onLoad="action-price-list-line-attrs-scale-and-precision" width="large">
		<panel name="applicationPanel" title="Apply on" colSpan="11">
			<field name="product" canEdit="false" colSpan="5" onChange="action-price-list-line-record-product" form-view="product-form" grid-view="product-grid" requiredIf="productCategory == null" hideIf="productCategory != null"/> 
			<label name="orLabel" title="Or" colSpan="1" hideIf="product != null || productCategory != null"/>
			<field name="productCategory" colSpan="5" form-view="product-category-form" grid-view="product-category-grid" requiredIf="product == null" hideIf="product != null" onChange="action-price-list-line-attrs-product-category-change"/>
		</panel>
		<panel name="calculationMethodPanel" title="Calculation method" colSpan="12" >
			<field name="typeSelect" hideIf="productCategory" selection="base.price.list.line.type.select" colSpan="12" onChange="action-price-list-line-record-type-select, action-price-list-line-attrs-amount-title-change, action-price-list-line-attrs-amount-percent-title-change" />
			<field name="typeSelect" hideIf="!productCategory" selection-in="[1,2]" selection="base.price.list.line.type.select" colSpan="12" onChange="action-price-list-line-record-type-select, action-price-list-line-attrs-amount-title-change, action-price-list-line-attrs-amount-percent-title-change" />
			<field name="amountTypeSelect" colSpan="12" hideIf="typeSelect == 3" onChange="action-price-list-line-attrs-amount-percent-title-change"/>
			<field name="amount" colSpan="12" hideIf="amountTypeSelect == 3"/>
			<field name="minQty" colSpan="12"/>
		</panel>
	</form>
	
	<action-group name="action-group-base-pricelistline-onnew">
		<action name="action-price-list-line-attrs-scale-and-precision"/>
		<action name="action-price-list-line-record-default"/>
		<action name="action-price-list-line-record-type-select"/>
	</action-group>
	
	<action-record name="action-price-list-line-record-default" model="com.axelor.apps.base.db.PriceListLine">
		<field name="typeSelect" expr="3"/>
	</action-record>
   
   	<action-record name="action-price-list-line-record-product" model="com.axelor.apps.base.db.PriceListLine">
 		<field name="amount" expr="eval: product?.salePrice" if="product &amp;&amp; _parent?.typeSelect == 1 &amp;&amp; typeSelect == 3"/>
 		<field name="amount" expr="eval: product?.purchasePrice" if="product &amp;&amp; _parent?.typeSelect == 2 &amp;&amp; typeSelect == 3"/>
    </action-record>
    
    <action-record name="action-price-list-line-record-type-select" model="com.axelor.apps.base.db.PriceListLine">
    	<field name="amountTypeSelect" expr="2" if="typeSelect == 3"/>
    </action-record>
    
    <action-attrs name="action-price-list-line-attrs-scale-and-precision">
		<attribute name="scale" for="amount" expr="eval: __config__.app.getNbDecimalDigitForUnitPrice()"/>
	</action-attrs>
	
	<action-attrs name="action-price-list-line-attrs-amount-percent-title-change">
		<attribute name="title" for="amount" expr="%" if="amountTypeSelect == 1"/>	
		<attribute name="title" for="amount" expr="eval: com.axelor.i18n.I18n.get(&quot;Amount&quot;)" if="amountTypeSelect == 2"/>
	</action-attrs>
	
	<action-attrs name="action-price-list-line-attrs-amount-title-change">
		<attribute name="title" for="amount" expr="eval: com.axelor.i18n.I18n.get(&quot;Amount&quot;)" if="typeSelect == 3"/>
	</action-attrs>

	<action-attrs name="action-price-list-line-attrs-product-category-change">
		<attribute name="value" for="typeSelect" expr="eval: 1" if="productCategory"/>
        <attribute name="title" for="typeSelect" expr="eval: 'Discount/Additionnal'" if="productCategory"/>
		<attribute name="value" for="typeSelect" expr="eval: 3" if="!productCategory"/>
		<attribute name="title" for="typeSelect" expr="eval: 'Discount/Additionnal/Replace'" if="!productCategory"/>
	</action-attrs>
	
</object-views>

