<?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="move-template-line-in-amount-grid" title="Move template line" model="com.axelor.apps.account.db.MoveTemplateLine">
        <field name="name" />
        <field name="product" form-view="product-form" grid-view="product-grid"/>
        <field name="account" form-view="account-form" grid-view="account-grid"/>
        <field name="analyticDistributionTemplate" if="__config__.app.isApp('account') &amp;&amp; __config__.app.getApp('account').getManageAnalyticAccounting()" grid-view="analytic-distribution-template-grid" form-view="analytic-distribution-template-form"/>
    	<field name="debit"/>
        <field name="credit"/>
        <field name="tax" canEdit="false" grid-view="tax-grid" form-view="tax-form"/>
    </grid>
    
   	<grid name="move-template-line-in-percentage-grid"  title="Move template line" model="com.axelor.apps.account.db.MoveTemplateLine">
		<field name="name"/>
		<field name="product" grid-view="product-grid" form-view="product-form"/>
		<field name="account" grid-view="account-grid" form-view="account-form"/>
        <field name="analyticDistributionTemplate" if="__config__.app.isApp('account') &amp;&amp; __config__.app.getApp('account').getManageAnalyticAccounting()" grid-view="analytic-distribution-template-grid" form-view="analytic-distribution-template-form"/>
    	<field name="debitCreditSelect"/>
		<field name="percentage"/>
        <field name="tax" canEdit="false" grid-view="tax-grid" form-view="tax-form"/>
    </grid>
    
	<form name="move-template-line-in-amount-form" title="Move template line" model="com.axelor.apps.account.db.MoveTemplateLine">
		<panel name="mainPanel">
			<field name="name"/>
			<field name="partner" canEdit="false" form-view="partner-form" grid-view="partner-grid"/>
			<field name="debit" readonlyIf="credit > 0" onChange="action-move-template-line-record-update-need-to-check-validity"/>
        	<field name="credit" readonlyIf="debit > 0" onChange="action-move-template-line-record-update-need-to-check-validity"/>
        	<field name="product" canEdit="false" onChange="action-move-template-line-get-account" form-view="product-form" grid-view="product-grid"/>
			<field name="account" canEdit="false" onSelect="action-move-template-line-set-account-domain" grid-view="account-grid" form-view="account-form"/>
	        <field name="tax" canEdit="false" grid-view="tax-grid" form-view="tax-form"/>
	        <field name="analyticDistributionTemplate" if="__config__.app.isApp('account') &amp;&amp; __config__.app.getApp('account').getManageAnalyticAccounting()" grid-view="analytic-distribution-template-grid" form-view="analytic-distribution-template-form"/>
			<field name="isValid" readonly="true" hidden="true"/>
		</panel>
  	</form>
  	
  	<form name="move-template-line-in-percentage-form" title="Move template line" model="com.axelor.apps.account.db.MoveTemplateLine">
		<panel name="mainPanel">
			<field name="name"/>
			<field name="debitCreditSelect" onChange="action-move-template-line-get-account" required="true"/>
			<field name="percentage" placeholder="80" onChange="action-template-move-line-check-percent,action-move-template-line-record-update-need-to-check-validity"/>
			<field name="product" canEdit="false" onChange="action-move-template-line-get-account" form-view="product-form" grid-view="product-grid"/>
			<field name="account" canEdit="false" onSelect="action-move-template-line-set-account-domain" grid-view="account-grid" form-view="account-form"/>
			<field name="hasPartnerToDebit" showIf="debitCreditSelect == 'D'"/>
			<field name="hasPartnerToCredit" showIf="debitCreditSelect == 'C'"/>
	        <field name="tax" canEdit="false" grid-view="tax-grid" form-view="tax-form"/>
	        <field name="analyticDistributionTemplate" if="__config__.app.isApp('account') &amp;&amp; __config__.app.getApp('account').getManageAnalyticAccounting()" grid-view="analytic-distribution-template-grid" form-view="analytic-distribution-template-form"/>
			<field name="isValid" readonly="true" hidden="true"/>
		</panel>
  	</form>
  	
  	<action-record name="action-move-template-line-record-update-need-to-check-validity" model="com.axelor.apps.account.db.MoveTemplateLine">
  		<field name="isValid" expr="eval: false"/>
  	</action-record>
    
    <action-record name="action-move-template-line-get-account" model="com.axelor.apps.account.db.MoveTemplateLine">
    	<field name="account" expr="call:com.axelor.apps.account.service.AccountManagementServiceAccountImpl:getProductAccount(product,moveTemplate.company,true)" if="product != null &amp;&amp; moveTemplate?.company != null &amp;&amp; (debitCreditSelect == 'D' || debit &gt; 0) "/>
    	<field name="account" expr="call:com.axelor.apps.account.service.AccountManagementServiceAccountImpl:getProductAccount(product,__repo__(Company).find(_parent.company.id),true)" if="product != null &amp;&amp; _parent?.company != null &amp;&amp; (debitCreditSelect == 'D' || debit &gt; 0) "/>
    	<field name="account" expr="call:com.axelor.apps.account.service.AccountManagementServiceAccountImpl:getProductAccount(product,moveTemplate.company,false)" if="product != null &amp;&amp; moveTemplate?.company != null &amp;&amp; (debitCreditSelect == 'C' || credit &gt; 0) "/>
    	<field name="account" expr="call:com.axelor.apps.account.service.AccountManagementServiceAccountImpl:getProductAccount(product,__repo__(Company).find(_parent.company.id),false)" if="product != null &amp;&amp; _parent?.company != null &amp;&amp; (debitCreditSelect == 'C' || credit &gt; 0) "/>
    </action-record>
    
    <action-validate name="action-template-move-line-check-percent">
    	<error message="Please input values between 1 to 100" action="action-template-move-line-set-percent" if="percentage &lt; 0 || percentage &gt; 100"/>
    </action-validate>
    
    <action-record name="action-template-move-line-set-percent" model="com.axelor.apps.account.db.MoveTemplateLine">
    	<field name="percentage" expr="eval: 0" />
    </action-record>
    
    <action-attrs name="action-move-template-line-set-account-domain">
        <attribute name="domain" for="account" expr="eval:&quot;self.company.id = ${_parent?.company?.id} &quot;" if="_parent != null" />
        <attribute name="domain" for="account" expr="eval:&quot;self.company.id = ${moveTemplate?.company?.id} &quot;" if="moveTemplate != null" />
    </action-attrs>
    
    
</object-views>