<?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="sale-order-quotation-grid" title="Sale quotations" model="com.axelor.apps.sale.db.SaleOrder" orderBy="-creationDate">
		<menubar>
		    <menu name="saleOrderReportsMenu" title="Reports" icon="fa-files-o" showTitle="true">
	        <item name="printItem" title="Print" action="action-sale-order-method-show-sale-order"/>
		    </menu>
		    <menu name="saleOrderToolsMenu" title="Tools" icon="fa-wrench" showTitle="true">
		      <item name="mergeQuotationsItem" title="Merge quotations" action="action-open-sale-quotation-merge-form"/>
		      <item name="seeQuotationLinesItem" title="See quotation lines" action="action-view-open-quotation-lines"/>
		    </menu>
		</menubar>
		<hilite background="warning" if="(endOfValidityDate != null) &amp;&amp; ($moment(endOfValidityDate) &lt; $moment(todayDate)) &amp;&amp; (statusSelect == 3)"/>
		<hilite background="danger" if="(endOfValidityDate != null) &amp;&amp; ($moment(endOfValidityDate) &lt; $moment(todayDate)) &amp;&amp; (statusSelect == 2)"/>
	  <field name="endOfValidityDate" hidden="true"/>
	  <field name="saleOrderSeq" width="120"/>
	  <field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="stockLocation" if="__config__.app.isApp('supplychain')"/>
		<field name="tradingName" form-view="trading-name-form" grid-view="trading-name-grid" if="__config__.app.getApp('base').enableTradingNamesManagement"/>
	  <field name="clientPartner" form-view="partner-form" grid-view="partner-grid"/>
	  <field name="externalReference"/>
	  <field name="creationDate"/>
	  <field name="exTaxTotal" aggregate="sum"/>
	  <field name="inTaxTotal" aggregate="sum"/>
	  <field name="currency" form-view="currency-form" grid-view="currency-grid"/>
	  <field name="statusSelect"/>
	  <button name="printBtn" title="Print" icon="fa-print" onClick="action-sale-order-method-show-sale-order"/>
	  <button name="sendByEmailBtn" title="Send email" icon="fa-envelope" onClick="action-send-by-email-with-template"/>
  </grid>

	<grid name="sale-order-grid" title="Sale orders" model="com.axelor.apps.sale.db.SaleOrder" orderBy="-creationDate">
	  <menubar>
	    <menu name="saleOrderReportsMenu" title="Reports" icon="fa-files-o" showTitle="true">
        <item name="printItem" title="Print" action="action-sale-order-method-show-sale-order"/>
	    </menu>
	    <menu name="saleOrderToolsMenu" title="Tools" icon="fa-wrench" showTitle="true">
        <item name="seeSaleOrderLinesItem" title="See sale orders lines" action="action-view-open-sale-order-lines"/>
	    </menu>
	  </menubar>
		<hilite background="warning" if="(endOfValidityDate != null) &amp;&amp; ($moment(endOfValidityDate) &lt; $moment(todayDate)) &amp;&amp; (statusSelect == 3)" />
		<hilite background="danger" if="(endOfValidityDate != null) &amp;&amp; ($moment(endOfValidityDate) &lt; $moment(todayDate)) &amp;&amp; (statusSelect == 2)" />
		<field name="endOfValidityDate" hidden="true" />
		<field name="saleOrderSeq" width="120"/>
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="stockLocation" if="__config__.app.isApp('supplychain')"/>
    <field name="tradingName" form-view="trading-name-form" grid-view="trading-name-grid" if="__config__.app.getApp('base').enableTradingNamesManagement"/>
		<field name="clientPartner" form-view="partner-form" grid-view="partner-grid" />
		<field name="externalReference" />
		<field name="confirmationDateTime" />
		<field name="exTaxTotal" aggregate="sum" />
		<field name="inTaxTotal" aggregate="sum" />
		<field name="amountInvoiced" hidden="true" aggregate="sum" if="__config__.app.isApp('supplychain')"/>
		<field name="currency" form-view="currency-form" grid-view="currency-grid" />
		<field name="deliveryState" if="__config__.app.isApp('supplychain')" />
		<field name="statusSelect" />
		<field name="salemanUser"/>
		<button name="printBtn" title="Print" icon="fa-print" onClick="action-sale-order-method-show-sale-order" />
		<button name="sendByEmailBtn" title="Send email" icon="fa-envelope" onClick="action-send-by-email-with-template" />
	</grid>

	<grid name="sale-order-partner-grid" title="Sale orders" model="com.axelor.apps.sale.db.SaleOrder" orderBy="-creationDate">
    <menubar>
      <menu name="saleOrderReportsMenu" title="Reports" icon="fa-files-o" showTitle="true">
        <item name="printItem" title="Print" action="action-sale-order-method-show-sale-order"/>
      </menu>
      <menu name="saleOrderToolsMenu" title="Tools" icon="fa-wrench" showTitle="true">
        <item name="seeSaleOrderLinesItem" title="See sale orders lines" action="action-view-open-sale-order-lines"/>
      </menu>
    </menubar>
		<field name="saleOrderSeq" width="120" />
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="tradingName" form-view="trading-name-form" grid-view="trading-name-grid" if="__config__.app.getApp('base').enableTradingNamesManagement"/>
    <field name="externalReference"/>
    <field name="creationDate"/>
    <field name="exTaxTotal" aggregate="sum"/>
    <field name="inTaxTotal" aggregate="sum"/>
		<field name="externalReference"/>
		<field name="statusSelect"/>
    <button name="printBtn" title="Print" icon="fa-print" onClick="action-sale-order-method-show-sale-order"/>
    <button name="sendByEmailBtn" title="Send email" icon="fa-envelope" onClick="action-send-by-email-with-template"/>
  </grid>

    <grid name="sale-order-opportunity-grid" title="Sale quotations" model="com.axelor.apps.sale.db.SaleOrder" orderBy="-creationDate">
        <hilite background="warning" if="(endOfValidityDate != null) &amp;&amp; ($moment(endOfValidityDate) &lt; $moment(todayDate)) &amp;&amp; (statusSelect == 3)"/>
        <hilite background="danger" if="(endOfValidityDate != null) &amp;&amp; ($moment(endOfValidityDate) &lt; $moment(todayDate)) &amp;&amp; (statusSelect == 2)"/>
        <field name="endOfValidityDate" hidden="true"/>
        <field name="saleOrderSeq" width="120"/>
        <field name="creationDate"/>
		<field name="exTaxTotal" aggregate="sum"/>
        <field name="inTaxTotal" aggregate="sum"/>
		<field name="currency" form-view="currency-form" grid-view="currency-grid"/>
		<field name="statusSelect" />
		<button name="printBtn" title="Print" icon="fa-print"
			onClick="action-sale-order-method-show-sale-order" />
		<button name="sendByEmailBtn" title="Send email" icon="fa-envelope"
			onClick="action-send-by-email-with-template" />
	</grid>

    <calendar name="sale-order-calendar" model="com.axelor.apps.sale.db.SaleOrder" eventStart="creationDate"
        eventLength="24" mode="month" title="Sale quotations/orders" colorBy="statusSelect" editable="false">
        <field name="fullName" />
    </calendar>

    <form name="sale-order-merge-form" model="com.axelor.apps.base.db.Wizard" title="Merge sale orders" width="large">
		<panel-related name="saleOrderToMergePanel" field="$saleOrderToMerge" form-view="sale-order-form" title="Sale orders to merge" colSpan="12" type="many-to-many" target="com.axelor.apps.sale.db.SaleOrder" domain="self.statusSelect = 1" canNew="false" canEdit="false" grid-view="sale-order-grid"/>
		<panel name="actionsPanel" sidebar="true" title="Actions">
			<button name="generateMergedSaleOrderBtn" title="Merge into single sale order" onClick="action-validate-sale-order-check-selection,action-group-sale-order-merge-action"/>
	  	</panel>
    </form>

    <form name="sale-quotation-merge-form" model="com.axelor.apps.base.db.Wizard" title="Merge quotations" width="large">
		<panel-related name="saleQuotationToMergePanel" field="$saleQuotationToMerge" form-view="sale-order-form" title="Quotations to merge" colSpan="12" type="many-to-many" target="com.axelor.apps.sale.db.SaleOrder" domain="self.statusSelect = 1" canNew="false" canEdit="false" grid-view="sale-order-quotation-grid"/>
		<panel name="actionsPanel" sidebar="true" title="Actions">
			<button name="generateMergedSaleOrderBtn" title="Merge into single quotation" onClick="action-validate-sale-quotation-check-selection,action-group-sale-order-merge-action"/>
	  	</panel>
    </form>

    <form name="sale-order-merge-confirm-form" model="com.axelor.apps.base.db.Wizard" title="Confirmation" onNew="action-record-load-dummy-field-confirm-merge-saleorder">
		<panel name="mainPanel" colSpan="6" colOffset="3">
            <field name="priceListToCheck" hidden="true" colSpan="12" />
            <field name="locationToCheck" hidden="true" colSpan="12" />
            <field name="contactPartnerToCheck" hidden="true" colSpan="12" />
			<field name="$priceList" title="Price List" type="many-to-one" target="com.axelor.apps.base.db.PriceList" domain="self.typeSelect = 2 and self.isActive = true" colSpan="6" colOffset="3" width="200px" showIf="priceListToCheck" canSelect="true" form-view="price-list-form" grid-view="price-list-grid"/>
			<field name="$stockLocation" canEdit="false" title="Stock location" showIf="locationToCheck" if-module="axelor-supplychain" colSpan="6" colOffset="3" width="200px" type="many-to-one" canSelect="true" target="com.axelor.apps.stock.db.StockLocation" domain="self.company = company and self.typeSelect = 1" form-view="stock-location-form" grid-view="stock-location-grid" if="__config__.app.isApp('supplychain')" />
			<field name="$contactPartner" title="Contact partner" type="many-to-one" target="com.axelor.apps.base.db.Partner" domain="self.isContact IS TRUE AND EXISTS (SELECT 1 FROM Partner part WHERE part.id = :partnerId AND self.id IN (SELECT id FROM part.contactPartnerSet))" colSpan="6" colOffset="3" width="200px" widget="SuggestBox" showIf="contactPartnerToCheck" form-view="partner-contact-form" grid-view="partner-contact-grid"/>
			<button name="confirmBtn" title="Confirmer" onClick="action-group-sale-order-merge-action" colSpan="12" width="200px"/>
		</panel>
    </form>

	<form name="sale-order-template-wizard-form" model="com.axelor.apps.base.db.Wizard" title="Create the quotation" onNew="action-sale-order-attrs-template-deafult-currency,action-sale-order-method-fill-price-list">
		<panel name="mainPanel">
			<field name="currency" type="many-to-one" target="com.axelor.apps.base.db.Currency" title="Currency" required="true" form-view="currency-form" grid-view="currency-grid"/>
			<field name="priceList" type="many-to-one" target="com.axelor.apps.base.db.PriceList" title="Price list" onSelect="action-sale-order-method-price-list-domain" form-view="price-list-form" grid-view="price-list-grid"/>
			<button name="createOrderFromTemplateBtn" title="Create Order from this Template" onClick="action-sale-order-method-generate-order" readonlyIf="!currency" colSpan="4"/>
		</panel>
	</form>

    <form name="sale-order-cancel-wizard-form" model="com.axelor.apps.sale.db.SaleOrder" 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-sale-order-cancel-reason-check,action-sale-order-method-confirm-cancel" colOffset="4" colSpan="4"/>
		</panel>
    </form>

    <form name="sale-order-form-wizard" title="Sale order" model="com.axelor.apps.sale.db.SaleOrder"
		onNew="action-group-sale-saleorder-onnew,action-sale-order-method-create-order,action-sale-order-record-hide-discount"
		onLoad="action-group-sale-saleorder-onload">

		<panel-include view="sale-order-form"/>
	</form>

	<form name="sale-order-form-partner" title="Sale order" model="com.axelor.apps.sale.db.SaleOrder"
	onNew="action-group-sale-saleorder-onnew,action-group-partner-saleorder-onnew"
	onLoad="action-group-sale-saleorder-onload">

		<panel-include view="sale-order-form"/>
	</form>

	<form id="sale-order-form" name="sale-order-form" title="Sale order" model="com.axelor.apps.sale.db.SaleOrder" onLoad="action-group-sale-saleorder-onload" onNew="action-group-sale-saleorder-onnew">
	  <menubar>
	    <menu name="saleOrderReportsMenu" title="Reports">
	      <item name="printItem" title="Print" hideIf="clientPartner == null" action="save,action-sale-order-method-show-sale-order"/>
	      <item name="printProformaInvoiceItem" title="Print proforma invoice" hideIf="clientPartner == null" action="save,action-sale-order-method-print-proforma-invoice"/>
	      <item name="excelExportItem" title="Excel Export" hideIf="clientPartner == null" action="save,action-sale-order-method-export-sale-order-excel"/>
	      <item name="wordExportItem" title="Word Export" hideIf="clientPartner == null" action="save,action-sale-order-method-export-sale-order-word"/>
	    </menu>
	    <menu name="saleOrderToolsMenu" title="Tools">
	      <item name="scheduleEventItem" title="Schedule Event" hideIf="clientPartner == null" action="action-sale-order-view-schedule-event"/>
	      <item name="sendEmailItem" title="Send email" hideIf="clientPartner == null" action="save,action-send-by-email-with-template"/>
	      <item name="defineAsTemplateItem" title="Define as template" hideIf="clientPartner == null" action="save,action-sale-order-method-generate-template"/>
          <item name="allocateAllItem" title="Allocate all" action="save,action-sale-order-method-allocate-all" showIf="statusSelect == 3 &amp;&amp; !orderBeingEdited" if="__config__.app.getApp('supplychain')?.manageStockReservation"/>
          <item name="deallocateAllItem" title="Deallocate all" action="save,action-sale-order-method-deallocate-all" showIf="statusSelect == 3 &amp;&amp; !orderBeingEdited" if="__config__.app.getApp('supplychain')?.manageStockReservation"/>
		  <item name="reserveAllItem" title="Reserve all" action="save,action-sale-order-method-reserve-all" showIf="statusSelect == 3 &amp;&amp; !orderBeingEdited" if="__config__.app.getApp('supplychain')?.manageStockReservation"/>
          <item name="cancelReservationItem" title="Cancel reservation" action="save,action-sale-order-method-cancel-reservation" showIf="statusSelect == 3 &amp;&amp; !orderBeingEdited" if="__config__.app.getApp('supplychain')?.manageStockReservation"/>
	    </menu>
	  </menubar>
	  <panel name="mainPanel">
	    <panel name="blockedCustCreditExceedPanel" colSpan="12">
	      <field name="blockedOnCustCreditExceed" showTitle="false" readonly="true" showIf="blockedOnCustCreditExceed &amp;&amp; !manualUnblock" colSpan="4">
	        <viewer depends="blockedOnCustCreditExceed"><![CDATA[
	          <h5>
	            <span class="label label-default" style="background-color: #B6473F; margin: 0px 0 !important; display: inline-table; line-height: initial;" ng-show="record.blockedOnCustCreditExceed" x-translate>Blocked</span>
	          </h5>
	        ]]></viewer>
	      </field>
	      <button name="manualUnblockBtn" title="Manual Unblock" showIf="blockedOnCustCreditExceed == true &amp;&amp; manualUnblock == false" colSpan="4" css="btn-custom" onClick="action-sale-order-manual-unblock"/>
	      <field name="manualUnblock" hidden="true"/>
	      <field name="orderBeingEdited" hidden="true"/>
	      <field name="$viewerOrderBeingEdited" showTitle="false" readonly="true" showIf="orderBeingEdited" colSpan="9">
	        <viewer depends="orderBeingEdited"><![CDATA[
	          <h4>
	            <span class="label label-important" ng-show="record.orderBeingEdited" x-translate>Order being edited</span>
	          </h4>
	        ]]></viewer>
	      </field>
	      <field name="$viewerOrderRequiresAdvancePayment" showTitle="false" readonly="true" showIf="(statusSelect == 2 &amp;&amp; advancePaymentNeeded) &amp;&amp; $number(advanceTotal) &lt; $number(advancePaymentAmountNeeded)" colSpan="6">
		      	<viewer><![CDATA[
		      	<h4>
		        	<span class="label label-important" x-translate>Advance payment needed</span>
		      	</h4>
		    	]]></viewer>
		   </field>
	    </panel>
	    <field name="statusSelect" showTitle="false" colSpan="12" widget="NavSelect"/>
	    <field name="saleOrderSeq" showTitle="false">
		    <viewer depends="statusSelect,saleOrderSeq"><![CDATA[
		      <h3>
		        <span ng-show="[1,2,5].includes(record.statusSelect) &amp;&amp; record.saleOrderSeq" x-translate>Quotation</span>
		        <span ng-show="[3,4].includes(record.statusSelect)" x-translate>Sale order</span>
		        {{record.saleOrderSeq}}
		      </h3>
		    ]]></viewer>
		  </field>
	    <panel name="detailsPanel" colSpan="12">
	      <field name="saleOrderTypeSelect" colSpan="3" css="label-bold bold" showTitle="false" readonlyIf="statusSelect >= 2" if="__config__.app.isApp('supplychain') &amp;&amp; __config__.app.getApp('supplychain').getAllowSusbcriptionSaleOrder()" if-module="axelor-supplychain">
	        <viewer><![CDATA[
	          <div>
	            <div class="span7">
	              <h5>
	                <span class="label label-info">
	                <span ng-show="record.saleOrderTypeSelect == 1" x-translate>Standard</span>
	                <span ng-show="record.saleOrderTypeSelect == 2" x-translate>Subscription</span>
	              </h5>
	            </div>
	          </div>
	        ]]></viewer>
	      </field>
	      <field name="$invoicingState" showTitle="false" readonly="true" showIf="statusSelect >= 3" css="label-bold bold" colSpan="3">
	        <viewer depends="amountInvoiced,exTaxTotal"><![CDATA[
	        <div>
	        <div class="span7">
	          <h5>
	          <span class="label label-important" ng-show="record.amountInvoiced == 0"  x-translate>Not invoiced</span>
	          <span class="label label-warning" ng-show="record.amountInvoiced > 0 && $number(record.amountInvoiced) < $number(record.exTaxTotal)" x-translate>Partially invoiced</span>
	          <span class="label label-success" ng-show="record.amountInvoiced > 0 && $number(record.amountInvoiced) >= $number(record.exTaxTotal)" x-translate>Invoiced</span>
	        </h5>
	        </div>
	      </div>
	      ]]></viewer>
	      </field>
	      <field if="__config__.app.isApp('supplychain')" if-module="axelor-supplychain" showTitle="false" name="deliveryState" showIf="statusSelect >= 3" css="label-bold bold" colSpan="3">
	        <viewer><![CDATA[
	        <div>
	        <div class="span7">
	        <h5>
	          <span class="label label-important" ng-show="record.deliveryState == 1" x-translate>Not delivered</span>
	          <span class="label label-warning" ng-show="record.deliveryState == 2" x-translate>Partially delivered</span>
	          <span class="label label-success" ng-show="record.deliveryState == 3" x-translate>Delivered</span>
	        </h5>
	        </div>
	      </div>
	      ]]></viewer>
	      </field>
	      <field name="availabilityRequestLabel" colSpan="3" css="label-bold bold" showTitle="false" readonly="true" hidden="true">
	        <viewer><![CDATA[
	          <div>
	            <div class="span7">
	              <h5>
	                <span class="label label-important">
	                <span x-translate>Availability Request</span>
	              </h5>
	            </div>
	          </div>
	        ]]></viewer>
	      </field>
	  	</panel>
	    <panel name="generalInfoPanel" colSpan="12">
	      <field name="company" readonlyIf="statusSelect == 3 || clientPartner != null" widget="SuggestBox" canEdit="false" onChange="action-sale-group-onchange-company" form-view="company-form" grid-view="company-grid" colSpan="3"/>
	      <field if="__config__.app.getApp('base').enableTradingNamesManagement" name="tradingName" readonlyIf="statusSelect >= 2" canEdit="false" onChange="action-sale-method-printing-settings-default-values" domain=":company MEMBER OF self.companySet" form-view="trading-name-form" grid-view="trading-name-grid" colSpan="3"/>
	      <label name="tradingNameLabel" if="!(__config__.app.getApp('base').enableTradingNamesManagement)" colSpan="3" />
	      <field name="currency" required="true" readonlyIf="saleOrderLineList.length > 0 || statusSelect >= 2" canEdit="false" form-view="currency-form" grid-view="currency-grid" colSpan="3"/>
	      <field name="priceList" readonlyIf="saleOrderLineList.length > 0 || statusSelect >= 2" onChange="action-sale-order-record-hide-discount" onSelect="action-sale-order-method-price-list-domain" canEdit="false" form-view="price-list-form" grid-view="price-list-grid" hideIf="company == null" colSpan="3"/>
	       <field name="clientPartner" required="true"  hideIf="company == null" readonlyIf="statusSelect > 1" onChange="action-sale-order-group-client-partner-change,action-sale-order-record-compute-end-of-validity-date" onSelect="action-sale-order-method-set-client-partner-domain" form-view="partner-form" grid-view="partner-grid" colSpan="3"/>
	      <field name="contactPartner" colSpan="3" hideIf="company == null" onChange="action-record-so-contact-partner-change" onSelect="action-sale-order-domain-on-contact-partner" domain="self.isContact = true" canEdit="false" form-view="partner-contact-form" grid-view="partner-contact-grid"/>
	      <field if="__config__.app.getApp('sale').getManageSaleOrderVersion()" name="versionNumber" colSpan="3"/>
	      <field if="__config__.app.isApp('supplychain')" if-module="axelor-supplychain" colSpan="3" name="directOrderLocation" onChange="action-sale-order-record-direct-order-location-onchange" widget="boolean-switch"/>
	      <panel name="otherInfoPanel" colSpan="3">
	        <field name="inAti" hidden="true" readonlyIf="saleOrderLineList.length > 0 || statusSelect &gt;= 2" onChange="action-sale-order-attrs-in-ati" widget="boolean-switch"/>
	        <field if="__config__.app.isApp('supplychain')" if-module="axelor-supplychain" hidden="true" colSpan="6" name="interco" widget="boolean-switch"/>
	        <field if="__config__.app.isApp('supplychain')" if-module="axelor-supplychain" colSpan="6" readonly="true" showIf="createdByInterco" name="createdByInterco"/>
	    	</panel>
	    </panel>
	    <panel name="addressPanel" colSpan="12" hideIf="company == null">
	      <panel name="mainInvoicingAddressPanel" stacked="true">
	        <field name="mainInvoicingAddress" hideIf="$readonly() || (statusSelect > 1 &amp;&amp; !orderBeingEdited)" canNew="true" canEdit="false" onChange="action-sale-order-method-address-str" onSelect="action-sale-order-attrs-domain-main-invoicing-address" form-view="address-partner-address-form" grid-view="address-grid"/>
	        <field name="mainInvoicingAddressStr" readonlyIf="statusSelect > 1 &amp;&amp; !orderBeingEdited" height="5">
	          <viewer><![CDATA[{{record.mainInvoicingAddressStr}}]]></viewer>
	        </field>
	      </panel>
	      <panel name="deliveryAddressPanel" stacked="true">
	        <field name="deliveryAddress" hideIf="$readonly() || (statusSelect > 1 &amp;&amp; !orderBeingEdited)" canNew="true" canEdit="false" onChange="action-sale-order-method-address-str,action-sale-order-attrs-set-is-ispm-required" onSelect="action-sale-order-attrs-domain-delivery-address" form-view="address-partner-address-form" grid-view="address-grid"/>
	        <field name="deliveryAddressStr" readonlyIf="statusSelect > 1 &amp;&amp; !orderBeingEdited" height="5">
	          <viewer><![CDATA[{{record.deliveryAddressStr}}]]></viewer>
	        </field>
	      </panel>
	    </panel>
	    <field name="clientPartner.saleOrderInformation" showTitle="false" hideIf="clientPartner == null || clientPartner.saleOrderInformation == null" colSpan="12" css="bold red"/>
	  </panel>
	  <panel-tabs name="mainPanelTab" hideIf="clientPartner == null">
	    <panel name="contentPanel" title="Content">
	      <panel-related name="detailLinesPanel" canRemove="!(clientPartner == null || statusSelect == 2 || (statusSelect == 3 &amp;&amp; !orderBeingEdited) || statusSelect == 4)" 
                     canNew="!(clientPartner == null || statusSelect == 2 || (statusSelect == 3 &amp;&amp; !orderBeingEdited) || statusSelect == 4)"
                     title="Details Lines" readonlyIf="clientPartner == null" colSpan="12" field="saleOrderLineList" form-view="sale-order-line-form" grid-view="sale-order-line-grid" orderBy="sequence" onChange="action-sale-order-line-change-group" canMove="true" height="30"/>
	      <panel name="descriptionPanel" title="Description to display" colSpan="12">
	        <field name="description" showTitle="false" colSpan="12" widget="Html" x-lite="true"/>
	      </panel>
	    </panel>
	    <panel name="taxPanel" title="Tax">
	      <panel-related name="saleOrderLineTaxListPanel" colSpan="12" field="saleOrderLineTaxList" form-view="sale-order-line-tax-form" grid-view="sale-order-line-tax-grid"/>
	    </panel>
	    <panel if="__config__.app.isApp('supplychain')" if-module="axelor-supplychain" name="deliveryInformationPanel" title="Delivery" colSpan="12">
	      <field name="specificPackage" colSpan="12"/>
	      <field name="stockLocation" canEdit="false" onSelect="action-sale-order-attrs-set-stock-location-domain" form-view="stock-location-form" grid-view="stock-location-grid"/>
	      <field name="deliveryDate" onChange="action-sale-order-method-fill-sale-order-lines-estimated-date"/>
	      <field name="deliveryCondition" colSpan="12"/>
	      <field name="shipmentMode" canEdit="false" form-view="shipment-mode-grid" grid-view="shipment-mode-grid"/>
	      <field name="freightCarrierMode" canEdit="false" onChange="action-sale-order-record-freight-carrier" domain="self.shipmentMode = :shipmentMode" form-view="freight-carrier-mode-form" grid-view="freight-carrier-mode-grid"/>
	      <field name="carrierPartner" canEdit="false" domain="self.isCarrier = TRUE AND (self.companySet IS EMPTY OR :company MEMBER OF self.companySet)" form-view="partner-form" grid-view="partner-grid"/>
	      <field name="forwarderPartner" canEdit="false" domain=":company MEMBER OF self.companySet" form-view="partner-form" grid-view="partner-grid"/>
	      <field name="incoterm" canEdit="false" form-view="incoterm-form" grid-view="incoterm-grid"/>
	      <field name="isNeedingConformityCertificate" colSpan="3"/>
	      <field name="isIspmRequired" readonly="true" colSpan="3"/>
	      <button name="customerDeliveriesDetailsBtn" title="Customer deliveries details" showIf="statusSelect >= 3" colSpan="6" onClick="action-view-show-stock-move-line"/>
	      <panel-dashlet name="customerDeliveriesPanel" title="Customer deliveries" showIf="statusSelect >= 3" colSpan="12" action="action-sale-order-view-stock-moves"/>
	      <panel name="deliveryCommentsPanel" title="Comment to display on delivery" colSpan="12">
             <field name="deliveryComments" widget="html" colSpan="12" showTitle="false"/>
	      </panel>
          <panel name="pickingOrderCommentsPanel" title="Comment to display on picking order" colSpan="12">
             <field name="pickingOrderComments" widget="html" colSpan="12" showTitle="false"/>
	      </panel>
	      </panel>
	    <panel name="invoicingPanel" title="Invoicing">
	    	<panel-dashlet name="saleOrderInvoicePanel" if="__config__.app.isApp('supplychain')" if-module="axelor-supplychain" title="Invoicing" showIf="statusSelect >= 3" action="action-view-show-invoices-from-sale-order" colSpan="12"/>
				<panel name="invoiceCommentsPanel" title="Comment to display on invoice" colSpan="12">
          <field name="invoiceComments" widget="html" colSpan="12" showTitle="false"/>
				</panel>
				<panel name="descriptionToDisplayOnProformaPanel" title="Comment to display on proforma" colSpan="12">
				  <field name="proformaComments" widget="html" colSpan="12" showTitle="false"/>
				</panel>
	    </panel>
	    <panel if="__config__.app.isApp('production')" if-module="axelor-production" name="productionPanel" title="Production" colSpan="12">
		  	<field name="productionNote" widget="Html" colSpan="12"/>
		  	<panel-dashlet name="manufOrdersPanel" action="action-sale-order-view-manuf-orders" colSpan="12"/>
	    </panel>

      <panel name="businessProjectPanel" title="Business project" if="__config__.app.isApp('business-project') &amp;&amp; __config__.app.getApp('business-project').getGenerateProjectOrder()" if-module="axelor-business-project">
        <field name="$_projectGeneratorType" title="Type of project's elements generated" x-enum-type="com.axelor.apps.project.db.ProjectGeneratorType"/>
        <field name="$_elementStartDate" title="Start date" widget="date-time" type="datetime"/>
        <field name="project" canEdit="false" domain="self.clientPartner = :clientPartner" form-view="project-form" grid-view="project-grid"/>
        <field name="toInvoiceViaTask" hidden="true" showIf="$_projectGeneratorType == 'TASK_BY_LINE' || $_projectGeneratorType == 'TASK_TEMPLATE'"/>
        <panel name="projectDetailsPanel" colSpan="12">
          <button name="updateLinesBtn" title="Update lines with selected project" onClick="save,action-business-project-sale-order-method-update-lines,save" readonlyIf="!project"/>
          <panel name="fillOrGenerateProjectPanel" stacked="true">
            <button name="fillProjectBtn" readonlyIf="!$_projectGeneratorType" title="Fill project" if="__config__.app.getApp('business-project').projectSaleOrderLines" showIf="project != null" hidden="true" onClick="save,action-business-project-method-fill-project"/>
            <button name="generateProjectBtn" readonlyIf="!$_projectGeneratorType" title="Generate Project/Business" if="!__config__.app.getApp('business-project').automaticProject" showIf="project == null" hidden="true" onClick="save,action-business-project-method-generate-project"/>
          </panel>
        </panel>
      </panel>

      <panel if="__config__.app.isApp('supplychain') &amp;&amp; __config__.app.getApp('supplychain').getAllowTimetableInvoicing()" if-module="axelor-supplychain" name="timetablePanel" title="Timetable">
	      <field name="expectedRealisationDate" colSpan="12" width="50%"/>
	      <label name="orLabel" title="OR" colSpan="12"/>
	       <field name="timetableTemplate" onChange="action-sale-order-method-apply-timetable-template,action-sale-order-method-update-amount-to-be-spread-over-the-timetable"/>
	       <field name="computationDate" onChange="action-sale-order-method-apply-timetable-template,action-sale-order-method-update-amount-to-be-spread-over-the-timetable"/>
	      <field name="amountToBeSpreadOverTheTimetable" colSpan="12"/>
	      <panel-related name="timetableListPanel"  if-module="axelor-supplychain" colSpan="12" field="timetableList" form-view="timetable-form" grid-view="timetable-grid" onChange="action-sale-order-method-update-amount-to-be-spread-over-the-timetable,action-supplychain-sale-order-validate-check-amount-timetable"/>
	    </panel>
	    <panel-related name="advancePaymentListPanel" if="__config__.app.isApp('supplychain') &amp;&amp; !__config__.app.getApp('account').getManageAdvancePaymentInvoice()" if-module="axelor-supplychain" readonly="true" colSpan="12" field="advancePaymentList" form-view="advance-payment-form" grid-view="advance-payment-grid"/>
	    <panel name="advancePaymentNeededPanel" title="Advance payments" if="__config__.app.getApp('supplychain')?.manageAdvancePaymentsFromPaymentConditions">
                  <field name="advancePaymentNeeded" readonlyIf="statusSelect &gt; 1"/>
                  <field name="advancePaymentAmountNeeded" showIf="advancePaymentNeeded" readonlyIf="statusSelect &gt; 1"/>
        </panel>
	    <panel if="__config__.app.getApp('sale').getPrintingConfigPerSaleOrder()" name="printingPanel" title="Printing">
	      <field name="printingSettings" canEdit="false" onSelect="action-sale-method-filter-printing-settings"/>
	      <field name="hideDiscount"/>
	      <field name="specificNotes" readonly="true" showIf="specificNotes" colSpan="12"/>
	    </panel>
	    <panel-include if="__config__.app.isApp('supplychain') &amp;&amp; __config__.app.getApp('supplychain').getAllowSusbcriptionSaleOrder()" if-module="axelor-supplychain" view="incl-sale-order-subscrption-form"/>
			<panel-dashlet if="__config__.app.isApp('supplychain')" name="generatedPurchaseOrderPanel" title="Generated purchase orders" action="action-sale-order-view-show-generated-po"/>
	  </panel-tabs>
	  <panel name="attrsPanel">
	    <field name="attrs" colSpan="12"/>
	  </panel>
	  <panel name="actionsPanel" hideIf="clientPartner == null" sidebar="true" stacked="true">
	    <button name="finalizeBtn" title="Finalize" showIf="statusSelect == 1" colSpan="12" onClick="action-group-sale-order-finalize-quotation"/>
	    <button if="(__config__.app.isApp('supplychain') &amp;&amp; __config__.app.getApp('supplychain')?.allowCompleteManuallySaleOrder) || (!__config__.app.isApp('supplychain'))" name="completeManuallySaleOrderBtn" title="Complete manually sale order" showIf="statusSelect == 3" prompt="Warning, a completed order can't be changed anymore, do you want to continue?" colSpan="12" onClick="save,action-sale-order-method-complete-sale-order"/>
	    <button if="__config__.app.getApp('sale').getManageSaleOrderVersion()" name="newVersionBtn" title="New version" showIf="statusSelect == 2" colSpan="12" onClick="save,action-sale-record-newVersion,save"/>
	    <button if="__config__.app.getApp('sale').allowPendingOrderModification" name="editOrderBtn" title="Edit order" showIf="statusSelect == 3 &amp;&amp; !orderBeingEdited" colSpan="12" onClick="action-sale-order-method-edit-order"/>
	    <button name="validateChangesBtn" title="Validate changes" showIf="statusSelect == 3 &amp;&amp; orderBeingEdited" colSpan="12" onClick="action-group-sale-order-validate-changes"/>
	    <button if="__config__.app.getApp('supplychain')?.custStockMoveMgtOnSO &amp;&amp; !__config__.app.getApp('supplychain').customerStockMoveGenerationAuto" name="generateCustomerStockMoveBtn" title="Generate customer deliveries" showIf="statusSelect == 3 &amp;&amp; !orderBeingEdited" readonlyIf="!saleOrderLineList || !saleOrderLineList.length" colSpan="12" onClick="save, action-supplychain-sale-order-create-stock-move"/>
	    <button name="confirmOrderBtn" title="Confirm order" showIf="statusSelect == 2" colSpan="12" onClick="save,action-sale-group-confirmed" readonlyIf="advancePaymentNeeded &amp;&amp; $number(advanceTotal) &lt; $number(advancePaymentAmountNeeded)"/>
	    <button name="invoiceAdvancePaymentBtn" title="Invoice an advance payment" if="__config__.app.isApp('supplychain') &amp;&amp; __config__.app.getApp('supplychain')?.getGenerateInvoiceFromSaleOrder()" showIf="statusSelect == 2 &amp;&amp; inTaxTotal != 0 &amp;&amp; advancePaymentAmountNeeded > 0  &amp;&amp; advancePaymentNeeded" colSpan="12" onClick="save,action-sale-order-view-invoicing-advance-payment-wizard" if-module="axelor-supplychain"/>
	    <button if="__config__.app.isApp('supplychain') &amp;&amp; __config__.app.getApp('supplychain').getGenerateInvoiceFromSaleOrder()" if-module="axelor-supplychain" name="generateInvoiceBtn" title="Generate invoice" showIf="statusSelect == 3 &amp;&amp; !orderBeingEdited" colSpan="12" onClick="action-supplychain-sale-order-group-generate-invoice"/>
	    <button if="__config__.app.isApp('supplychain') &amp;&amp; !__config__.app.getApp('supplychain').getPurchaseOrderGenerationAuto()" name="generatePOBtn" title="Generate purchase order" showIf="(statusSelect == 2 || statusSelect == 3) &amp;&amp; !orderBeingEdited" colSpan="12" onClick="save,action-supplychain-sale-order-generate-purchase-orders-from-selected-SOLines"/>
	    <button if="__config__.app.getApp('production')?.prodOrderMgtOnSO &amp;&amp; !__config__.app.getApp('production')?.productionOrderGenerationAuto" name="generateProductionOrderBtn" title="Generate production order" showIf="statusSelect == 3 &amp;&amp; !orderBeingEdited" colSpan="12" onClick="save,action-sale-order-method-create-production-order"/>
	    <button name="cancelBtn" title="Cancel" css="btn-danger" icon="fa-times" showIf="id &amp;&amp; (statusSelect == 1 || statusSelect == 2)" colSpan="12" onClick="save,action-sale-order-view-cancel"/>
	    <button if="__config__.app.isApp('supplychain') &amp;&amp; !__config__.app.getApp('account').getManageAdvancePaymentInvoice()" if-module="axelor-supplychain" name="addAdvancePaymentBtn" title="Register a deposit" showIf="statusSelect == 3 &amp;&amp; amountInvoiced == 0" colSpan="12" onClick="save,action-sale-order-view-register-advance-payment"/>
	    <field name="message" hidden="true" type="string"/>
	    <field name="amountInvoiced" hidden="true"/>
	    <button if="__config__.app.getApp('sale').getEnableConfigurator()" name="addLineFromConfiguratorBtn" title="Add Line from Configurator" showIf="statusSelect == 1" onClick="save,action-sale-order-view-generate-line"/>
	  </panel>
	  <panel name="inTaxTotalPanel" readonly="true" hideIf="clientPartner == null" colSpan="4" sidebar="true">
	    <separator/>
	    <field name="inTaxTotal" showTitle="false" colSpan="12" css="order-subtotal">
	      <viewer depends="exTaxTotal,currency.symbol,taxTotal,statusSelect,amountInvoiced,advanceTotal"><![CDATA[

	                  <dl class="dl-horizontal">
	                      <dt x-translate>Total W.T.</dt>
	                      <dd>{{record.exTaxTotal}}  {{record.currency.symbol}}</dd>
	                      <dt x-translate>Total tax</dt>
	                      <dd>{{record.taxTotal}}  {{record.currency.symbol}}</dd>
	                      <dt class="order-subtotal-total" x-translate>Total A.T.I.</dt>
	                      <dd class="order-subtotal-total">{{record.inTaxTotal}}  {{record.currency.symbol}}</dd>
	                      <dt ng-show="record.statusSelect >= 3" x-translate>Amount invoiced W.T.</dt>
	                      <dd ng-show="record.statusSelect >= 3">{{record.amountInvoiced}}  {{record.currency.symbol}}</dd>
	                      <dt ng-show="record.statusSelect >= 2" x-translate>Advance payment total</dt>
	                      <dd ng-show="record.statusSelect >= 2">{{record.advanceTotal}}  {{record.currency.symbol}}</dd>
	                  </dl>

	              ]]></viewer>
	    </field>
	  </panel>
	  <panel name="salesFollowUpPanel" title="Sales follow-up" hideIf="clientPartner == null" sidebar="true" itemSpan="6" canCollapse="true" collapseIf="true">
	    <field name="salemanUser" canNew="false" canView="false" canEdit="false" form-view="user-form" grid-view="user-grid"/>
	    <field if="__config__.app.getApp('base').getTeamManagement()" name="team" canEdit="false" onSelect="action-sale-order-domain-on-team" form-view="team-form" grid-view="team-grid"/>
	  </panel>
	  <panel name="characteristicsPanel" title="Characteristics" hideIf="clientPartner == null" sidebar="true" itemSpan="6" canCollapse="true" collapseIf="true">
	    <panel name="paymentDetailsPanel" colSpan="12" if="__config__.app.isApp('supplychain')" if-module="axelor-supplychain">
	      <field name="paymentMode" readonlyIf="statusSelect > 2" canEdit="false" onChange="action-sale-order-method-fill-company-bank-details" domain="self.inOutSelect = 1" form-view="payment-mode-form" grid-view="payment-mode-grid"/>
		    <field name="paymentCondition" readonlyIf="statusSelect > 2" canEdit="false" form-view="payment-condition-form" grid-view="payment-condition-grid" onChange="action-sale-order-record-set-advance-payment"/>
	    </panel>
	    <field name="companyBankDetails" canEdit="false" hidden="true" widget="SuggestBox" onSelect="com.axelor.apps.base.web.CompanyBankDetailsController:fillCompanyBankDetailsDomain" form-view="bank-details-form" grid-view="bank-details-grid"/>
	  </panel>
	  <panel name="referencePanel" title="References" hideIf="clientPartner == null" itemSpan="6" sidebar="true" canCollapse="true" collapseIf="true">
	    <field name="externalReference" hideIf="company == null" onChange="action-sale-order-attrs-external-reference"/>
	    <field name="opportunity" readonlyIf="statusSelect >= 2" form-view="opportunity-form" grid-view="opportunity-grid" canEdit="false"/>
	    <field name="duplicateReferenceLabel" showTitle="false" readonly="true" hidden="true">
        <viewer>
          <![CDATA[
            <h5>
              <span ng-show="true" class='label label-warning' x-translate>Reference already existing</span>
            </h5>
          ]]>
        </viewer>
      </field>
	  </panel>
	  <panel name="marginPanel" title="Margin" readonly="true" hideIf="clientPartner == null" itemSpan="6" sidebar="true" canCollapse="true" collapseIf="true">
	  	<field name="accountedRevenue">
	  		<hilite if="accountedRevenue &lt; companyExTaxTotal" color="warning"/>
	  	</field>
	    <field name="totalCostPrice"/>
	    <field name="totalGrossMargin">
	    	<hilite if="totalGrossMargin &lt; 0" color="danger"/>
	    </field>
	    <field name="marginRate">
	    	<hilite if="marginRate &lt; 0" color="danger"/>
	    </field>
	    <field name="markup">
	    	<hilite if="markup &lt; 0" color="danger"/>
	    </field>
	    <field name="company.currency" title="Company currency" readonly="true"/>
	  </panel>
	  <panel name="datesPanel" title="Dates" hideIf="clientPartner == null" sidebar="true" canCollapse="true" collapseIf="true">
	    <field name="creationDate" readonlyIf="statusSelect != 1" colSpan="6" onChange="action-sale-order-record-compute-end-of-validity-date"/>
	    <field name="confirmedByUser" readonly="true" showIf="statusSelect == 3" colSpan="6" canNew="false" canView="false" canEdit="false" form-view="user-form" grid-view="user-grid"/>
	    <field name="confirmationDateTime" readonly="true" showIf="statusSelect == 3" colSpan="6"/>
	    <field name="orderDate" showIf="statusSelect == 3" colSpan="6"/>
	    <field name="orderNumber" showIf="statusSelect == 3" colSpan="6"/>
	    <field if="__config__.app.isApp('supplychain')" if-module="axelor-supplychain" name="shipmentDate" showIf="statusSelect == 3" colSpan="6"/>
	    <field name="duration" canEdit="false" readonlyIf="statusSelect >= 2" colSpan="6" widget="SuggestBox" canNew="true" onChange="action-sale-order-record-compute-end-of-validity-date"/>
	    <field name="endOfValidityDate" readonly="true" colSpan="6">
	      <hilite color="danger" if="$moment().diff(endOfValidityDate, 'days') > 0 &amp;&amp; statusSelect != 3"/>
	    </field>
	    <field if="__config__.app.isApp('supplychain') &amp;&amp; !__config__.app.getApp('supplychain').getAllowTimetableInvoicing()" name="expectedRealisationDate" colSpan="6"/>
	    <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>
	    <field if="__config__.app.isApp('supplychain')" if-module="axelor-supplychain" name="standardDelay" hidden="true" readonly="true" showIf="standardDelay > 0"/>
	  </panel>
	  <panel name="internalNotePanel" title="Internal Note" colSpan="12" sidebar="true">
	    <field name="internalNote" showTitle="false" colSpan="12" widget="Html" x-lite="true"/>
	  </panel>
	  <panel-mail name="mailPanel">
	    <mail-messages limit="4"/>
	    <mail-followers/>
	  </panel-mail>
	</form>

	<grid name="sale-order-template-grid" title="Templates" model="com.axelor.apps.sale.db.SaleOrder" orderBy="-creationDate">
		<field name="title" width="120"/>
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field  name="clientPartner" form-view="partner-form" grid-view="partner-grid" />
		<field name="externalReference" />
		<field name="creationDate" /><field name="exTaxTotal" aggregate="sum"/>
		<field name="exTaxTotal" aggregate="sum"/>
		<field name="inTaxTotal" aggregate="sum"/>
	</grid>

    <form name="sale-order-template-form-wizard" title="Template" model="com.axelor.apps.sale.db.SaleOrder"
		onNew="action-group-sale-saleorder-onnew,action-saleorder-record-template,action-sale-order-method-create-template"
		onLoad="action-group-sale-saleorder-onload">

		<panel-include view="sale-order-template-form"/>
	</form>

	<form name="sale-order-template-form" title="Template" model="com.axelor.apps.sale.db.SaleOrder"
		onNew="action-group-sale-saleorder-onnew,action-sale-order-template-hide-allocated-qty"
		onLoad="action-group-sale-saleorder-onload,action-sale-order-template-hide-allocated-qty">
	  <panel name="overviewPanel">
	  	<field name="clientPartner.saleOrderInformation" css="bold red" colSpan="12" showTitle="false" hideIf="clientPartner == null || clientPartner.saleOrderInformation == null"/>
	    <field name="title"/>
	    <field name="company" canEdit="false" widget="SuggestBox" onChange="action-sale-group-onchange-company" form-view="company-form" grid-view="company-grid" readonlyIf="statusSelect == 3"/>
	    <field name="templateUser" canNew="false" canEdit="false" canView="false" form-view="user-form" grid-view="user-grid"/>
	  </panel>

	  <panel-tabs name="mainPanelTab">

	    <panel name="contentPanel" title="Content">
	    	<panel-related name="saleOrderLineListPanel" field="saleOrderLineList" colSpan="12" onChange="action-sale-order-method-compute" form-view="sale-order-line-template-form" grid-view="sale-order-line-grid" canMove="true" orderBy="sequence"/>
	    	<panel-related name="saleOrderLineTaxListPanel" field="saleOrderLineTaxList" colSpan="12" form-view="sale-order-line-tax-form" grid-view="sale-order-line-tax-grid"/>
	    </panel>

		<panel name="customerInformationPanel" title="Customer information">
			<field name="clientPartner" onChange="action-sale-order-group-client-partner-change" onSelect="action-sale-order-method-set-client-partner-domain" form-view="partner-form" grid-view="partner-grid"/>
			<field name="contactPartner" onChange="action-record-so-contact-partner-change" onSelect="action-sale-order-domain-on-contact-partner" domain="self.isContact = true" form-view="partner-contact-form" grid-view="partner-contact-grid"/>
			<panel name="mainInvoicingAddressPanel" stacked="true">
				<field name="mainInvoicingAddress" canNew="true"
					 hideIf="$readonly() || statusSelect &gt; 1"
					 onChange="action-sale-order-method-address-str"
                     onSelect="action-sale-order-attrs-domain-main-invoicing-address"
                     form-view="address-partner-address-form"
                     grid-view="address-grid"/>
			</panel>
			<panel name="deliveryAddressPanel" stacked="true">
				<field name="deliveryAddress" canNew="true"
					 hideIf="$readonly() || statusSelect &gt; 1"
					 onChange="action-sale-order-method-address-str"
                     onSelect="action-sale-order-attrs-domain-delivery-address"
                     form-view="address-partner-address-form"
                     grid-view="address-grid"/>
			</panel>
	      	<field name="duplicateReferenceLabel" showTitle="false" readonly="true" hidden="true">
	          <viewer>
	            <![CDATA[
		            <h5>
		              <span ng-show="true" class='label label-warning' x-translate>Reference already existing</span>
		            </h5>
	            ]]>
	          </viewer>
	        </field>
		</panel>
	    <panel name="otherInformationsPanel" title="Other informations" showTitle="false">
	      <panel name="salesFollowUpPanel" title="Sales follow-up" colSpan="12">
	        <field name="salemanUser" canNew="false" canEdit="false" canView="false" form-view="user-form" grid-view="user-grid"/>
	        <field name="team" onSelect="action-sale-order-domain-on-team" form-view="team-form" grid-view="team-grid"/>
	      </panel>
	      <panel name="financialTermsPanel" title="Financial terms" colSpan="12"  if-module="axelor-supplychain" if="__config__.app.isApp('supplychain')">
	        <field name="paymentMode" canEdit="false" domain="self.inOutSelect = 1" form-view="payment-mode-form" grid-view="payment-mode-grid"/>
	        <field name="paymentCondition" canEdit="false" form-view="payment-condition-form" grid-view="payment-condition-grid"/>
	      </panel>
	      <panel name="stockLocationPanel" title="Stock location" if-module="axelor-supplychain" if="__config__.app.isApp('supplychain')">
   		      <field name="stockLocation" canEdit="false" domain="self.company = :company and self.typeSelect = 1" form-view="stock-location-form" grid-view="stock-location-grid"/>
	      </panel>
	      <panel name="descriptionPanel" title="Description" colSpan="12">
	        <field name="description" showTitle="false" widget="Html" x-lite="true" colSpan="12"/>
	      </panel>
	    </panel>

	    <panel name="projectPanel" if="__config__.app.isApp('business-project') &amp;&amp; __config__.app.getApp('business-project').getGenerateProjectOrder()" title="Business project" colSpan="12" if-module="axelor-business-project">
      		  <field name="project" domain="self.typeSelect = 'project'" form-view="project-form" grid-view="project-grid" colSpan="12"/>
       	</panel>

	  </panel-tabs>

	  <panel sidebar="true" name="actionsPanel" title="Actions">
	  	<button name="createOrderBtn" title="Create Order from this Template" onClick="save,action-sale-order-validate-client-partner,action-sale-order-method-generate-sale-order-from-template-wizard"/>
	  </panel>

	  <panel sidebar="true" name="infoPanel" title="Info.">
	    <field name="creationDate"  readonlyIf="statusSelect != 1" colSpan="6" onChange="action-sale-order-record-compute-end-of-validity-date"/>
	    <field name="confirmedByUser" canNew="false" canEdit="false" canView="false" readonly="true" colSpan="6" showIf="statusSelect == 3" form-view="user-form" grid-view="user-grid"/>
	    <field name="confirmationDateTime" readonly="true" colSpan="6" showIf="statusSelect == 3"/>
	    <field name="orderDate" colSpan="6" showIf="statusSelect == 3"/>
	    <field name="orderNumber" colSpan="6" showIf="statusSelect == 3"/>
	    <field name="shipmentDate" colSpan="6" showIf="statusSelect == 3" if-module="axelor-supplychain" if="__config__.app.isApp('supplychain')" />
	    <field name="duration" canEdit="false" widget="SuggestBox" canNew="true" colSpan="6" onChange="action-sale-order-record-compute-end-of-validity-date" readonlyIf="statusSelect == 3"/>
	  </panel>

        <panel name="inTaxTotalPanel" sidebar="true" readonly="true"  colSpan="4">
            <field name="inTaxTotal" css="order-subtotal" showTitle="false" colSpan="12">
                <viewer depends="exTaxTotal,currency.symbol,taxTotal,statusSelect,amountInvoiced,advanceTotal">
                    <![CDATA[
                    <dl class="dl-horizontal">
                        <dt x-translate>Total W.T.</dt>
                        <dd>{{record.exTaxTotal}}</dd>
                        <dt x-translate>Total tax</dt>
                        <dd>{{record.taxTotal}}</dd>
                        <dt class="order-subtotal-total" x-translate>Total A.T.I.</dt>
                        <dd class="order-subtotal-total">{{record.inTaxTotal}}</dd>
                        <dt ng-show="record.statusSelect >= 3" x-translate>Amount invoiced W.T.</dt>
                        <dd ng-show="record.statusSelect >= 3">{{record.amountInvoiced}}  {{record.currency.symbol}}</dd>
                        <dt ng-show="record.statusSelect >= 2" x-translate>Advance payment total</dt>
                        <dd ng-show="record.statusSelect >= 2">{{record.advanceTotal}}  {{record.currency.symbol}}</dd>
                    </dl>
                    ]]>
                </viewer>
            </field>
        </panel>

	</form>

	<grid name="sale-order-grid-client" title="Sale orders" model="com.axelor.apps.sale.db.SaleOrder" orderBy="-creationDate">
		<field name="saleOrderSeq" width="120"/>
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="clientPartner" form-view="partner-form" grid-view="partner-grid" />
		<field name="externalReference" />
		<field name="creationDate" />
		<field name="exTaxTotal" aggregate="sum"/>
    <field name="inTaxTotal" aggregate="sum" />
		<field name="currency" form-view="currency-form" grid-view="currency-grid"/>
    <field name="statusSelect" />
		<button name="printBtn" title="Print" icon="fa-print" onClick="action-sale-order-method-show-sale-order" />
	</grid>

	<form name="sale-order-form-client" title="Sale order"
		model="com.axelor.apps.sale.db.SaleOrder" id="sale-order-form-client"
		onLoad="action-group-sale-saleorder-onload" onSave="save,action-sale-order-method-compute,save"
		onNew="action-group-sale-saleorder-onnew" width="large">
	  <toolbar>
	    <button name="printBtn" title="Print" icon="fa-print" onClick="save,action-sale-order-method-show-sale-order"/>
	  </toolbar>
	  <panel name="mainPanel" readonly="true">
	    <field name="saleOrderSeq" css="highlight"/>
	    <field name="company" canEdit="false" widget="SuggestBox" form-view="company-form" grid-view="company-grid"/>
	    <field name="externalReference"/>
	    <field name="currency" required="true" canEdit="false" form-view="currency-form" grid-view="currency-grid"/>
	  </panel>
		<panel-tabs readonly="true" name="mainPanelTab">
			<panel name="customerInformationPanel" title="Customer information" showTitle="false">
				<field name="clientPartner" required="true" form-view="partner-form" grid-view="partner-grid" canView="false" domain=":company member of self.companySet"/>
				<panel stacked="true" name="mainInvoicingAddressPanel">
					<field name="mainInvoicingAddress" canNew="true"
						   hideIf="$readonly() || statusSelect &gt; 1"
						   onChange="action-sale-order-method-address-str"
						   onSelect="action-sale-order-attrs-domain-main-invoicing-address"
						   form-view="address-partner-address-form"
						   grid-view="address-grid"/>
					<field name="mainInvoicingAddressStr" readonlyIf="statusSelect &gt; 1" height="5">
						<viewer>{{record.mainInvoicingAddressStr}}</viewer>
					</field>
				</panel>

	      <field name="contactPartner" domain="self.isContact = true AND :company member of self.companySet" form-view="partner-contact-form" grid-view="partner-contact-grid" canView="false"/>
				<panel stacked="true" name="deliveryAddressPanel">
					<field name="deliveryAddress" canNew="true"
						   hideIf="$readonly() || statusSelect &gt; 1"
						   onChange="action-sale-order-method-address-str"
						   onSelect="action-sale-order-attrs-domain-delivery-address"
						   form-view="address-partner-address-form"
						   grid-view="address-grid"/>
					<field name="deliveryAddressStr" readonlyIf="statusSelect &gt; 1" height="5">
						<viewer>{{record.deliveryAddressStr}}</viewer>
					</field>
				</panel>
	      <panel name="detailsPanel" colSpan="8">
	        <field name="confirmationDateTime"/>
	        <field name="creationDate"/>
	        <field name="orderDate"/>
	        <field name="shipmentDate" if-module="axelor-supplychain" if="__config__.app.isApp('supplychain')" />
	        <field name="duration" canEdit="false"/>
	        <field name="endOfValidityDate">
	    		<hilite if="$moment().diff(endOfValidityDate, 'days') &gt; 0 &amp;&amp; statusSelect != 3" color="danger"/>
	    	</field>
	        <field name="salemanUser" canNew="false" canEdit="false" colSpan="10" form-view="user-form" grid-view="user-grid" canView="false"/>
	        <field name="statusSelect" widget="NavSelect" colSpan="12"/>
	      </panel>
            <panel name="inTaxTotalPanel" readonly="true"  css="order-subtotal" colSpan="4">
                <field name="inTaxTotal" showTitle="false" colSpan="12">
                    <viewer depends="exTaxTotal,currency.symbol,taxTotal,statusSelect,amountInvoiced,advanceTotal">
                        <![CDATA[
                        <dl class="dl-horizontal">
                            <dt x-translate>Total W.T.</dt>
                            <dd>{{record.exTaxTotal}} {{record.currency.symbol}}</dd>
                            <dt x-translate>Total V.A.T.</dt>
                            <dd>{{record.taxTotal}} {{record.currency.symbol}}</dd>
                            <dt class="order-subtotal-total" x-translate>Total A.T.I.</dt>
                            <dd class="order-subtotal-total">{{record.inTaxTotal}} {{record.currency.symbol}}</dd>
                            <dt ng-show="record.statusSelect >= 3" x-translate>Amount invoiced W.T.</dt>
                            <dd ng-show="record.statusSelect >= 3">{{record.amountInvoiced}}  {{record.currency.symbol}}</dd>
                            <dt ng-show="record.statusSelect >= 2" x-translate>Advance payment total</dt>
                            <dd ng-show="record.statusSelect >= 2">{{record.advanceTotal}}  {{record.currency.symbol}}</dd>
                        </dl>
                        ]]>
                    </viewer>
                </field>
            </panel>
	    </panel>
	    <panel-related name="saleOrderLineListPanel" field="saleOrderLineList" showTitle="false" form-view="sale-order-line-form" grid-view="sale-order-line-grid" canMove="true" orderBy="sequence" height="30" />
	    <panel-related name="saleOrderLineTaxListPanel" field="saleOrderLineTaxList" showTitle="false" form-view="sale-order-line-tax-form" grid-view="sale-order-line-tax-grid"/>
	    <panel-dashlet name="invoicesFromSOPanel" action="action-view-show-invoices-from-sale-order" title="Invoicing"/>
	  </panel-tabs>
	</form>
	
	<form name="sale-order-invoicing-advance-payment-wizard-form" title="Advance payments"
		  model="com.axelor.apps.sale.db.SaleOrder">
		<panel>
		<panel showFrame="false" colSpan="12">
			<field name="advancePaymentAmountNeeded" readonly="true"/>
			<field name="isPercent" title="Is amount in % ?" type="boolean"/>
		</panel>
		<panel name="amountToInvoicePanel" showFrame="false">
            <field name="amountToInvoice" title="Adv. payment amount" type="decimal" onChange="action-sale-order-attrs-amount-to-invoice" colSpan="12"/>
		</panel>
		<spacer/>
		<panel name="amountToInvoiceHiddenPanel" hidden="true" showFrame="false">
			<field name="amountToInvoice" title="Adv. payment amount" colSpan="12" css="font-orange" type="decimal" onChange="action-sale-order-attrs-amount-to-invoice"/>
		</panel>
		</panel>
		<panel>
			<button name="generateAdvancePaymentInvoiceBtn" title="Generate advance payment invoice"
					onClick="action-sale-order-method-generate-advance-payment"/>
		</panel>
	</form>

	<action-attrs name="action-sale-order-attrs-amount-to-invoice">
		<attribute name="hidden" expr="eval: advancePaymentAmountNeeded > (new BigDecimal(amountToInvoice))" for="amountToInvoicePanel"/>
		<attribute name="hidden" expr="eval: !(advancePaymentAmountNeeded > (new BigDecimal(amountToInvoice)))" for="amountToInvoiceHiddenPanel"/>
	</action-attrs>

	<cards name="sale-order-cards" title="Sale order" model="com.axelor.apps.sale.db.SaleOrder" width="300px"  css="rect-image" orderBy="-orderDate">
		<toolbar>
    		<button name="seeSaleOrderLinesBtn" title="See sale orders lines" onClick="action-view-open-sale-order-lines"/>
		</toolbar>
		<field name="saleOrderSeq"/>
		<field name="externalReference"/>
		<field name="clientPartner.fullName"/>
		<field name="orderDate"/>
		<field name="exTaxTotal"/>
		<field name="inTaxTotal"/>
		<field name="currency.symbol"/>
		<field name="statusSelect"/>
		<field name="deliveryState"/>
		<field name="amountInvoiced" />
        <field name="orderBeingEdited" />
        <field name="company"/>
        <field name="tradingName"/>
        <field name="stockLocation" if="__config__.app.isApp('supplychain')"/>
		<template><![CDATA[
		    <div class="span12">
		    	<strong><span x-translate>Sale order</span> {{ saleOrderSeq }}</strong> <span ng-show="record.externalReference">( {{ externalReference }} )</span>
		    	<a class="pull-right muted">{{ $fmt('orderDate') }}</a>
	    	</div>
			<div>
			  <div>
				  <div class="span8">
				    <i class="fa fa-users" aria-hidden="true"></i>
				  	{{ clientPartner.fullName }}
				  </div>
					<div class="span4 pull-right">
						<i class="fa fa-long-arrow-right" aria-hidden="true"></i>
						<span ng-show="record.statusSelect == 1" x-translate>Draft quotation</span>
						<span ng-show="record.statusSelect == 2" x-translate>Finalized quotation</span>
						<span ng-show="record.statusSelect == 3" x-translate>Order confirmed</span>
						<span ng-show="record.statusSelect == 4" x-translate>Order completed</span>
						<span ng-show="record.statusSelect == 5" x-translate>Canceled</span>
					</div>
			  </div>
			  <div>
				  <div class="span6">
				  	<h5>
						<span class="label label-important"  ng-show="record.amountInvoiced == 0"  x-translate>Not invoiced</span>
						<span class="label label-warning" ng-show="record.amountInvoiced > 0 && $number(record.amountInvoiced) < $number(record.exTaxTotal)" x-translate>Partially invoiced</span>
						<span class="label label-success" ng-show="record.amountInvoiced > 0 && record.amountInvoiced == record.exTaxTotal" x-translate>Invoiced</span>
					</h5>
					<h5>
						<span class="label label-important" ng-show="record.deliveryState > 0 && record.deliveryState == 1" x-translate>Not delivered</span>
						<span class="label label-warning" ng-show="record.deliveryState > 0 && record.deliveryState == 2" x-translate>Partially delivered</span>
						<span class="label label-success" ng-show="record.deliveryState > 0 && record.deliveryState == 3" x-translate>Delivered</span>
					</h5>
                    <h5>
                        <span class="label label-important" ng-show="record.orderBeingEdited" x-translate>Order being edited</span>
                    </h5>
				  </div>
				  <div class="span6">
				    <span><strong><span x-translate>WT</span> : {{ $fmt('exTaxTotal') }} {{ currency.symbol }}</strong><br/>
				    <strong><span x-translate>ATI</span> : {{ $fmt('inTaxTotal') }} {{ currency.symbol }}</strong></span>
				  </div>
			  </div>
			</div>
			<div class="span12" style="margin-left:0px;">
			  <span class="label label-default" ng-show="!record.tradingName.name" style="background-color: #2185D0;" x-translate>{{ company.name }}</span>
			  <span class="label label-default" ng-show="record.tradingName.name" style="background-color: #2185D0;" x-translate>{{ tradingName.name }}</span>
			  <span class="label label-default pull-right muted" style="background-color: #2185D0; padding: 5px;" x-translate>{{ stockLocation.name }}</span>
			</div>
		]]>
		</template>
	</cards>

	<cards name="sale-order-quotation-cards" title="Sale order quotation" model="com.axelor.apps.sale.db.SaleOrder" width="300px"  css="rect-image" orderBy="-orderDate">
	<toolbar>
			<button name="mergeQuotationOrderBtn" title="Merge quotations" onClick="action-open-sale-quotation-merge-form"/>
	</toolbar>
		<field name="saleOrderSeq"/>
		<field name="externalReference"/>
		<field name="clientPartner.fullName"/>
		<field name="orderDate"/>
		<field name="exTaxTotal"/>
		<field name="inTaxTotal"/>
		<field name="currency.symbol"/>
		<field name="statusSelect"/>
		<field name="deliveryState"/>
		<field name="amountInvoiced" />
		<field name="company"/>
		<field name="tradingName"/>
		<field name="stockLocation" if="__config__.app.isApp('supplychain')"/>
		<template><![CDATA[
		    <div class="span12">
		    	<strong><span x-translate>Sale quotation</span> {{ saleOrderSeq }}</strong> <span ng-show="record.externalReference">( {{ externalReference }} )</span>
		    	<a class="pull-right muted">{{ $fmt('orderDate') }}</a>
	    	</div>
			<div>
			  <div>
				  <div class="span8">
				    <i class="fa fa-users" aria-hidden="true"></i>
				  	{{ clientPartner.fullName }}
				  </div>
					<div class="span4 pull-right">
						<i class="fa fa-long-arrow-right" aria-hidden="true"></i>
						<span ng-show="record.statusSelect == 1" x-translate>Draft quotation</span>
						<span ng-show="record.statusSelect == 2" x-translate>Finalized quotation</span>
						<span ng-show="record.statusSelect == 3" x-translate>Order confirmed</span>
						<span ng-show="record.statusSelect == 4" x-translate>Order completed</span>
						<span ng-show="record.statusSelect == 5" x-translate>Canceled</span>
					</div>
			  </div>
			  <div>
				  <div class="span6">
				  	<h5>
						<span class="label label-important"  ng-show="record.amountInvoiced == 0"  x-translate>Not invoiced</span>
						<span class="label label-warning" ng-show="record.amountInvoiced > 0 && $number(record.amountInvoiced) < $number(record.exTaxTotal)" x-translate>Partially invoiced</span>
						<span class="label label-success" ng-show="record.amountInvoiced > 0 && record.amountInvoiced == record.exTaxTotal" x-translate>Invoiced</span>
					</h5>
					<h5>
						<span class="label label-important" ng-show="record.deliveryState > 0 && record.deliveryState == 1" x-translate>Not delivered</span>
						<span class="label label-warning" ng-show="record.deliveryState > 0 && record.deliveryState == 2" x-translate>Partially delivered</span>
						<span class="label label-success" ng-show="record.deliveryState > 0 && record.deliveryState == 3" x-translate>Delivered</span>
					</h5>
				  </div>
				  <div class="span6">
				    <span><strong><span x-translate>WT</span> : {{ $fmt('exTaxTotal') }} {{ currency.symbol }}</strong><br/>
				    <strong><span x-translate>ATI</span> : {{ $fmt('inTaxTotal') }} {{ currency.symbol }}</strong></span>
				  </div>
			  </div>
			</div>
			<div class="span12" style="margin-left:0px;">
			  <span class="label label-default" ng-show="!record.tradingName.name" style="background-color: #2185D0;" x-translate>{{ company.name }}</span>
			  <span class="label label-default" ng-show="record.tradingName.name" style="background-color: #2185D0;" x-translate>{{ tradingName.name }}</span>
			  <span class="label label-default pull-right muted" style="background-color: #2185D0; padding: 5px;" x-translate>{{ stockLocation.name }}</span>
			</div>
		]]>
		</template>
	</cards>

    <action-attrs name="action-sale-order-domain-on-team">
    	<attribute name="domain" for="team" expr="eval: salemanUser?.teamSet?.collect{it.id}?.size() > 0 ? &quot;self.id IN (${salemanUser?.teamSet?.collect{it.id}?.join(',')})&quot; : null"/>
    </action-attrs>

	<action-attrs name="action-sale-order-attrs-generate-stockmove-readonly">

		<attribute name="readonly" for="generateCustomerStockMoveBtn" expr="eval: !saleOrderLineList"/>
	</action-attrs>

	<action-attrs name="action-attrs-sale-other-reason">
		<attribute for="cancelReasonStr" name="hidden" expr="cancelReason.freeText == false"/>
	</action-attrs>

	<action-group name="action-group-partner-saleorder-onnew">
		<action name="action-sale-order-record-from-partner"/>
		<action name="action-sale-order-record-partner"/>
		<action name="action-sale-order-record-set-advance-payment" if="__config__.app.getApp('supplychain')?.manageAdvancePaymentsFromPaymentConditions"/>
        <action name="action-partner-attrs-hide-contact-partner"/>
        <action name="action-sale-order-method-address-str"/>
		<action name="action-sale-order-method-fill-price-list"/>
		<action name="action-sale-order-record-compute-end-of-validity-date"/>
        <action name="action-sale-order-method-fill-company-bank-details"/>
	</action-group>

	<action-group name="action-group-sale-order-merge-action">
	    <action name="action-sale-order-method-merge-sale" if="!__config__.app.isApp('supplychain')"/>
	    <action name="action-sale-order-method-merge-supplychain" if="__config__.app.isApp('supplychain')"/>
	</action-group>

    <action-group name="action-sale-group-onchange-company">
    	<action name="action-sale-order-record-company-configuration"/>
    	<action name="action-supplychain-sale-order-method-get-stock-location" />
        <action name="action-sale-order-method-fill-company-bank-details"/>
		<action name="action-sale-record-update-info-company"/>
    </action-group>

	<action-group name="action-sale-group-onchange-client-partner">
		<action name="action-sale-order-record-partner"/>
		<action name="action-sale-order-record-set-advance-payment" if="__config__.app.getApp('supplychain')?.manageAdvancePaymentsFromPaymentConditions"/>
		<action name="action-partner-attrs-hide-contact-partner"/>
		<action name="action-sale-order-method-fill-company-bank-details"/>
		<action name="action-sale-method-printing-settings-default-values"/>
	</action-group>

    <action-group name="action-group-sale-saleorder-onnew">
    	<action name="action-sale-order-record-default"/>
    	<action name="action-sale-order-record-company-configuration"/>
    	<action name="action-sale-order-record-currency"/>
    	<action name="action-sale-order-attrs-collapse-specific-settings-group"/>
    	<action name="action-sale-order-record-in-ati"/>
    	<action name="action-sale-order-attrs-in-ati"/>
        <action name="action-sale-order-attrs-hidden-bank-details"/>
        <action name="action-sale-order-method-fill-company-bank-details"/>
        <action name="action-sale-order-attrs-external-reference"/>
        <action name="action-sale-order-attrs-availability-request-label"/>
        <action name="action-sale-order-group-set-defualts-from-opportunity" if="_parent != null &amp;&amp; _parent?._model=='com.axelor.apps.crm.db.Opportunity'"/>
    </action-group>

	<action-group name="action-sale-order-group-set-defualts-from-opportunity">
		 <action name="action-sale-order-record-set-clientPartner-from-opportunity"/>
		 <action name="action-sale-order-group-client-partner-change" if="clientPartner != null"/>
	</action-group>

    <action-record name="action-sale-order-record-set-clientPartner-from-opportunity" model="com.axelor.apps.sale.db.SaleOrder">
    	<field name="clientPartner" expr="eval:_parent?.partner"/>
    </action-record>

    <action-group name="action-group-sale-saleorder-onload">
    	<action name="action-sale-order-attrs-collapse-specific-settings-group"/>
    	<action name="action-partner-attrs-hide-contact-partner" />
    	<action name="action-sale-order-attrs-in-ati"/>
		<action name="action-sale-order-attrs-hidden-bank-details"/>
		<action name="action-sale-order-record-project-default-fields" if="__config__.app.isApp('business-project')"/>
		<action name="action-sale-order-attrs-external-reference"/>
		<action name="action-sale-order-attrs-availability-request-label"/>
		<action name="action-sale-order-attrs-set-required"/>
	</action-group>

	<action-group name="action-sale-group-confirmed">
    <action name="action-sale-order-method-check-analytic-distribution-template"/>
    	<action name="action-business-project-method-generate-project" if="__config__.app.isApp('business-project') &amp;&amp; __config__.app.getApp('business-project').getAutomaticProject()"/>
		<action name="action-sale-order-validate-check-on-confirm"/>
    	<action name="action-sale-order-method-confirm"/>
		<action name="action-sale-order-method-notify-stock-move-created" if="__config__.app.isApp('supplychain') &amp;&amp; __config__.app.getApp('supplychain').customerStockMoveGenerationAuto "/>
    </action-group>

    <action-group name="action-sale-order-line-change-group">
		<action name="action-sale-order-method-remove-subline"/>
    	<action name="save" if="saleOrderLineList.find{it->it.typeSelect == 2 &amp;&amp; (it.version != null || it.id == null)} != null" />
    	<action name="action-sale-order-method-compute"/>
    	<action name="action-sale-order-method-compute-margin"/>
    	<action name="action-sale-order-record-set-advance-payment" if="__config__.app.getApp('supplychain')?.manageAdvancePaymentsFromPaymentConditions"/>
    	<action name="action-sale-order-record-update-timetable-amounts" if="__config__.app.isApp('supplychain') &amp;&amp; timetableList != null"/>
    	<action name="action-sale-order-method-update-amount-to-be-spread-over-the-timetable" if="__config__.app.isApp('supplychain') &amp;&amp; timetableList != null"/>
    	<action name="save" if="saleOrderLineList.find{it->it.typeSelect == 2 &amp;&amp; (it.version != null || it.id == null)} != null" />
    </action-group>

	<action-group name="action-sale-order-group-client-partner-change">
		<action name="action-sale-order-record-partner"/>
		<action name="action-sale-order-record-set-advance-payment" if="__config__.app.getApp('supplychain')?.manageAdvancePaymentsFromPaymentConditions"/>
        <action name="action-sale-order-method-address-str"/>
		<action name="action-sale-order-method-fill-price-list" if="!template"/>
		<action name="action-sale-order-attrs-interco"
				if="__config__.app.isApp('supplychain')"/>
		<action name="action-sale-order-record-interco"
				if="__config__.app.isApp('supplychain')"/>
		<action name="action-sale-order-record-set-contact-partner"/>
		<action name="action-sale-order-record-partner-supplychain" 
				if="__config__.app.isApp('supplychain')"/>
		<action name="action-supplychain-sale-order-method-get-stock-location"
				if="__config__.app.isApp('supplychain') &amp;&amp; stockLocation == null"/>
		<action name="action-partner-attrs-hide-contact-partner"/>
		<action name="action-sale-order-method-change-sale-order-line-tax" if="template"/>
		<action name="action-sale-order-method-compute" if="template"/>
		<action name="action-sale-order-attrs-set-is-ispm-required"
				if="__config__.app.isApp('supplychain')"/>
	</action-group>

  <action-group name="action-group-sale-order-validate-changes">
    <action name="action-method-sale-order-validate-changes"/>
  </action-group>
  
  <action-group name="action-group-sale-order-finalize-quotation">
  	<action name="save"/>
  	<action name="action-sale-order-validate-quotation"/>
  	<action name="action-sale-order-method-finalize-quotation"/>
  </action-group>
  
  	<action-validate name="action-sale-order-validate-quotation">
		<error message="Please enter at least one detail line." if="saleOrderLineList?.isEmpty()"/>
	</action-validate>

    <action-attrs name="action-sale-order-attrs-in-ati">
    	<attribute name="hidden" for="saleOrderLineList.exTaxTotal" expr="inAti"/>
    	<attribute name="hidden" for="saleOrderLineList.price" expr="inAti"/>
    	<attribute name="hidden" for="saleOrderLineList.inTaxTotal" expr="!inAti"/>
    	<attribute name="hidden" for="saleOrderLineList.inTaxPrice" expr="!inAti"/>
    	<attribute name="hidden" for="inAti" expr=" eval: __repo__(SaleConfig).all().filter('self.company = ?',company).fetchOne()?.saleOrderInAtiSelect == 1
    									|| __repo__(SaleConfig).all().filter('self.company = ?',company).fetchOne()?.saleOrderInAtiSelect == 2" if="company != null"/>
    </action-attrs>

    <action-record name="action-sale-order-record-set-contact-partner" model="com.axelor.apps.sale.db.SaleOrder">
    	<field name="contactPartner" expr="eval: clientPartner?.contactPartnerSet?.size() == 1 ? clientPartner.contactPartnerSet.collect{it}[0] : null"/>
    </action-record>

    <action-record name="action-sale-order-record-from-partner" model="com.axelor.apps.sale.db.SaleOrder">
    	<field name="clientPartner" expr="eval: _partner" if="_partner.isContact == false"/>
    	<field name="clientPartner" expr="eval: __repo__(Partner).find(_partner.mainPartner.id)" if="_partner.isContact == true &amp; _partner.mainPartner != null"/>
    	<field name="contactPartner" expr="eval: _partner" if="_partner.isContact == true"/>
    	<field name="contactPartner" expr="eval: _partner?.contactPartnerSet?.size() == 1 ? _partner?.contactPartnerSet[0] : null" if="_partner.isContact == false"/>
    </action-record>

    <action-record name="action-sale-order-record-in-ati" model="com.axelor.apps.sale.db.SaleOrder">
    	<field name="inAti" expr="eval: __repo__(SaleConfig).all().filter('self.company = ?',company).fetchOne()?.saleOrderInAtiSelect == 2
    									|| __repo__(SaleConfig).all().filter('self.company = ?',company).fetchOne()?.saleOrderInAtiSelect == 4"/>
    </action-record>
    
    <action-record name="action-sale-order-record-set-advance-payment" model="com.axelor.apps.sale.db.SaleOrder" if-module="axelor-supplychain">
    	<field name="advancePaymentNeeded" expr="eval: paymentCondition?.advancePaymentNeeded > 0 ? true : false" if="__config__.app.getApp('supplychain')?.manageAdvancePaymentsFromPaymentConditions"/>
		<field name="advancePaymentAmountNeeded" expr="eval: inTaxTotal * ((paymentCondition?.advancePaymentNeeded == null) ? 0 : paymentCondition?.advancePaymentNeeded / 100.0)" if="__config__.app.getApp('supplychain')?.manageAdvancePaymentsFromPaymentConditions"/>
    </action-record>

	<action-method name="action-sale-order-method-update-amount-to-be-spread-over-the-timetable" if-module="axelor-supplychain">
		<call class="com.axelor.apps.supplychain.web.SaleOrderController" method="updateAmountToBeSpreadOverTheTimetable"/>
	</action-method>

    <action-method name="action-sale-order-method-finalize-quotation">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="finalizeQuotation"/>
	</action-method>

    <action-method name="action-sale-order-method-complete-sale-order">
        <call class="com.axelor.apps.sale.web.SaleOrderController" method="completeSaleOrder"/>
    </action-method>

	<action-method name="action-sale-order-method-merge-sale">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="mergeSaleOrder"/>
	</action-method>

	<action-method name="action-sale-order-method-merge-supplychain" if-module="axelor-supplychain">
		<call class="com.axelor.apps.supplychain.web.SaleOrderController" method="mergeSaleOrder"/>
	</action-method>

    <action-method name="action-sale-order-method-confirm">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="confirmSaleOrder"/>
	</action-method>

    <action-method name="action-sale-order-method-show-sale-order">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="showSaleOrder"/>
	</action-method>

    <action-method name="action-sale-order-method-print-proforma-invoice">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="printProformaInvoice"/>
	</action-method>

	<action-method name="action-sale-order-method-export-sale-order-excel">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="exportSaleOrderExcel"/>
	</action-method>

	<action-method name="action-sale-order-method-export-sale-order-word">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="exportSaleOrderWord"/>
	</action-method>

	<action-method name="action-sale-order-method-fill-price-list">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="fillPriceList"/>
	</action-method>

	<action-method name="action-sale-order-method-price-list-domain">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="changePriceListDomain"/>
	</action-method>
	
	<action-method name="action-sale-order-method-notify-stock-move-created">
		<call class="com.axelor.apps.supplychain.web.SaleOrderController" method="notifyStockMoveCreated"/>
	</action-method>
	
    <action-record name="action-sale-record-newVersion" model="com.axelor.apps.sale.db.SaleOrder">
    	<field name="statusSelect" expr="eval: 1"/>
    	<field name="deliveryState" expr="eval: 1"/>
    	<field name="versionNumber" expr="eval: versionNumber + 1"/>
    </action-record>

    <action-view name="action-open-sale-order-merge-form" title="Merge sale orders" model="com.axelor.apps.base.db.Wizard">
	    <view type="form" name="sale-order-merge-form"/>
	</action-view>

	<action-view name="action-open-sale-quotation-merge-form" title="Merge sale quotation" model="com.axelor.apps.base.db.Wizard">
	    <view type="form" name="sale-quotation-merge-form"/>
	</action-view>

    <action-view name="action-sale-order-view-cancel" title="Cancellation" model="com.axelor.apps.sale.db.SaleOrder">
	  	<view type="form" name="sale-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-condition name="action-sale-order-cancel-reason-check">
		<check error="A cancel reason must be selected" field="cancelReason" if="cancelReason == null || cancelReason == 0"/>
	</action-condition>

	<action-method name="action-sale-order-method-confirm-cancel">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="cancelSaleOrder"/>
	</action-method>

	<action-record name="action-record-load-dummy-field-confirm-merge-saleorder" model="com.axelor.apps.base.db.Wizard">
		<field name="priceListToCheck" expr="eval: contextPriceListToCheck"/>
		<field name="contactPartnerToCheck" expr="eval: contextContactPartnerToCheck"/>
		<field name="locationToCheck" expr="eval: contextLocationToCheck"/>
		<field name="partnerId" expr="eval: contextPartnerId"/>
	</action-record>

    <action-record name="action-sale-order-record-currency" model="com.axelor.apps.sale.db.SaleOrder">
	    <field name="currency" expr="eval: company?.currency" if="!template"/>
	</action-record>

    <action-record name="action-sale-order-record-default" model="com.axelor.apps.sale.db.SaleOrder">
    	<field name="exTaxTotal" expr="eval: 0"/>
    	<field name="taxTotal" expr="eval: 0"/>
    	<field name="inTaxTotal" expr="eval: 0"/>
    	<field name="amountInvoiced" expr="eval: 0"/>
        <field name="advanceTotal" expr="eval: 0"/>
    	<field name="creationDate" expr="eval: __date__"/>
    	<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="salemanUser" expr="eval:__user__" if="__config__.app.getApp('sale').getSalemanSelect() == 1"/>
    	<field name="salemanUser" expr="eval: clientPartner?.getUser()" if="__config__.app.getApp('sale').getSalemanSelect() == 2"/>
    	<field name="team" expr="call:com.axelor.apps.base.service.user.UserService:getUserActiveTeam()"/>
    	<field name="template" expr="eval:_template" />
		<field name="printingSettings" expr="eval: __user__.activeCompany?.printingSettings" if="__user__.activeCompany != null"/>
    </action-record>

    <action-record name="action-sale-order-record-company-configuration" model="com.axelor.apps.sale.db.SaleOrder">
    	<field name="duration" expr="eval: company?.saleConfig?.defaultValidityDuration"/>
    </action-record>

    <action-record name="action-sale-order-record-partner" model="com.axelor.apps.sale.db.SaleOrder">
    	<field name="paymentCondition" expr="eval: clientPartner?.paymentCondition" if="__config__.app.isApp('account') &amp;&amp; clientPartner?.paymentCondition != null"/>
    	<field name="paymentCondition" expr="eval: company?.accountConfig?.defPaymentCondition" if="__config__.app.isApp('account') &amp;&amp; clientPartner?.paymentCondition == null"/>
 		<field name="currency" expr="eval: clientPartner?.currency" if="!template"/>
		<field name="paymentMode" expr="eval: clientPartner?.inPaymentMode" if="__config__.app.isApp('supplychain') &amp;&amp; clientPartner?.inPaymentMode != null"/>
		<field name="paymentMode" expr="eval: company?.accountConfig?.inPaymentMode" if="__config__.app.isApp('supplychain') &amp;&amp; clientPartner?.inPaymentMode == null"/>
		<field name="mainInvoicingAddress" expr="call:com.axelor.apps.base.service.PartnerService:getInvoicingAddress(clientPartner)" if="clientPartner != null"/>
		<field name="deliveryAddress" expr="call:com.axelor.apps.base.service.PartnerService:getDeliveryAddress(clientPartner)" if="clientPartner != null"/>
		<field name="hideDiscount" expr="eval: priceList?.hideDiscount"/>
		<field name="companyBankDetails" expr="call: com.axelor.apps.account.service.AccountingSituationService:getCompanySalesBankDetails(company, clientPartner)"/>
			<field name="isNeedingConformityCertificate" expr="eval: clientPartner?.isNeedingConformityCertificate"/>
		<field name="salemanUser" expr="eval:__user__" if="__config__.app.getApp('sale').getSalemanSelect() == 1"/>
		<field name="salemanUser" expr="eval: clientPartner?.getUser()" if="__config__.app.getApp('sale').getSalemanSelect() == 2"/>
		<field name="invoiceComments" expr="eval: clientPartner?.invoiceComments"/>
		<field name="deliveryComments" expr="eval: clientPartner?.deliveryComments"/>
		<field name="description" expr="eval: clientPartner?.saleOrderComments"/>
		<field name="pickingOrderComments" expr="eval: clientPartner?.pickingOrderComments"/>
		<field name="proformaComments" expr="eval: clientPartner?.proformaComments"/>
    </action-record>

    <action-record name="action-sale-order-record-hide-discount" model="com.axelor.apps.sale.db.SaleOrder">
		<field name="hideDiscount" expr="eval: priceList?.hideDiscount" if="priceList"/>
	</action-record>

		<action-record name="action-record-so-contact-partner-change" model="com.axelor.apps.sale.db.SaleOrder">
		  <field name="clientPartner" expr="eval: contactPartner.mainPartner" if="!clientPartner"/>
		</action-record>

    <action-method name="action-sale-order-record-compute-end-of-validity-date">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="computeEndOfValidityDate"/>
    </action-method>

    <action-method name="action-sale-order-method-remove-subline">
        <call class="com.axelor.apps.sale.web.SaleOrderController" method="removeSubLines"/>
	</action-method>

    <action-method name="action-sale-order-method-compute">
        <call class="com.axelor.apps.sale.web.SaleOrderController" method="compute"/>
  	</action-method>

  	<action-method name="action-sale-order-method-compute-margin">
        <call class="com.axelor.apps.sale.web.SaleOrderController" method="computeMargin"/>
  	</action-method>

	<action-attrs name="action-sale-order-attrs-collapse-specific-settings-group">
		<attribute name="collapse" for="specificSettings" expr="eval: true"/>
	</action-attrs>

	<action-attrs name="action-sale-order-domain-on-contact-partner">
		<attribute for="contactPartner" if="clientPartner != null &amp;&amp; !clientPartner.contactPartnerSet.empty" name="domain" expr="eval: &quot;self.id IN (${clientPartner.contactPartnerSet?.collect{it.id}.join(',')})&quot;"/>
 		<attribute for="contactPartner" if="clientPartner != null &amp;&amp; clientPartner.contactPartnerSet.empty" name="domain" expr="eval: &quot;self.id IN (0)&quot;"/>
 		<attribute for="contactPartner" if="clientPartner == null" name="domain" expr="eval: &quot;self.isContact = true AND :company member of self.companySet&quot;"/>
	</action-attrs>

    <action-attrs name="action-sale-order-attrs-domain-main-invoicing-address">
		<attribute name="domain" for="mainInvoicingAddress" expr="eval: &quot;self.id IN (${(clientPartner?.partnerAddressList?.findAll{it.isInvoicingAddr}.collect{it.address.id}+[null]).join(',')})&quot;"/>
    </action-attrs>

    <action-attrs name="action-sale-order-attrs-domain-delivery-address">
		<attribute name="domain" for="deliveryAddress" expr="eval: &quot;self.id IN (${(clientPartner?.partnerAddressList?.findAll{it.isDeliveryAddr}.collect{it.address.id}+[null]).join(',')})&quot;"/>
    </action-attrs>

	<action-attrs name="action-sale-order-attrs-hidden-bank-details">
		<attribute for="companyBankDetails" name="hidden" expr="eval: !__config__.app.getApp('base').getManageMultiBanks()"/>
	</action-attrs>

	<action-method name="action-sale-order-method-set-client-partner-domain">
        <call class="com.axelor.apps.sale.web.SaleOrderController" method="getSaleOrderPartnerDomain" />
	</action-method>

	<search-filters name="sale-order-filters" model="com.axelor.apps.sale.db.SaleOrder" title="Sales Order filters">
		<field name="saleOrderLineList.product.name" title="Product Name"/>
		<field name="companyExTaxTotal" title="Total W.T. in company currency"/>
		<field name="cancelReason" hidden="true"/>
		<field name="deliveryAddress" hidden="true"/>
		<field name="mainInvoicingAddress" hidden="true"/>
		<filter title="My Proposals">
			<domain>(self.statusSelect = 1 or self.statusSelect = 2) and self.salemanUser.id = :_internalUser</domain>
		</filter>
		<filter title="My Sales">
			<domain>self.statusSelect = 3 and self.salemanUser.id = :_internalUser</domain>
		</filter>
		<filter title="My Team Proposals">
			<domain>(self.statusSelect = 1 or self.statusSelect = 2) and self.team = :_myActiveTeam</domain>
		</filter>
		<filter title="My Team Sales">
			<domain>self.statusSelect = 3 and self.team = :_myActiveTeam</domain>
		</filter>
	</search-filters>

	<action-view name="action-sale-order-view-schedule-event" title="Schedule Event" model="com.axelor.apps.crm.db.Event">
    	<view type="form" name="event-form"/>
    	<context name="_saleOrder" expr="eval:_ids != null ? __repo__(SaleOrder).find(_ids.get(0)) : __this__"/>
    	<context name="_clientPartner" expr="eval: _ids != null ? __repo__(SaleOrder).find(_ids.get(0)).clientPartner : __self__.clientPartner" />
  		<context name="_contactPartner" expr="eval: _ids != null ? __repo__(SaleOrder).find(_ids.get(0)).contactPartner : __self__.contactPartner" />
    </action-view>

    <action-view name="action-sale-order-view-register-advance-payment" title="Register a deposit" model="com.axelor.apps.sale.db.AdvancePayment">
    	<view type="form" name="advance-payment-form"/>
    	<view-param name="popup" value="reload"/>
	  	<view-param name="show-toolbar" value="false"/>
	  	<view-param name="forceEdit" value="true" />
	  	<view-param name="popup-save" value="true"/>
 	  	<view-param name="show-confirm" value="true"/>
	  	<context name="_saleOrder" expr="eval: __this__"/>
    </action-view>

	<action-view name="action-view-show-stock-move-line" title="Customer deliveries" model="com.axelor.apps.stock.db.StockMoveLine">
		<view type="grid" name="stock-move-line-sale-order-grid"/>
		<view type="form" name="stock-move-line-all-form"/>
		<domain>self.stockMove.originTypeSelect LIKE 'com.axelor.apps.sale.db.SaleOrder' AND self.stockMove.originId = :saleOrder</domain>
		<context name="saleOrder" expr="eval: __self__.id"/>
	</action-view>
	
	<action-view name="action-sale-order-view-stock-moves" title="Stock moves" model="com.axelor.apps.stock.db.StockMove">
  		<view type="grid" name="stock-move-sale-order-grid"/>
		<view type="form" name="stock-move-form"/>
		<domain>self.originTypeSelect LIKE 'com.axelor.apps.sale.db.SaleOrder' AND self.originId = :saleOrder</domain>
		<context name="saleOrder" expr="eval: __self__.id"/>
		<context name="_userType" expr="eval: __repo__(StockMove).USER_TYPE_SALESPERSON"/>
  	</action-view>
    
    
	<action-view name="action-view-open-quotation-lines" title="Quotation lines" model="com.axelor.apps.sale.db.SaleOrderLine">
		<view type="grid" name="sale-order-line-menu-grid"/>
		<view type="form" name="sale-order-line-all-form"/>
		<domain>self.saleOrder.statusSelect in (1,2)</domain>
	</action-view>

	<action-view name="action-view-open-sale-order-lines" title="Sale order lines" model="com.axelor.apps.sale.db.SaleOrderLine">
		<view type="grid" name="sale-order-line-menu-grid"/>
		<view type="form" name="sale-order-line-all-form"/>
		<domain>self.saleOrder.statusSelect IN (:_status)</domain>
  		<context name="_status" expr="eval: status"/>
	</action-view>

	<action-view name="action-sale-order-view-generate-line" title="Generate configurator" model="com.axelor.apps.sale.db.Configurator">
        <view type="form" name="generate-configurator-form"/>
		<view-param name="popup" value="reload"/>
		<view-param name="popup-save" value="false"/>
		<view-param name="show-toolbar" value="false"/>
		<view-param name="show-confirm" value="false"/>
        <context name="_saleOrderId" expr="eval: id"/>
	</action-view>
	
	<action-view name="action-sale-order-view-manuf-orders" title="Manufacturing Orders" model="com.axelor.apps.production.db.ManufOrder">
		<view type="grid" name="manuf-order-grid"/>
		<view type="form" name="manuf-order-form"/>
		<domain>self.saleOrder.id = :id</domain>
	</action-view>

	<action-view name="action-sale-order-view-show-generated-po" title="Generated purchase orders" model="com.axelor.apps.purchase.db.PurchaseOrder">
		<view type="grid" name="purchase-order-grid"/>
		<view type="form" name="purchase-order-form"/>
    <domain>self.generatedSaleOrderId = :id</domain>
	</action-view>
	
	<action-view name="action-sale-order-view-invoicing-advance-payment-wizard" title="" model="com.axelor.apps.sale.db.SaleOrder">
		<view type="form" name="sale-order-invoicing-advance-payment-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: id"/></action-view>

	<action-validate name="action-validate-sale-order-check-selection">
		<error message="You have to choose at least one sale order" if="saleOrderToMerge == null || (saleOrderToMerge != null &amp;&amp; saleOrderToMerge.size() == 0)"/>
	</action-validate>

	<action-validate name="action-validate-sale-quotation-check-selection">
		<error message="You have to choose at least one sale quotation" if="saleQuotationToMerge == null || (saleQuotationToMerge != null &amp;&amp; saleQuotationToMerge.size() == 0)"/>
	</action-validate>
	
	<action-record name="action-saleorder-record-template" model="com.axelor.apps.sale.db.SaleOrder">
		<field name="template" expr="true"/>
		<field name="templateUser" expr="eval: __user__"/>
	</action-record>

	<action-method name="action-sale-order-method-generate-template">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="generateViewTemplate"/>
	</action-method>

	<action-method name="action-sale-order-method-generate-order">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="generateViewSaleOrder"/>
	</action-method>

	<action-method name="action-sale-order-method-create-order">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="createSaleOrder"/>
	</action-method>
	
	<action-method name="action-sale-order-method-create-template">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="createTemplate"/>
	</action-method>

	<action-method name="action-sale-order-method-address-str">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="computeAddressStr"/>
	</action-method>

	<action-method name="action-sale-order-method-fill-company-bank-details">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="fillCompanyBankDetails"/>
 	</action-method>

	<action-method name="action-sale-order-method-edit-order">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="enableEditOrder"/>
	</action-method>

    <action-method name="action-method-sale-order-validate-changes">
        <call class="com.axelor.apps.sale.web.SaleOrderController" method="validateChanges" />
    </action-method>

	<action-method name="action-sale-method-filter-printing-settings">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="filterPrintingSettings"/>
	</action-method>

	<action-method name="action-sale-method-printing-settings-default-values">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="fillDefaultPrintingSettings"/>
	</action-method>

	<action-validate name="action-sale-order-validate-check-on-confirm">
		<alert message="The total amount of quotation is zero. Do you want to proceed ?" if="exTaxTotal == 0 &amp;&amp; !saleOrderLineList.isEmpty()"/>
	</action-validate>

	<action-record name="action-sale-record-update-info-company" model="com.axelor.apps.sale.db.SaleOrder">
		<field name="tradingName" expr="eval: null" if="__config__.app.getApp('base').enableTradingNamesManagement"/>
		<field name="printingSettings" expr="eval: company?.printingSettings"/>
		<field name="incoterm" expr="eval: __repo__(PartnerStockSettings).all().filter('self.company = ? AND self.partner = ?', company, clientPartner).fetchOne()?.incoterm" if="company != null &amp;&amp; clientPartner != null"/>
	</action-record>

	<action-record name="action-sale-order-manual-unblock" model="com.axelor.apps.sale.db.SaleOrder">
		<field name="manualUnblock" expr="true"/>
	</action-record>

	<action-attrs name="action-sale-order-record-project-default-fields" if-module="axelor-business-project">
		<attribute for="$_elementStartDate" name="value" expr="#{__datetime__}"/>
	</action-attrs>
	
	<action-attrs name="action-sale-order-attrs-external-reference">
		<attribute name="hidden" for="duplicateReferenceLabel" expr="eval: !((externalReference != null &amp;&amp; id != null &amp;&amp; __repo__(SaleOrder).all().filter('self.externalReference = ? AND self.id != ?', externalReference , id).count() > 0)
                 || (externalReference != null &amp;&amp; id == null &amp;&amp; __repo__(SaleOrder).all().filter('self.externalReference = ?', externalReference).count() > 0))"/>
	</action-attrs>
	
	<action-attrs name="action-sale-order-attrs-availability-request-label">
		<attribute name="hidden" for="availabilityRequestLabel" expr="eval: !(__repo__(StockMove).all().filter('self.originTypeSelect LIKE ? AND self.originId = ? AND self.availabilityRequest = ? AND self.statusSelect = ?','com.axelor.apps.sale.db.SaleOrder',id,true,__repo__(StockMove).STATUS_PLANNED).count() > 0)"/>
	</action-attrs>

	<action-method name="action-sale-order-method-fill-sale-order-lines-estimated-date">
		<call class="com.axelor.apps.supplychain.web.SaleOrderController" method="fillSaleOrderLinesEstimatedDate"/>
	</action-method>

	<action-attrs name="action-sale-order-template-hide-allocated-qty">
		<attribute name="hidden" for="saleOrderLineList.reservedQty" expr="true"/>
		<attribute name="hidden" for="saleOrderLineList.allocateAll" expr="true"/>
		<attribute name="hidden" for="saleOrderLineList.deallocate" expr="true"/>
	</action-attrs>

  <action-validate name="action-sale-order-validate-client-partner">
		<error message="Please select a customer" if="!clientPartner"/>
	</action-validate>

	<action-method name="action-sale-order-method-generate-sale-order-from-template-wizard">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="generateSaleOrderWizard"/>
	</action-method>

	<action-method name="action-sale-order-method-change-sale-order-line-tax">
		<call class="com.axelor.apps.sale.web.SaleOrderController" method="updateSaleOrderLineTax"/>
	</action-method>

	<action-attrs name="action-sale-order-attrs-template-deafult-currency">
		<attribute name="value" for="currency" expr="eval: _clientPartnerCurrency" if="_clientPartnerCurrency"/>
	</action-attrs>

	<action-attrs name="action-sale-order-attrs-set-required">
		<attribute name="required" for="$_projectGeneratorType" expr="eval: statusSelect == com.axelor.apps.sale.db.repo.SaleOrderRepository.STATUS_FINALIZED_QUOTATION &amp;&amp; __config__.app.getApp('business-project')?.getAutomaticProject()"/>
	</action-attrs>

  <action-method name="action-sale-order-method-check-analytic-distribution-template">
    <call class="com.axelor.apps.supplychain.web.SaleOrderController" method="checkSaleOrderAnalyticDistributionTemplate" if="company?.saleConfig?.isAnalyticDistributionRequired"/>
  </action-method>
  
  <action-method name="action-sale-order-method-generate-advance-payment">
  	<call class="com.axelor.apps.supplychain.web.SaleOrderController" method="generateAdvancePaymentInvoice"/>
  </action-method>
  
</object-views>
