<?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="manuf-order-grid" title="Manufacturing orders" model="com.axelor.apps.production.db.ManufOrder" orderBy="-manufOrderSeq">
		<toolbar>
			<button name="printBtn" title="Print" icon="fa-print" onClick="action-manuf-order-method-print"/>
			<button name="planBtn" title="Plan" onClick="action-manuf-order-method-plan"/>
		</toolbar>
		<hilite color="danger" if="prioritySelect == 4"/>
		<hilite color="warning" if="prioritySelect == 3"/>
		<hilite color="primary" if="prioritySelect == 2"/>
		<hilite color="info" if="prioritySelect == 1"/>
    <field name="prioritySelect" hidden="true"/>
		<field name="manufOrderSeq" width="120"/>
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="workshopStockLocation" if="__config__.app.getApp('production').getManageWorkshop()"/>
		<field name="product" form-view="product-form" grid-view="product-grid"/>
		<field name="billOfMaterial" grid-view="bill-of-material-grid" form-view="bill-of-material-form"/>
		<field name="prodProcess" grid-view="prod-process-grid" form-view="prod-process-form"/>
		<field name="prodProcess.outsourcing"/>
		<field name="plannedStartDateT"/>
		<field name="plannedEndDateT"/>
		<field name="realStartDateT"/>
		<field name="realEndDateT"/>
		<field name="statusSelect"/>
		<button name="planBtn" icon="fa-calendar" onClick="action-manuf-order-method-plan" readonlyIf="statusSelect >= 3"/>
		<button name="startBtn" icon="fa-play" onClick="action-manuf-order-method-start-or-resume" readonlyIf="statusSelect != 3 &amp;&amp; statusSelect != 5"/>
		<button name="pauseBtn" icon="fa-pause" onClick="action-manuf-order-method-pause" readonlyIf="statusSelect != 4"/>
		<button name="finishBtn" icon="fa-power-off" onClick="action-manuf-order-group-finish" readonlyIf="statusSelect != 4"/>
		<button name="cancelBtn" icon="fa-times-circle" onClick="action-manuf-order-view-cancel" readonlyIf="statusSelect == 2"/>
		<button name="printBtn" title="Print" icon="fa-print" onClick="action-manuf-order-method-print"/>
  </grid>
    
  <grid name="manuf-order-business-grid" title="Manufacturing orders" model="com.axelor.apps.production.db.ManufOrder" orderBy="-manufOrderSeq" groupBy="productionOrder">
    <toolbar>
      <button name="printBtn" title="Print" icon="fa-print" onClick="action-manuf-order-method-print"/>
    </toolbar>
    <field name="productionOrder" width="120"/>
		<field name="manufOrderSeq" width="120"/>
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="product" form-view="product-form" grid-view="product-grid"/>
		<field name="billOfMaterial" grid-view="bill-of-material-grid" form-view="bill-of-material-form"/>
		<field name="prodProcess" grid-view="prod-process-grid" form-view="prod-process-form"/>
		<field name="prodProcess.outsourcing"/>
		<field name="plannedStartDateT"/>
		<field name="plannedEndDateT"/>
		<field name="realStartDateT"/>
		<field name="realEndDateT"/>
		<field name="statusSelect"/>
		<button name="planBtn" icon="fa-calendar" onClick="action-manuf-order-method-plan" readonlyIf="statusSelect >= 3"/>
		<button name="startBtn" icon="fa-play" onClick="action-manuf-order-method-start-or-resume" readonlyIf="statusSelect != 3 &amp;&amp; statusSelect != 5"/>
		<button name="pauseBtn" icon="fa-pause" onClick="action-manuf-order-method-pause" readonlyIf="statusSelect != 4"/>
		<button name="finishBtn" icon="fa-power-off" onClick="action-manuf-order-group-finish" readonlyIf="statusSelect != 4"/>
		<button name="cancelBtn" icon="fa-times-circle" onClick="action-manuf-order-view-cancel" readonlyIf="statusSelect == 2"/>
		<button name="printBtn" title="Print" icon="fa-print" onClick="action-manuf-order-method-print"/>
  </grid>
    
  <grid name="manuf-order-invoicing-project-grid" title="Manufacturing orders" model="com.axelor.apps.production.db.ManufOrder" orderBy="-manufOrderSeq" groupBy="productionOrder">
    <field name="productionOrder" width="120"/>
    <field name="manufOrderSeq" width="120"/>
    <field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
    <field name="product" form-view="product-form" grid-view="product-grid"/>
    <field name="prodProcess" grid-view="prod-process-grid" form-view="prod-process-form"/>
    <field name="plannedStartDateT"/>
    <field name="realStartDateT"/>
    <field name="statusSelect"/>
  </grid>
    
  <grid name="manuf-order-time-tracking-grid" title="Manufacturing orders" model="com.axelor.apps.production.db.ManufOrder" orderBy="-manufOrderSeq" groupBy="productionOrder" >
	  <field name="productionOrder" width="120" />
	  <field name="manufOrderSeq" width="120"/>
	  <field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
	  <field name="product" form-view="product-form" grid-view="product-grid"/>
	  <field name="prodProcess" grid-view="prod-process-grid" form-view="prod-process-form"/>
	  <field name="plannedEndDateT"/>
	  <field name="realEndDateT"/>
	  <field name="endTimeDifference">
	  	<hilite color="danger" if="endTimeDifference &gt; 0"/>
	  	<hilite color="success" if="endTimeDifference &lt;= 0"/>
	  </field>
  </grid>

	<form onNew="action-manuf-order-default-record,action-manuf-order-attrs-price-digits"
	      name="manuf-order-form" title="Manufacturing order" model="com.axelor.apps.production.db.ManufOrder"
	      onLoad="action-manuf-order-attrs-isConsProOnOperation,action-manuf-order-attrs-price-digits" width="large">
