<?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="prod-process-line-grid" title="Phases" model="com.axelor.apps.production.db.ProdProcessLine" orderBy="priority">
		<field name="priority" width="75"/>
		<field name="name"/>
		<field name="workCenter" grid-view="work-center-grid" form-view="work-center-form"/>
		<field name="outsourcing" width="115"/>
		<field name="optional"/>
		<field name="description"/>
	</grid>
    
    <form name="prod-process-line-form" title="Phase" model="com.axelor.apps.production.db.ProdProcessLine"
    onNew="action-prod-process-line-record-default, action-prod-process-line-attrs-default"
    onLoad="action-prod-process-line-attrs-default" width="large">
    	<panel name="mainPanel"> 
			<field name="name"/>
			<field name="priority" colSpan="3"/>
			<field name="workCenter" grid-view="work-center-grid" form-view="work-center-form" canNew="true" onChange="action-prod-process-line-group-work-center-onchange"/>
			<field name="outsourcing"/>
			<field name="optional"/>
			<field name="stockLocation"/>
			<panel name="capacitySettingsPanel" title="Capacity settings" colSpan="12">
				<field name="minCapacityPerCycle" colSpan="3"/>
				<field name="maxCapacityPerCycle" colSpan="3"/>
				<field name="durationPerCycle" colSpan="3" widget="duration" x-big="true" x-seconds="true"/>
	        </panel>
			<panel name="descriptionPanel" title="Description" colSpan="12">
    			<field name="description" showTitle="false" height="5" colSpan="12"/>
    		</panel>
    	</panel>
    	<panel-tabs name="mainPanelTab">
			<panel-related name="toConsumeProdProductListPanel" field="toConsumeProdProductList" title="To consume products" editable="true" colSpan="12" form-view="prod-product-form" grid-view="prod-product-grid"/>
				<panel name="descriptionPanel" title="Descriptions">
					<field name="objectDescriptionList" colSpan="12">
						<editor x-layout="table" x-show-on-new="false" x-viewer="true">
							<panel name="mainPanel" colSpan="12">
								<field name="image" colSpan="3" canNew="true" widget="Image"/>
								<field name="description" widget="html" colSpan="9"/>
							</panel>
						</editor>
					</field>
				</panel>
    	</panel-tabs>
    	        
    	<panel-mail name="mailPanel">
			<mail-messages limit="4"/>
			<mail-followers/>
		</panel-mail>        
    </form>

	<action-group name="action-prod-process-line-group-work-center-onchange">
		<action name="action-prod-process-line-method-duration"/>
		<action name="action-prod-process-line-method-capacity-settings"/>
	</action-group>
    
    <action-method name="action-prod-process-line-method-duration">
    	<call class="com.axelor.apps.production.web.ProdProcessLineController" method="updateDuration"/>
    </action-method>
    
    <action-method name="action-prod-process-line-method-capacity-settings">
    	<call class="com.axelor.apps.production.web.ProdProcessLineController" method="updateCapacitySettings"/>
    </action-method>
    
    <action-record name="action-prod-process-line-record-default" model="com.axelor.apps.production.db.ProdProcessLine">
    	<field name="priority" expr="eval:__parent__?.prodProcessLineList?.max{ it.getPriority() }?.getPriority() + 10"/>
    	<field name="stockLocation" expr="eval:__parent__?.company?.getStockConfig().getProductionVirtualStockLocation()"/>
    </action-record>
    
    <action-attrs name="action-prod-process-line-attrs-default">
    	<attribute name="hidden" for="toConsumeProdProductList" expr="eval: _parent != null ? !_parent.isConsProOnOperation : !prodProcess.isConsProOnOperation"/>
		<attribute name="hidden" for="stockLocation" expr="eval: !__parent__.isConsProOnOperation"/>
    </action-attrs>
    
</object-views>

