<?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="year-account-grid" title="Fiscal years" model="com.axelor.apps.base.db.Year" orderBy="-fromDate">
		<field name="name"/>
		<field name="code" x-bind="{{code|unaccent|uppercase}}"/>
		<field name="fromDate"/>
		<field name="toDate"/>
		<field name="reportedBalanceDate"/>
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="statusSelect"/>
	</grid>

    <form name="year-account-form" title="Fiscal year" model="com.axelor.apps.base.db.Year"
      onLoad="action-attrs-year-hide-linked-adjusting-moves-dashlet" onSave="action-year-check-date" onNew="action-year-account-record-new">
		<panel name="mainPanel" readonlyIf="statusSelect == 2">
			<field name="name"/>
			<field name="code" x-bind="{{code|unaccent|uppercase}}" colSpan="3"/>
			<field name="company" widget="SuggestBox" form-view="company-form" required="true" colSpan="3" grid-view="company-grid"/>
			<panel name="datesPanel" title="Dates" colSpan="12">
				<field name="fromDate" colSpan="3" readonlyIf="periodList.length > 0"/>
				<field name="toDate" colSpan="3" readonlyIf="periodList.length > 0"/>
				<field name="reportedBalanceDate" colSpan="3"/>
			</panel>
		</panel>
		<panel-related name="periodListPanel" field="periodList" colSpan="12" readonlyIf="statusSelect == 2" form-view="period-year-form" grid-view="period-grid"/>
		<panel-dashlet action="action-view-year-linked-adjusting-moves-dashlet" name="linkedAdjustingMovesPanel" showIf="statusSelect &gt; 1"/>
		<panel name="actionsPanel" sidebar="true" readonlyIf="statusSelect == 2">
			<field name="typeSelect" readonly="true" colSpan="6"/>
			<field name="statusSelect" colSpan="6"/>
			<field name="closureDateTime" showIf="statusSelect == 2"/>
			<button name="closeBtn" title="Close fiscal year" onClick="action-group-account-year-close-click" hideIf="statusSelect == 2" prompt="The closing of a fiscal year brings irrevocable integration of a move in Moves book"/>
			<button name="adjustBtn" title="Adjust fiscal year" onClick="action-group-account-year-adjust-click" showIf="statusSelect == 2"/>
		</panel>
		<panel sidebar="true" name="periodsGenerationAssistantPanel" title="Periods generation assistant" hideIf="statusSelect == 2">
			<field name="periodDurationSelect"/>
			<button name="generatePeriodsBtn" title="Generate periods" onClick="action-year-group-generate-period-click" />
		</panel>
	</form>

	<action-attrs name="action-attrs-year-hide-linked-adjusting-moves-dashlet">
		<attribute for="linkedAdjustingMovesPanel" name="hidden" expr="eval: __repo__(AdjustHistory).all().filter('self.fiscalYear.id = ?', id).fetch().size() == 0"/>
	</action-attrs>

	<action-view name="action-view-year-linked-adjusting-moves-dashlet" title="Linked Adjusting Moves" model="com.axelor.apps.account.db.Move">
		<view type="grid" name="move-grid"/>
		<view type="form" name="move-form"/>
		<domain>self.period.year.id = :id AND self.adjustingMove = true</domain>
	</action-view>
    
    <action-group name="action-group-account-year-close-click">
    	<action name="action-year-check-date"/>
    	<action name="action-year-close-method"/>
    	<action name="save"/>
    </action-group>

	<action-group name="action-group-account-year-adjust-click">
		<action name="action-year-check-date"/>
		<action name="action-year-adjust-method"/>
		<action name="save"/>
	</action-group>
    
    <action-record name="action-year-account-record-new" model="com.axelor.apps.base.db.Year">
    	<field name="company"  expr="eval:__user__.activeCompany" if="__user__.activeCompany != null"/>
    	<field name="company"  expr="eval:__repo__(Company).all().fetchOne()" if="__user__.activeCompany == null &amp;&amp; __repo__(Company).all().fetch().size == 1"/>
    	<field name="typeSelect"  expr="eval:1"/>
    </action-record>
    
    <action-method name="action-year-close-method">
    	<call class="com.axelor.apps.account.web.YearController" method="close"/>
    </action-method>

    <action-method name="action-year-adjust-method">
    	<call class="com.axelor.apps.account.web.YearController" method="adjust"/>
    </action-method>
	
</object-views>