<?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="advance-payment-grid" title="Advance Payments" model="com.axelor.apps.sale.db.AdvancePayment" orderBy="advancePaymentDate">
   	    <field name="advancePaymentDate"/>
	    <field name="amount"/>
	    <field name="currency" form-view="currency-form" grid-view="currency-grid"/>
	    <field name="paymentMode" if-module="axelor-supplychain" form-view="payment-mode-form" grid-view="payment-mode-grid" if="__config__.app.isApp('supplychain')" /> 
	    <field name="statusSelect"/>
   		<button name="cancelBtn" icon="fa-times-circle" onClick="action-advance-payment-method-cancel" readonlyIf="statusSelect == 2"/>
	</grid>
    
	<form name="advance-payment-form" title="Advance Payment" model="com.axelor.apps.sale.db.AdvancePayment" onNew="action-advance-payment-record-new">
		<panel name="mainPanel" readonlyIf="id">
			<field name="amount" onChange="action-advance-payment-record-change-amount" required="true"/>
			<field name="currency" canEdit="false" form-view="currency-form" grid-view="currency-grid" required="true"/>
			<field name="advancePaymentDate" required="true"/> 
			<field name="amountRemainingToUse" if-module="axelor-supplychain" if="__config__.app.isApp('supplychain')" /> 
	    	<field name="paymentMode" form-view="payment-mode-form" grid-view="payment-mode-grid" required="true" if-module="axelor-supplychain" if="__config__.app.isApp('supplychain')" /> 
	 	</panel>
	 	<panel showIf="id" name="otherDetailsPanel">
  	    	<field name="move" form-view="move-form" grid-view="move-grid"/>
			<field name="statusSelect"/>
   			<button name="cancelBtn" icon="fa-times-circle" onClick="action-advance-payment-method-cancel" readonlyIf="statusSelect == 2"/>
	 	</panel>
	</form>
	
	
	<action-record name="action-advance-payment-record-new" model="com.axelor.apps.sale.db.AdvancePayment">
    	<field name="currency" expr="eval: _saleOrder?.currency"/>
    	<field name="advancePaymentDate" expr="eval: __date__"/>
    	<field name="saleOrder" expr="eval: _saleOrder"/>
    	<field name="paymentMode" expr="eval: _saleOrder?.paymentMode"/>
    </action-record>
  
    <action-record name="action-advance-payment-record-change-amount" model="com.axelor.apps.sale.db.AdvancePayment">
    	<field name="amountRemainingToUse" expr="eval: amount" /> 
    </action-record>

    <action-method name="action-advance-payment-method-cancel">
        <call class="com.axelor.apps.sale.web.AdvancePaymentController" method="cancelAdvancePayment"/>
    </action-method>
    
</object-views>
	