<?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-batch-grid" title="Sale batches" model="com.axelor.apps.sale.db.SaleBatch">
    <field name="actionSelect" />
    <field name="code" x-bind="{{code|unaccent|uppercase}}" />
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="createdOn"/>
		<field name="createdBy" form-view="user-form" grid-view="user-grid"/>
  </grid>
 
	<form onLoad="action-group-supplychain-salebatch-onload" onNew="action-group-supplychain-salebatch-onnew" name="sale-batch-form" title="Sale Batch" model="com.axelor.apps.sale.db.SaleBatch" width="large">
	  <panel name="mainPanel" >
	    <field name="actionSelect" onChange="action-sale-batch-attrs-action-select"/>
	    <field name="code" x-bind="{{code|unaccent|uppercase}}" onChange="action-base-batch-condition-check-unique-code"/>
	    <field name="company" widget="SuggestBox" form-view="company-form" grid-view="company-grid" />
	  </panel>
	  <panel name="createdPanel">
	    <field name="createdOn" title="Created on"/>
	    <field name="createdBy" title="Created by" form-view="user-form" grid-view="user-grid"/>
	    <button name="invoicingBatchBtn" title="Invoicing batch" onClick="save,action-sale-batch-method-action-invoicing"/>
	  </panel>
	  <panel-tabs name="mainPanelTab">    
	    <panel name="descriptionPanel" title="Description">
	      <field name="description" showTitle="false" colSpan="12"/>      
	    </panel>
		<panel-related name="batchListPanel" field="batchList" colSpan="12" form-view="batch-form" grid-view="batch-grid" readonly="true" />
	  </panel-tabs>
	</form>
    
    <!-- ACTION GROUPs -->
    <action-group name="action-group-supplychain-salebatch-onload">
    	<action name="action-sale-batch-attrs-action-select"/>
    	<action name="action-sale-batch-attrs-action-select"/>
    </action-group>
    
    <action-group name="action-group-supplychain-salebatch-onnew">
    	<action name="action-sale-batch-record-on-new"/>
    	<action name="action-sale-batch-attrs-action-select"/>
    </action-group>
    
    <!-- ACTION RECORD -->
    <action-record name="action-sale-batch-record-on-new" model="com.axelor.apps.sale.db.SaleBatch">
		<field name="createdOn" expr="eval: __config__.app.getTodayDate()"/>
		<field name="createdBy" expr="__user__"/>
		<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"/>
	</action-record>
    
    <!-- ACTION METHOD -->
	<action-method name="action-sale-batch-method-action-invoicing">
		<call class="com.axelor.apps.supplychain.web.SaleBatchController" method="actionInvoicing"/>
	</action-method>
	
    <!-- ACTION ATTRS -->
    <action-attrs name="action-sale-batch-attrs-action-select">
	    <attribute name="hidden" expr="eval: actionSelect != 1" for="InvoicingPage"/>
	</action-attrs>
	
</object-views>