<?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="analytic-move-line-grid" title="Analytic Move Lines" model="com.axelor.apps.account.db.AnalyticMoveLine">
    	<hilite if="typeSelect == 1" color="warning"/>
    	<hilite if="typeSelect == 2" color="info"/>
    	<hilite if="typeSelect == 3" color="success"/>
    	<hilite if="typeSelect == 4" color="primary"/>
        <field name="analyticJournal" form-view="analytic-journal-form" grid-view="analytic-journal-grid"/>
        <field name="analyticAxis" form-view="analytic-axis-form" grid-view="analytic-axis-grid"/>
        <field name="analyticAccount" form-view="analytic-account-form" grid-view="analytic-account-grid"/>
        <field name="accountType" />
        <field name="date"/>
        <field name="originalPieceAmount" aggregate="sum"/>
        <field name="amount" aggregate="sum"/>
        <field name="typeSelect"/>
    </grid>
    
    <grid name="analytic-move-line-distribution-grid" title="Analytic move lines" model="com.axelor.apps.account.db.AnalyticMoveLine" groupBy="analyticAxis">
        <field name="analyticJournal" grid-view="analytic-journal-grid" form-view="analytic-journal-form"/>
        <field name="analyticAxis" form-view="analytic-axis-form" grid-view="analytic-axis-grid"/>
        <field name="analyticAccount" grid-view="analytic-account-grid" form-view="analytic-account-form"/>
         <field name="accountType" />
        <field name="percentage"/>
        <field name="originalPieceAmount" aggregate="sum"/>
        <field name="amount"/>
        <field name="date"/>
        <field name="project" if-module="axelor-business-project" if="__config__.app.isApp('business-project')"/>
        <field name="typeSelect"/>
    </grid>
    
    <form name="analytic-move-line-form" title="Analytic Move Line" model="com.axelor.apps.account.db.AnalyticMoveLine"  onNew="action-analytic-move-line-record-currency,action-analytic-move-line-attrs-title-project"
    	onLoad="action-analytic-move-line-attrs-title-project" width="large">
       <panel name="mainPanel" >
       		<field name="analyticJournal" form-view="analytic-journal-form" grid-view="analytic-journal-grid"/>
       		<field name="analyticAxis" form-view="analytic-axis-form" grid-view="analytic-axis-grid"/>
	        <field name="analyticAccount" form-view="analytic-account-form" grid-view="analytic-account-grid"/>
	        <field name="date"/>
	        <field name="percentage"/>
            <field name="originalPieceAmount" aggregate="sum"/>
	        <field name="amount"/>
	        <field name="currency" canEdit="false"  form-view="currency-form" grid-view="currency-grid" />
	        <field name="project" domain="self.imputable = true AND self.isBusinessProject = true" if-module="axelor-business-project" form-view="project-form" grid-view="project-grid" if="__config__.app.isApp('business-project')" title="Business project"/>
  			<field name="account" onSelect="action-analytic-move-line-attrs-account-domain" onChange="action-analytic-move-line-record-account-onchange"/>
            <field name="accountType" onChange="action-analytic-move-line-record-account-type-onchange"/>
	        <field name="typeSelect"/>
           <field name="moveLine" width="135" form-view="move-line-form" grid-view="move-line-grid" showIf="moveLine"/>
       </panel>

    </form>
    
    <form name="analytic-move-line-distribution-form" title="Analytic move line" model="com.axelor.apps.account.db.AnalyticMoveLine" onNew="action-analytic-move-line-attrs-set-original-piece-amount">
        <panel name="mainPanel" >
   	        <field name="analyticJournal" grid-view="analytic-journal-grid" form-view="analytic-journal-form"/>
	        <field name="analyticAxis" form-view="analytic-axis-form" grid-view="analytic-axis-grid"/>
	        <field name="analyticAccount" grid-view="analytic-account-grid" form-view="analytic-account-form"/>
	        <field name="accountType" grid-view="account-type-grid" form-view="account-type-form"/>
	        <field name="percentage" colSpan="4" onChange="action-analytic-move-line-method-compute-amount"/>
            <field name="originalPieceAmount" aggregate="sum"/>
	        <field name="amount" colSpan="4" readonly="true"/>
	        <field name="date" colSpan="4"/>
	        <field name="project" grid-view="project-grid" form-view="project-form" if-module="axelor-business-project" if="__config__.app.isApp('business-project')"/>
	        <field name="typeSelect"/>
        </panel>      
    </form>
    
    <action-method name="action-analytic-move-line-method-compute-amount">
    	<call class="com.axelor.apps.account.web.AnalyticDistributionLineController" method="computeAmount"/>
    </action-method>
    
    <action-record name="action-analytic-move-line-record-currency" model="com.axelor.apps.account.db.AnalyticMoveLine">
    	<field name="currency" expr="eval: __user__.activeCompany?.currency"/>
    </action-record>

    <action-record name="action-analytic-move-line-record-account-onchange" model="com.axelor.apps.account.db.AnalyticMoveLine">
        <field name="accountType" expr="eval: account.accountType" if="account"/>
    </action-record>

    <action-record name="action-analytic-move-line-record-account-type-onchange" model="com.axelor.apps.account.db.AnalyticMoveLine">
        <field name="account" expr="eval: null"/>
    </action-record>

    <action-attrs name="action-analytic-move-line-attrs-account-domain">
        <attribute for="account" name="domain" expr="eval: null"/>
        <attribute for="account" name="domain" expr="eval: 'self.accountType = :accountType'" if="accountType"/>
    </action-attrs>
    
    <action-attrs if-module="axelor-business-project"  name="action-analytic-move-line-attrs-title-project">
		<attribute name="title" for="project" expr="eval: __config__.app.getApp('project').getProjectLabel()" if="__config__.app.isApp('project') &amp;&amp; !com.google.common.base.Strings.isNullOrEmpty(__config__.app.getApp('project').getProjectLabel())"/>
	</action-attrs>
  
    <action-attrs if-module="axelor-supplychain" name="action-analytic-move-line-attrs-set-original-piece-amount">
         <attribute for="originalPieceAmount" name="value" expr="eval: __parent__.exTaxTotal" if="__parent__ &amp;&amp; (__parent__._model == 'com.axelor.apps.purchase.db.PurchaseOrderLine' || __parent__._model == 'com.axelor.apps.sale.db.SaleOrderLine' || __parent__._model == 'com.axelor.apps.account.db.InvoiceLine')"/>
    </action-attrs>
	
</object-views>
