<?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">

    <form name="sale-order-line-form" id="supplychain-sale-order-line-form" title="SO line"
        model="com.axelor.apps.sale.db.SaleOrderLine" onNew="action-group-sale-saleorderline-onnew,action-record-sale-order-line-fill-request-qty"
		onLoad="action-group-sale-saleorderline-onload,action-sale-order-line-attrs-hidden-fields-for-client"
        width="large">
        <panel-include view="sale-order-line-form" from="axelor-sale" />
    </form>


	<form name="allocated-qty-sale-order-line-form" title="Change allocated qty"
		  model="com.axelor.apps.sale.db.SaleOrderLine">
        <panel name="mainPanel">
			<field name="reservedQty" onChange="action-supplychain-attrs-sale-order-line-max-reserved-qty"/>
			<button name="confirmNewReservationBtn" title="OK"
					onClick="action-method-sale-order-line-change-reserved-qty,close"/>
			<field name="qty" hidden="true"/>
		</panel>
	</form>

	<form name="requested-reserved-qty-sale-order-line-form" title="Change reserved qty"
		model="com.axelor.apps.sale.db.SaleOrderLine">
		<panel>
			<field name="requestedReservedQty" onChange="action-supplychain-attrs-sale-order-line-max-requested-reserved-qty"/>
			<button name="confirmNewReservationBtn" title="OK"
				onClick="action-method-sale-order-line-change-requested-reserved-qty,close"/>
			<field name="qty" hidden="true"/>
		</panel>
	</form>


	<action-method name="action-method-sale-order-line-available-and-allocated-stock" model="com.axelor.apps.sale.db.SaleOrderLine">
		<call class="com.axelor.apps.supplychain.web.SaleOrderLineController" method="fillAvailableAndAllocatedStock"/>
	</action-method>

	<action-method name="action-method-sale-order-line-change-reserved-qty">
		<call class="com.axelor.apps.supplychain.web.SaleOrderLineController" method="changeReservedQty"/>
	</action-method>

  <action-method name="action-supplychain-sale-order-line-allocate-all">
		<call class="com.axelor.apps.supplychain.web.SaleOrderLineController" method="allocateAll"/>
  </action-method>

  <action-method name="action-supplychain-sale-order-line-deallocate-all">
		<call class="com.axelor.apps.supplychain.web.SaleOrderLineController" method="deallocateAll"/>
  </action-method>

	<action-method name="action-method-sale-order-line-change-requested-reserved-qty">
		<call class="com.axelor.apps.supplychain.web.SaleOrderLineController" method="changeRequestedReservedQty"/>
	</action-method>
	
	<action-method name="action-sale-order-line-method-check-delivered-or-invoiced-order-qty">
		<call class="com.axelor.apps.supplychain.web.SaleOrderLineController" method="checkInvoicedOrDeliveredOrderQty"/>
	</action-method>

	<action-method name="action-method-sale-order-line-request-qty">
		<call class="com.axelor.apps.supplychain.web.SaleOrderLineController" method="requestQty"/>
	</action-method>

	<action-method name="action-method-sale-order-line-cancel-reservation">
		<call class="com.axelor.apps.supplychain.web.SaleOrderLineController" method="cancelReservation"/>
	</action-method>

	<action-record name="action-sale-order-line-record-update-requested-reserved-qty-from-qty" model="com.axelor.apps.sale.db.SaleOrderLine">
    <field name="requestedReservedQty" expr="eval: BigDecimal.ZERO.max(qty)" if="requestedReservedQty &gt; qty || isQtyRequested"/>
	</action-record>

	<action-attrs name="action-supplychain-sale-order-line-attrs-hide-button">
		<attribute for="updateAllocatedQtyBtn" name="hidden" expr="eval: id == null || __parent__.statusSelect != 3" if="__parent__"/>
    <attribute for="updateAllocatedQtyBtn" name="hidden" expr="eval: id == null || saleOrder.statusSelect != 3" if="saleOrder"/>
	</action-attrs>

	<action-attrs name="action-supplychain-attrs-sale-order-line-max-requested-reserved-qty">
		<attribute for="requestedReservedQty" name="value" expr="eval: qty" if="requestedReservedQty &gt; qty"/>
	</action-attrs>

	<action-attrs name="action-supplychain-attrs-sale-order-line-max-reserved-qty">
		<attribute for="reservedQty" name="value" expr="eval: qty" if="reservedQty &gt; qty"/>
	</action-attrs>
  
  <action-attrs name="action-sale-order-line-attrs-reserved-qty-visibility">
		<attribute for="reservedQty" name="hidden" expr="eval: __parent__.statusSelect != 3" if="__parent__"/>
		<attribute for="reservedQty" name="hidden" expr="eval: saleOrder.statusSelect != 3" if="saleOrder"/>
  </action-attrs>

  <action-attrs name="action-sale-order-line-attrs-is-requested-qty-readonly">
    <attribute for="requestedReservedQty" name="readonly" expr="eval: isSubLine || __parent__.statusSelect &gt; 2" if="__parent__"/>
    <attribute for="requestedReservedQty" name="readonly" expr="eval: isSubLine || saleOrder.statusSelect &gt; 2" if="saleOrder"/>
  </action-attrs>

	<action-view name="action-view-sale-order-line-allocated-qty-wizard" title="Change allocated qty"
		model="com.axelor.apps.sale.db.SaleOrderLine">
		<view type="form" name="allocated-qty-sale-order-line-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: id"/>
	</action-view>

	<action-view name="action-view-sale-order-line-requested-reserved-qty-wizard"
		title="Change requested reserved qty" model="com.axelor.apps.sale.db.SaleOrderLine">
		<view type="form" name="requested-reserved-qty-sale-order-line-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: id"/>
	</action-view>

	<action-view name="action-view-sale-order-line-view-planned-stock-move-lines" title="Planned stock move lines" model="com.axelor.apps.stock.db.StockMoveLine">
		<view type="grid" name="stock-move-line-all-grid-planned"/>
		<view type="form" name="stock-move-line-all-form"/>
		<view-param name="popup" value="true"/>
		<domain>self.stockMove.statusSelect = 2 AND self.product.id = :productId AND (self.stockMove.fromStockLocation.id = :locationId OR self.stockMove.toStockLocation.id = :locationId)</domain>
		<context name="productId" expr="eval: product?.id"/>
		<context name="locationId" expr="eval: __parent__.stockLocation?.id"/>
	</action-view>

	<action-record name="action-record-sale-order-line-future-qty" model="com.axelor.apps.sale.db.SaleOrderLine">
		<field name="$futureQtyBtn" expr="call:com.axelor.apps.stock.service.StockLocationService:getFutureQty(product.id, __parent__.stockLocation.id, null)"/>
	</action-record>

  <action-record name="action-record-sale-order-line-fill-request-qty" model="com.axelor.apps.sale.db.SaleOrderLine">
    <field name="isQtyRequested" expr="eval: __parent__?.company?.supplyChainConfig?.autoRequestReservedQty"/>
    <field name="requestedReservedQty" expr="eval: qty" if="__parent__?.company?.supplyChainConfig?.autoRequestReservedQty"/>
  </action-record>

</object-views>	