<!--     TODO avec propagation -->
		<menubar>
            <menu name="manufOrderReportsMenu" title="Reports" icon="fa-files-o" showTitle="true">
	            <item name="printItem" title="Print" action="save,action-manuf-order-method-print" showIf="statusSelect > 1" />
	            <item name="printProductionProcessItem" title="Print Production Process" action="save,action-production-process-method-print"  />
	        </menu>
		</menubar>
		<panel name="mainPanel">
		<panel name="detailsPanel" colSpan="8">
			<field name="manufOrderSeq"  readonly="true" css="bold" colSpan="2"/>
			<field name="prioritySelect" readonlyIf="statusSelect == 6" colSpan="2"/>
			<field name="company" widget="SuggestBox" onChange="action-manuf-order-record-empty-workshop" canEdit="false" readonlyIf="statusSelect &gt; 1" colSpan="2" form-view="company-form" grid-view="company-grid"/>
			<field name="workshopStockLocation" colSpan="2" canEdit="false" onChange="action-manuf-order-record-workshop-onchange" readonlyIf="statusSelect &gt; 1" if="__config__.app.getApp('production').getManageWorkshop()" domain="self.company = :company and self.typeSelect = 1 and self.isWorkshop = true"/>
			<field name="$viewerIsOutsourcing" showTitle="false" readonly="true" showIf="$readonly()" colSpan="2" depends="prodProcess.outsourcing">
				<viewer>
					<![CDATA[
						<h4 class="text-right">
							<span class="label label-default" style="background-color: #E0A83C; margin: 5px 0 !important; display: inline-table; line-height: initial;" ng-show="record.prodProcess.outsourcing" x-translate>Outsourced</span>
						</h4>
					]]>
				</viewer>
			</field>
			<field name="$viewerIsPermanent" showTitle="false" colSpan="2" showIf="isPermanent &amp;&amp; $readonly()">
				<viewer depends="isPermanent">
					<![CDATA[
						<h4 style="text-align: left;">
							<span class="label label-default" style="background-color: green; margin: 5px 0 !important; display: inline-table; line-height: initial;" x-translate>Permanent</span>
						</h4>
	                ]]>
				</viewer>
			</field>
			<field name="statusSelect" showTitle="false" readonly="true" colSpan="12" widget="NavSelect"/>
			<field name="billOfMaterial" required="true" readonlyIf="statusSelect &gt; 1" onChange="action-manuf-order-group-onchange" domain="self.defineSubBillOfMaterial = true AND self.statusSelect = 3 AND ((:workshopStockLocation IS NULL AND self.workshopStockLocation IS NULL) OR self.workshopStockLocation = :workshopStockLocation)" grid-view="bill-of-material-grid" form-view="bill-of-material-form" colSpan="3" canEdit="false"/>
			<field name="prodProcess" onChange="action-manuf-order-group-prod-process-onchange" onSelect="action-manuf-order-attrs-filter-prodProcess" readonlyIf="statusSelect &gt; 1" grid-view="prod-process-grid" form-view="prod-process-form" colSpan="3" canEdit="false"/>
			<field name="prodProcess.outsourcing" colSpan="3" hidden="true"/>
			<field name="product" canEdit="false" required="true" readonlyIf="statusSelect &gt; 1 || !product.isModel" form-view="product-form" grid-view="product-grid" onSelect="action-manuf-order-attrs-filter-product"/>
			<field name="qty" readonlyIf="statusSelect &gt; 1 || isPermanent" validIf="isPermanent || qty > 0" colSpan="3"/>
			<field name="product.economicManufOrderQty" colSpan="3"/>
			<field name="unit" readonly="true"/>
			<field name="clientPartner" form-view="partner-form" grid-view="partner-grid" domain="self.isCustomer=true AND :company member of self.companySet" onChange="action-manuf-order-atts-sale-order-onchange-client-partner" canEdit="false"/>
			<field name="saleOrder" form-view="sale-order-form" grid-view="sale-order-grid" onSelect="action-manuf-order-attrs-sale-order-onselect" onChange="action-manuf-order-record-client-partner-onchange-sale-order" canEdit="false"/>
			<field name="isConsProOnOperation" hidden="true"/>
			<field name="isToInvoice" onChange="save,action-manuf-order-method-is-to-invoice" if-module="axelor-business-production" if="__config__.app.getApp('production').getManageBusinessProduction()" />
			<field name="invoiced" showIf="isToInvoice" if-module="axelor-business-production" if="__config__.app.getApp('production').getManageBusinessProduction()" />
			<button name="preFillOperationsBtn" colSpan="4" title="Pre-fill operations" hideIf="statusSelect &gt; 1  &#124;&#124; operationOrderList.length &gt; 0" onClick="save,action-manuf-order-method-pre-fill-operations" />
			<field name="product.isModel" hidden="true"/>
		</panel>
		<panel name="actionsPanel" title="Actions" colSpan="4">
			<button name="planBtn" icon="fa-calendar" title="Plan" colSpan="12" showIf="statusSelect == 1 || statusSelect == 2" onClick="save,action-manuf-order-method-plan" />
			<button name="startBtn" icon="fa-play" title="Start" colSpan="12" showIf="statusSelect == 3" onClick="save,action-manuf-order-method-start"/>
			<button name="pauseBtn" icon="fa-pause" title="Pause" colSpan="12" showIf="statusSelect == 4" onClick="save,action-manuf-order-method-pause"/>
			<button name="resumeBtn" icon="fa-step-forward" title="Resume" colSpan="12" showIf="statusSelect == 5" onClick="save,action-manuf-order-method-resume"/>
			<button name="realizeBtn" icon="fa-check" title="Consume in stock moves" colSpan="12" showIf="statusSelect == 4" onClick="save,action-manuf-order-method-consume-stock-move"/>
			<button name="finishBtn" icon="fa-power-off" title="Finish" colSpan="12" showIf="statusSelect == 4" onClick="save,action-manuf-order-group-finish"/>
			<button name="finishPartBtn" icon="fa-power-off" title="Partial Finish" colSpan="12" showIf="statusSelect == 4" onClick="save, action-manuf-order-method-part-finish"/>
			<button name="cancelBtn" icon="fa-times-circle" title="Cancel" colSpan="12" showIf="statusSelect != 2" onClick="save,action-manuf-order-view-cancel"/>
		</panel>
		</panel>
		<panel-tabs name="mainPanelTab" colSpan="4" >
			<panel-related name="operationOrderListPanel" field="operationOrderList" readonlyIf="statusSelect == 6" colSpan="12" height="15" form-view="operation-order-form" grid-view="operation-order-grid"/>
			<panel name="datesPanel" title="Dates" readonlyIf="statusSelect == 6">
				<panel name="plannedDatesPanel" title="Planned dates">
					<field name="plannedStartDateT" title="Start date" onChange="action-manuf-order-method-update-planned-dates"/>
					<field name="plannedEndDateT" title="End date" onChange="action-manuf-order-validate-planned-end-date"/>
					<field name="$totalPlannedDuration" title="Total Planned Duration" type="long" readonly="true" widget="duration" x-seconds="true" x-big="true"/>
					<field name="cancelReason" hidden="true"/>
					<field name="cancelReasonStr" title="Cancel Reason" hidden="true" readonly="true" showIf="cancelReason != null &amp;&amp; cancelReasonStr != null" colSpan="12" css="red">
						<viewer><![CDATA[{{record.cancelReasonStr}}]]></viewer>
					</field>
				</panel>
				<panel name="realDatesPanel" title="Real dates" showIf="statusSelect &gt; 3">
					<field name="realStartDateT" title="Start date"/>
					<field name="realEndDateT" title="End date"/>
					<field name="$totalRealDuration" title="Total Real Duration" type="long" readonly="true" widget="duration" x-seconds="true" x-big="true"/>
				</panel>
			</panel>
			<panel name="stockMovesPanel" title="Stock moves" showIf="statusSelect &gt;= 3" readonly="true">
				<panel name="stockMoveListPanel" title="Moves In/Out" readonlyIf="statusSelect == 6" colSpan="12">
					<field name="inStockMoveList" form-view="stock-move-form" grid-view="stock-move-manuf-order-grid" hideIf="isConsProOnOperation" colSpan="12"/>
					<field name="outStockMoveList" form-view="stock-move-form" grid-view="stock-move-manuf-order-grid" colSpan="12"/>
				</panel>
				<panel name="productionWastePanel" title="Production waste" colSpan="12" showIf="statusSelect &gt;= 4">
					<button name="generateWasteStockMoveBtn" title="Generate waste stock move" readonlyIf="wasteStockMove != null" onClick="save,action-manuf-order-method-generate-waste-stock-move"/>
					<field name="wasteStockMove" form-view="stock-move-form" grid-view="stock-move-manuf-order-grid" readonly="true"/>
				</panel>
			</panel>
			<panel name="consumedProductsPanel" title="Consumed products" hideIf="isConsProOnOperation || statusSelect &lt; 3">
				<button name="updatePlannedQtyBtn" title="Update planned quantities (Components and FP)" colSpan="12" showIf="statusSelect != 6 &amp;&amp; !isPermanent" onClick="save,action-manuf-order-update-planned-qty-popup-form-view" css="btn-custom"/>
				<panel-related name="toConsumeProdProductListPanel" field="toConsumeProdProductList" readonly="true" colSpan="12" grid-view="prod-product-consume-manuf-order-grid" form-view="prod-product-form" orderBy="product.code"/>
				<button name="updateRealQtyBtn" title="Update real quantities (Components and FP)" colSpan="12" showIf="$contains([4,5],statusSelect) &amp;&amp; !isPermanent" onClick="save,action-manuf-order-update-real-qty-popup-form-view" css="btn-custom"/>
				<panel-related name="consumedStockMoveLineListPanel" field="consumedStockMoveLineList" onChange="action-manuf-order-method-check-consumed-stock-move,save,action-manuf-order-method-update-consumed-stock-move" readonlyIf="statusSelect == 6" colSpan="12" form-view="stock-move-line-production-form" grid-view="stock-move-line-consumed-production-grid"/>
				<panel-related name="diffStockMoveLineListPanel" field="diffConsumeProdProductList" readonly="true" colSpan="12" grid-view="prod-product-diff-manuf-order-grid" form-view="prod-product-form"/>
			</panel>
   			<panel name="consumedProductsPanel" title="Consumed products" showIf="isConsProOnOperation &amp;&amp; statusSelect &gt;= 3">
				<button name="updatePlannedQtyBtn" title="Update planned quantities (Components and FP)" colSpan="12" showIf="statusSelect != 6 &amp;&amp; !isPermanent" onClick="save,action-manuf-order-update-planned-qty-popup-form-view" css="btn-custom"/>
				<panel-dashlet name="operationOrderToConsumeProductPanel" readonly="true" colSpan="12" action="action-manuf-order-view-operation-order-to-consume-product"/>
				<button name="updateRealQtyBtn" title="Update real quantities (Components and FP)" colSpan="12" showIf="statusSelect != 6 &amp;&amp; !isPermanent" onClick="save,action-manuf-order-update-real-qty-popup-form-view" css="btn-custom"/>
				<panel-dashlet name="operationOrderConsumedProductPanel" readonly="true" colSpan="12" action="action-manuf-order-view-operation-order-consumed-product"/>
				<panel-dashlet name="operationOrderDiffConsumeProductPanel" readonly="true" colSpan="12" action="action-manuf-order-view-operation-order-diff-consume-product"/>
			</panel>
			<panel name="finishedProductsPanel" title="Finished products" showIf="statusSelect &gt;= 3">
				<button name="updatePlannedQtyBtn" title="Update planned quantities (Components and FP)" colSpan="12" showIf="statusSelect != 6 &amp;&amp; !isPermanent" onClick="save,action-manuf-order-update-planned-qty-popup-form-view" css="btn-custom"/>
				<panel-related name="toProduceProdProductListPanel" field="toProduceProdProductList" readonlyIf="statusSelect &gt;= 3" colSpan="12" grid-view="prod-product-grid" form-view="prod-product-form"/>
				<button name="updateRealQtyBtn" title="Update real quantities (Components and FP)" colSpan="12" showIf="statusSelect != 6 &amp;&amp; !isPermanent" onClick="save,action-manuf-order-update-real-qty-popup-form-view" css="btn-custom"/>
				<panel-related name="producedStockMoveLineListPanel" field="producedStockMoveLineList" onChange="action-manuf-order-method-check-produced-stock-move,save,action-manuf-order-method-update-produced-stock-move" readonlyIf="statusSelect == 6" colSpan="12" form-view="stock-move-line-production-form" grid-view="stock-move-line-produced-production-grid"/>
				<panel-related name="wasteProdProductListPanel" field="wasteProdProductList" colSpan="12" grid-view="prod-product-grid" form-view="prod-product-form"/>
				<panel name="descriptionPanel" title="Waste description" colSpan="12">
					<field name="wasteProdDescription" showTitle="false" colSpan="12"/>
				</panel>
			</panel>
			<panel name="costPanel" title="Cost" showIf="statusSelect &gt; 3">
                <button name="computeCostPriceBtn" title="Compute cost price" onClick="save,action-manuf-order-method-compute-cost-price"/>
                <field name="costPrice" readonly="true"/>
                <field name="costSheetList" colSpan="12" readonly="true" form-view="cost-sheet-bill-of-material-form" grid-view="cost-sheet-bill-of-material-grid"/>
			</panel>
			<panel name="notePanel" title="Note">
				<field name="note" colSpan="12" showTitle="false"/>
			</panel> 
		</panel-tabs>
		
		<panel-mail name="mailPanel">
		  <mail-messages limit="4" />
		  <mail-followers />
	  	</panel-mail>
		
	</form>
	
	<form title="Update planned quantities (Components and FP)" name="popup-manuf-order-form-update-planned-qty" model="com.axelor.apps.production.db.ManufOrder">
		<panel name="mainPanel">
			<field name="qty" min="1" colSpan="8"/>
			<button name="okBtn" colSpan="4" title="OK" onClick="save,action-manuf-order-method-update-planned-qty,close"/>
		</panel>
	</form>

	<form title="Update real quantities (Components and FP)" name="popup-manuf-order-form-update-real-qty" model="com.axelor.apps.production.db.ManufOrder">
		<panel name="mainPanel">
			<field name="$qtyToUpdate" title="Qty" min="0" type="decimal" colSpan="8"/>
			<button name="okBtn" colSpan="4" title="OK" onClick="save,action-manuf-order-method-update-real-qty,close"/>
		</panel>
	</form>
	
	<form name="manuf-order-cancel-wizard-form" model="com.axelor.apps.production.db.ManufOrder" title="Cancellation confirmation" >
		<panel name="mainPanel">
			<field name="cancelReason" domain="self.applicationType = :_xApplicationType" colOffset="4" colSpan="4" widget="SuggestBox" canNew="false" canEdit="false" onChange="action-attrs-sale-other-reason"/>
			<field name="cancelReasonStr" colOffset="4" colSpan="4" hidden="true"/>
			<button name="cancelConfirmBtn" title="Confirm cancellation" onClick="action-manuf-order-group-cancel-confirm" colOffset="4" colSpan="4"/>
		</panel>
    </form>

	<action-view name="action-manuf-order-update-planned-qty-popup-form-view" title="Update planned quantities (Components and FP)" model="com.axelor.apps.production.db.ManufOrder">
		<view type="form" name="popup-manuf-order-form-update-planned-qty"/>
		<view-param name="popup" value="reload"/>
		<view-param name="forceEdit" value="true"/>
		<view-param name="show-toolbar" value="false"/>
		<view-param name="show-confirm" value="false" />
		<view-param name="popup-save" value="false"/>
		<context name="_showRecord" expr="eval: id"/>
	</action-view>

	<action-view name="action-manuf-order-update-real-qty-popup-form-view" title="Update real quantities (Components and FP)" model="com.axelor.apps.production.db.ManufOrder">
		<view type="form" name="popup-manuf-order-form-update-real-qty"/>
		<view-param name="popup" value="reload"/>
		<view-param name="forceEdit" value="true"/>
		<view-param name="show-toolbar" value="false"/>
		<view-param name="show-confirm" value="false" />
		<view-param name="popup-save" value="false"/>
		<context name="_showRecord" expr="eval: id"/>
	</action-view>
	
	<action-view name="action-manuf-order-view-cancel" title="Cancellation" model="com.axelor.apps.production.db.ManufOrder">
	  	<view type="form" name="manuf-order-cancel-wizard-form"/>
	  	<view-param name="popup" value="reload"/>
	  	<view-param name="show-toolbar" value="false"/>
	  	<view-param name="show-confirm" value="false" />
  	  	<view-param name="popup-save" value="false"/>
	  	<view-param name="forceEdit" value="true" />
	  	<context name="_showRecord" expr="eval: __this__.id" />
        <context name="_xApplicationType" expr="eval: _model"/>
	</action-view>

	<action-method name="action-manuf-order-method-update-planned-qty">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="updatePlannedQty"/>
	</action-method>

	<action-method name="action-manuf-order-method-update-real-qty">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="updateRealQty"/>
	</action-method>

	<action-method name="action-manuf-order-method-consume-stock-move">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="consumeStockMove"/>
	</action-method>

	<action-method name="action-manuf-order-method-compute-cost-price">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="computeCostPrice"/>
	</action-method>

	<action-method name="action-manuf-order-method-is-to-invoice">
		<call class="com.axelor.apps.businessproduction.web.ManufOrderBusinessController" method="propagateIsToInvoice"/>
	</action-method>

    <action-record name="action-manuf-order-record-isConsProOnOperation" model="com.axelor.apps.production.db.ManufOrder">
    	<field name="isConsProOnOperation" expr="eval: prodProcess?.isConsProOnOperation"/>
    </action-record>
    
    <action-attrs name="action-manuf-order-attrs-isConsProOnOperation">
    	<attribute for="isConsProOnOperation" name="hidden" expr="eval: !(prodProcess?.isConsProOnOperation)"/>
    </action-attrs>
    
    <action-attrs name="action-manuf-order-attrs-sale-order-onselect">
	  <attribute if="clientPartner != null" name="domain" expr="self.clientPartner = :clientPartner AND self.statusSelect = 3" for="saleOrder"/>
	  <attribute if="clientPartner == null" name="domain" expr="self.statusSelect = 3" for="saleOrder"/>
	</action-attrs>
	
	<action-attrs name="action-manuf-order-attrs-set-unit">
		<attribute name="value" for="unit" expr="eval: billOfMaterial.unit"/>
	</action-attrs>
	
	<action-attrs name="action-manuf-order-atts-sale-order-onchange-client-partner">
	  <attribute name="value" expr="eval:null" for="saleOrder" if="saleOrder?.clientPartner != clientPartner"/>
	</action-attrs>

    <action-record name="action-manuf-order-record-client-partner-onchange-sale-order" model="com.axelor.apps.production.db.ManufOrder">
	  <field name="clientPartner" expr="eval: saleOrder?.clientPartner"/>
	</action-record>
    
    <action-record name="action-manuf-order-default-record" model="com.axelor.apps.production.db.ManufOrder">
    	<field name="statusSelect" expr="eval: 1"/>
    	<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="isPermanent" expr="eval: _createPermanent"/>
    	<field name="qty" expr="eval: 0" if="_createPermanent"/>
    	<field name="workshopStockLocation" expr="eval:__user__.workshopStockLocation" if="__config__.app.getApp('production').getManageWorkshop() &amp;&amp; __user__.workshopStockLocation != null"/>
    </action-record>

	<action-record name="action-manuf-order-record-update-qty-from-prod-process" model="com.axelor.apps.production.db.ManufOrder">
		<field name="qty" expr="eval: prodProcess.launchQty" if="prodProcess?.launchQty > 0"/>
	</action-record>

    <action-record name="action-manuf-order-on-change-bill-of-material" model="com.axelor.apps.production.db.ManufOrder">
        <field name="product" expr="eval:billOfMaterial.product" if="billOfMaterial != null"/>
        <field name="qty" if="billOfMaterial != null"
					expr="eval: (billOfMaterial.prodProcess?.launchQty &amp;&amp; billOfMaterial.prodProcess.launchQty > 0) ? billOfMaterial.prodProcess.launchQty : billOfMaterial.qty"/>
        <field name="prodProcess" expr="eval:billOfMaterial.prodProcess" if="billOfMaterial != null"/>
    </action-record>

	<action-record name="action-manuf-order-record-empty-workshop" model="com.axelor.apps.production.db.ManufOrder">
		<field name="workshopStockLocation" expr="eval: null"/>
	</action-record>

	<action-record name="action-manuf-order-record-workshop-onchange" model="com.axelor.apps.production.db.ManufOrder">
		<field name="prodProcess" expr="eval: null"/>
		<field name="billOfMaterial" expr="eval: null"/>
	</action-record>

	<action-group name="action-manuf-order-group-prod-process-onchange">
    <action name="action-manuf-order-attrs-isConsProOnOperation"/>
		<action name="action-manuf-order-record-isConsProOnOperation"/>
		<action name="action-manuf-order-record-update-qty-from-prod-process"/>
	</action-group>

	<action-group name="action-manuf-order-group-finish">
		<action name="action-businessproduction-manuf-order-method-check-timesheet" if="__config__.app.getApp('production')?.getEnableTimesheetOnManufOrder()"/>
		<action name="action-manuf-order-method-finish"/>
	</action-group>
    
    <action-group name="action-manuf-order-method-start-or-resume">
    	<action name="action-manuf-order-method-start" if="statusSelect == 3"/>
    	<action name="action-manuf-order-method-resume" if="statusSelect == 5"/>
    </action-group>

	<action-group name="action-manuf-order-group-onchange">
		<action name="action-manuf-order-on-change-bill-of-material"/>
        <action name="action-manuf-order-attrs-isConsProOnOperation"/>
		<action name="action-manuf-order-record-isConsProOnOperation"/>
        <action name="action-manuf-order-reset"/>
        <action name="action-manuf-order-attrs-set-unit"  if="billOfMaterial != null"/>
	</action-group>
	
	<action-group name="action-manuf-order-group-cancel-confirm">
		<action name="action-sale-order-cancel-reason-check" if="statusSelect > 3"/>
		<action name="action-manuf-order-method-cancel"/>
	</action-group>

    <action-method name="action-manuf-order-method-print">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="print"/>
	</action-method>

	<action-method name="action-production-process-method-print">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="printProdProcess"/>
	</action-method>
    
    <action-method name="action-manuf-order-method-start">
    	<call class="com.axelor.apps.production.web.ManufOrderController" method="start"/>
    </action-method>
    
    <action-method name="action-manuf-order-method-pause">
    	<call class="com.axelor.apps.production.web.ManufOrderController" method="pause"/>
    </action-method>
    
    <action-method name="action-manuf-order-method-resume">
    	<call class="com.axelor.apps.production.web.ManufOrderController" method="resume"/>
    </action-method>
    
    <action-method name="action-manuf-order-method-finish">
    	<call class="com.axelor.apps.production.web.ManufOrderController" method="finish"/>
    </action-method>
    
    <action-method name="action-manuf-order-method-cancel">
    	<call class="com.axelor.apps.production.web.ManufOrderController" method="cancel"/>
    </action-method>
    
    <action-method name="action-manuf-order-method-plan">
    	<call class="com.axelor.apps.production.web.ManufOrderController" method="plan"/>
    </action-method>

	<action-method name="action-manuf-order-method-part-finish">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="partialFinish"/>
	</action-method>

    <action-method name="action-manuf-order-method-pre-fill-operations">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="preFillOperations"/>
    </action-method>
    
    <action-method name="action-manuf-order-method-generate-waste-stock-move">
    	<call class="com.axelor.apps.production.web.ManufOrderController" method="generateWasteStockMove"/>
    </action-method>

	<action-method name="action-manuf-order-method-update-planned-dates">
    	<call class="com.axelor.apps.production.web.ManufOrderController" method="updatePlannedDates"/>
	</action-method>

	<action-method name="action-manuf-order-method-check-consumed-stock-move">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="checkConsumedStockMoveLineList"/>
	</action-method>

	<action-method name="action-manuf-order-method-update-consumed-stock-move">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="updateConsumedStockMoveFromManufOrder"/>
	</action-method>

	<action-method name="action-manuf-order-method-check-produced-stock-move">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="checkProducedStockMoveLineList"/>
	</action-method>

	<action-method name="action-manuf-order-method-update-produced-stock-move">
		<call class="com.axelor.apps.production.web.ManufOrderController" method="updateProducedStockMoveFromManufOrder"/>
	</action-method>

   	<action-view name="action-manuf-order-view-operation-order-to-consume-product" title="To consume products" model="com.axelor.apps.production.db.ProdProduct">
  		<view type="grid" name="prod-product-consume-manuf-order-grid"/>
		<view type="form" name="prod-product-form"/>
			<view-param name="popup" value="true"/>
  		<domain>self.toConsumeOperationOrder.manufOrder.id = :id</domain>
			<context name="companyIdFromParent" expr="eval: company.id"/>
  	</action-view>
  	
  	<action-view name="action-manuf-order-view-operation-order-diff-consume-product" title="Differences" model="com.axelor.apps.production.db.ProdProduct">
  		<view type="grid" name="prod-product-diff-manuf-order-grid"/>
		<view type="form" name="prod-product-form"/>
			<view-param name="popup" value="true"/>
  		<domain>self.diffConsumeOperationOrder.manufOrder.id = :id</domain>
			<context name="companyIdFromParent" expr="eval: company.id"/>
  	</action-view>
  	
  	<action-view name="action-manuf-order-view-operation-order-consumed-product" title="Consumed products" model="com.axelor.apps.stock.db.StockMoveLine">
  		<view type="grid" name="stock-move-line-consumed-production-grid"/>
		<view type="form" name="stock-move-line-production-form"/>
  		<domain>self.consumedOperationOrder.manufOrder.id = :id</domain>
  		<context name="id" expr="eval: id"/>
  	</action-view>
    
    <action-attrs name="action-manuf-order-reset">
   		<attribute name="value" for="operationOrderList" expr="eval: null"/>
   		<attribute name="value" for="toConsumeProdProductList" expr="eval: null"/>
   		<attribute name="value" for="toProduceProdProductList" expr="eval: null"/>
   	</action-attrs>

	<action-attrs name="action-manuf-order-attrs-filter-prodProcess">
		<attribute name="domain" for="prodProcess" expr="eval: &quot; (self.id = ${billOfMaterial?.prodProcess?.id} OR self.product.id = ${billOfMaterial?.product?.id}) AND self.statusSelect = 3 AND ((:workshopStockLocation IS NULL AND self.workshopStockLocation IS NULL) OR self.workshopStockLocation = :workshopStockLocation) &quot;" if="prodProcess != null &amp;&amp; billOfMaterial != null"/>
		<attribute name="domain" for="prodProcess" expr="eval: &quot; self.statusSelect = 3 AND ((:workshopStockLocation IS NULL AND self.workshopStockLocation IS NULL) OR self.workshopStockLocation = :workshopStockLocation) &quot;" if="billOfMaterial == null"/>
	</action-attrs>

	<action-attrs name="action-manuf-order-attrs-filter-product">
		<attribute name="domain" for="product" expr="eval: &quot; self.productTypeSelect = 'storable' AND (self.productSubTypeSelect = 1 OR self.productSubTypeSelect = 2) AND self.defaultBillOfMaterial.product.id = '${billOfMaterial?.product?.id}' AND self.defaultBillOfMaterial.prodProcess.id = '${prodProcess?.id}' &quot;" if="billOfMaterial?.product != null &amp;&amp; prodProcess != null"/>
		<attribute name="domain" for="product" expr="eval: &quot; self.productTypeSelect = 'storable' AND (self.productSubTypeSelect = 1 OR self.productSubTypeSelect = 2) AND self.defaultBillOfMaterial.product.id = '${billOfMaterial?.product?.id}' &quot;" if="billOfMaterial?.product != null &amp;&amp; prodProcess == null"/>
		<attribute name="domain" for="product" expr="eval: &quot; self.productTypeSelect = 'storable' AND (self.productSubTypeSelect = 1 OR self.productSubTypeSelect = 2) AND self.defaultBillOfMaterial.prodProcess.id = '${prodProcess?.id}' &quot;" if="billOfMaterial?.product == null &amp;&amp; prodProcess != null"/>
		<attribute name="domain" for="product" expr="eval: &quot; self.productTypeSelect = 'storable' AND (self.productSubTypeSelect = 1 OR self.productSubTypeSelect = 2) &quot;" if="billOfMaterial?.product == null &amp;&amp; prodProcess == null"/>
	</action-attrs>

	<action-attrs name="action-manuf-order-attrs-filter-bill-of-material">
		<attribute name="domain" for="billOfMaterial" expr="eval: &quot; self.defineSubBillOfMaterial = true AND self.product.id = ${product?.id} &quot;" if="product != null"/>
		<attribute name="domain" for="billOfMaterial" expr="eval: &quot; self.defineSubBillOfMaterial = true &quot;" if="product == null"/>
	</action-attrs>

	<action-attrs name="action-manuf-order-attrs-price-digits">
		<attribute name="scale" for="costPrice" expr="eval: __config__.app.getNbDecimalDigitForUnitPrice()"/>
		<attribute name="value" for="$totalPlannedDuration" expr="eval: operationOrderList.collect{it->it.plannedDuration}.sum()" if="operationOrderList != null &amp;&amp; !operationOrderList.isEmpty()"/>
		<attribute name="value" for="$totalRealDuration" expr="eval: operationOrderList.collect{it->it.realDuration}.sum()" if="operationOrderList != null &amp;&amp; !operationOrderList.isEmpty()"/>
	</action-attrs>

	<action-validate name="action-manuf-order-validate-planned-end-date"
	   model="com.axelor.apps.production.db.ManufOrder">
	   <alert message="The planned end date is inferior to the actual date"
	       if="plannedEndDateT.isBefore(__config__.app.getTodayDateTime().toLocalDateTime())"/>
	</action-validate>

  	<search-filters name="manuf-order-filters" model="com.axelor.apps.production.db.ManufOrder" title="Manufacturing order filters">
		<filter title="Draft MOs">
			<domain>self.statusSelect = 1</domain>
		</filter>
		<filter title="Planned MOs">
			<domain>self.statusSelect = 3</domain>
		</filter>
		<filter title="MOs In Progress">
			<domain>self.statusSelect = 4</domain>
		</filter>
		<filter title="MOs In Standby">
			<domain>self.statusSelect = 5</domain>
		</filter>
		<filter title="Finished MOs">
			<domain>self.statusSelect = 6</domain>
		</filter>
		<filter title="MOs to invoice">
			<domain>self.isToInvoice = true</domain>
		</filter>
		<filter title="Cancelled MOs">
			<domain>self.statusSelect = 2</domain>
		</filter>
		<filter title="Late Planned MOs">
			<domain>self.statusSelect = 3 AND self.plannedStartDateT &lt; :_todayDateTime</domain>
		</filter>
		<filter title="MOs Finished late">
			<domain>self.statusSelect = 6 AND self.plannedEndDateT &lt; self.realEndDateT</domain>
		</filter>
	</search-filters>
    
</object-views>
