<?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="fixed-asset-category-grid" title="Fixed asset categories" model="com.axelor.apps.account.db.FixedAssetCategory" orderBy="company,fixedAssetType,name">
		<field name="name"/>
	  <field name="fixedAssetType"/>
	  <field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
	  <field name="computationMethodSelect"/>
	  <field name="journal" form-view="journal-form" grid-view="journal-grid"/>
	  <field name="chargeAccount" form-view="account-form" grid-view="account-grid"/>
	  <field name="depreciationAccount" form-view="account-form" grid-view="account-grid"/>
	</grid>

	<form name="fixed-asset-category-form" title="Fixed asset category" model="com.axelor.apps.account.db.FixedAssetCategory" width="large"
		onNew="action-fixed-asset-category-record-default" onSave="action-fixed-asset-category-record-compute-duration">
        <panel name="mainPanel">
        	<field name="name"/>
        	<field name="company" form-view="company-form" grid-view="company-grid"/>
        	<field name="fixedAssetType" form-view="fixed-asset-type-form" grid-view="fixed-asset-type-grid"/>
        	<field name="isValidateFixedAsset"/>
        </panel>
        
        <panel-tabs name="mainPanelTab">
        	<panel name="accountingInfoPanel" title="Accounting information">
        		<field name="journal" domain="self.company = :company" form-view="journal-form" grid-view="journal-grid"/>
        		<field name="chargeAccount" domain="self.company = :company AND self.accountType.technicalTypeSelect = 'charge'" form-view="account-form" grid-view="account-grid"/>
        		<field name="depreciationAccount" domain="self.company = :company AND self.accountType.technicalTypeSelect = 'immobilisation'" form-view="account-form" grid-view="account-grid"/>
        	</panel>
        	<panel name="periodicityPanel" title="Periodicity">
	        	<field name="numberOfDepreciation" onChange="action-fixed-asset-attrs-set-degressive-coef,action-fixed-asset-category-record-compute-duration"/>
	        	<field name="periodicityInMonth" onChange="action-fixed-asset-category-record-compute-duration"/>
	        	<field name="durationInMonth" readonly="true"/>
        	</panel>
        	<panel name="depreciationPanel" title="Depreciation method">
        		<field name="computationMethodSelect" onChange="action-fixed-asset-attrs-set-degressive-coef"/>
	        	<field name="degressiveCoef" showIf="computationMethodSelect == 'degressive'"/>
	        	<field name="isProrataTemporis"/>
        	</panel>
        </panel-tabs>
    </form>
    
    <action-record name="action-fixed-asset-category-record-default" model="com.axelor.apps.account.db.FixedAssetCategory">
    	<field name="company" expr="eval: __user__.activeCompany"/>
    	<field name="computationMethodSelect" expr="eval: 'linear'"/>
    </action-record>
    
    <action-record name="action-fixed-asset-category-record-compute-duration" model="com.axelor.apps.account.db.FixedAssetCategory">
    	<field name="durationInMonth" expr="eval: periodicityInMonth * numberOfDepreciation"/>
    </action-record>
    
    <action-attrs name="action-fixed-asset-attrs-set-degressive-coef">
    	<attribute name="value" for="degressiveCoef" expr="eval: 1.25" if="computationMethodSelect == 'degressive' &amp;&amp; numberOfDepreciation &lt;= 4"/>
    	<attribute name="value" for="degressiveCoef" expr="eval: 1.75" if="computationMethodSelect == 'degressive' &amp;&amp; numberOfDepreciation &gt; 4 &amp;&amp; numberOfDepreciation &lt;= 6"/>
    	<attribute name="value" for="degressiveCoef" expr="eval: 2.25" if="computationMethodSelect == 'degressive' &amp;&amp; numberOfDepreciation &gt; 6"/>
    </action-attrs>
    
</object-views>
