<?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="product-expense-grid" title="Expense types" model="com.axelor.apps.base.db.Product" orderBy="name">
	    <field name="code" x-bind="{{code|unaccent|uppercase}}"/>
	    <field name="name" width="400"/>
	    <field name="productFamily" form-view="product-family-form" grid-view="product-family-grid"/>
	    <field name="productTypeSelect" width="100"/>
	    <field name="saleSupplySelect"/>
	    <field name="unit" width="70" form-view="unit-form" grid-view="unit-grid"/>
	    <field name="personalExpense" />
	    <button name="sendByEmailBtn" title="Send Email" icon="fa-envelope" onClick="action-send-by-email-with-template"/>
    </grid>

   <form name="product-expense-form" onNew="action-group-base-product-expense-onnew" title="Expense type" model="com.axelor.apps.base.db.Product" onLoad="action-product-attrs-scale-and-precision">
        <toolbar>
    		<button name="sendByEmailBtn" title="Send Email" icon="fa-envelope" onClick="action-send-by-email-with-template"/>
			<button name="showProductSheetBtn" title="Product sheet" icon="fa-print" onClick="save,action-product-method-show-product-sheet"/>
    	</toolbar>
	    <panel name="mainPanel">
			<field name="name" showTitle="false" css="label-bold bold" placeholder="Name"	colSpan="8"/>
			<field name="code" x-bind="{{code|unaccent|uppercase}}"  showTitle="false" css="label-bold bold" placeholder="Code" colSpan="4" required="true" if="!__config__.app.getApp('base').getGenerateProductSequence()"/>
			<field name="code" x-bind="{{code|unaccent|uppercase}}"  showTitle="false" css="label-bold bold" placeholder="Code" colSpan="4" if="__config__.app.getApp('base').getGenerateProductSequence()" readonly="true"/>
			<panel name="productTypologyPanel" title="Product typology" colSpan="12">
				<field name="productTypeSelect" readonly="true" />
				<field name="deductLunchVoucher" hideIf="!expense" />
				<field name="blockExpenseTax" />
				<field name="personalExpense" />
				<field name="unavailableToUsers"/>
				<field name="saleSupplySelect" readonly="true" hidden="true"/>
                <field name="expense" hidden="true"/>
			</panel>
			<panel name="categorizationPanel" title="Categorization" colSpan="12">
				<field name="productFamily" colSpan="12" form-view="product-family-form" grid-view="product-family-grid"/>
			</panel>
	    </panel>
	    <panel-tabs name="productSpecificAttrsPanelTab" title="Product specific attributes">
			<panel name="salePanel" title="Sale" showTitle="false">
				<panel name="subSalePanel" colSpan="6" title="Sales">
				    <field name="sellable" colSpan="12"/>
					<field name="salePrice" colSpan="12" hideIf="!sellable"/>
					<field name="saleCurrency" canEdit="false" colSpan="12" hideIf="!sellable"/>
					<field name="unit" colSpan="12" hideIf="!sellable" form-view="unit-form" grid-view="unit-grid"/>
				</panel>
				<panel colSpan="12" name="internalDescriptionPanel" title="Internal description" >
					<field name="internalDescription" showTitle="false" colSpan="12"/>
				</panel>
				<panel colSpan="12" name="descriptionPanel" title="Description" hidden="true" showIf="sellable">
					<field name="description" showTitle="false" colSpan="12" widget="html"/>
				</panel>
			</panel>
	        <panel-related name="accountManagementListPanel" title="Accounting" field="accountManagementList" colSpan="12" domain="self.typeSelect = 1" showTitle="false" form-view="account-management-form" grid-view="account-management-product-grid"/>
	        <panel name="trackingNumberPanel" title="Tracking number" showIf="productTypeSelect != 'service'" showTitle="false" if-module="axelor-stock" if="__config__.app.isApp('stock')">
        		<panel colSpan="12" name="warantyDetailsPanel">
        			<field name="hasWarranty" />
	            	<field name="warrantyNbrOfMonths"  showIf="hasWarranty"/>
        	 		<field name="isPerishable" />
	            	<field name="perishableNbrOfMonths" showIf="isPerishable"/>
        	 	</panel>
        	 	<panel name="trackingNumberConfigPanel" colSpan="12">
		            <field name="trackingNumberConfiguration" canNew="true" grid-view="tracking-number-configuration-grid" form-view="tracking-number-configuration-form"/>
	            </panel>
	        </panel>
	  	</panel-tabs>
	</form>    
	
	<grid name="product-activity-grid" title="Product Activities" model="com.axelor.apps.base.db.Product" orderBy="name">
   		<toolbar>
        	<button name="catalogBtn" title="Catalog" onClick="action-print-product-catalog" icon="fa-book"/>
	    </toolbar>
	    <field name="code" x-bind="{{code|unaccent|uppercase}}"/>
	    <field name="name" width="400"/>
	    <field name="productCategory" form-view="product-category-form" grid-view="product-category-grid"/>
	    <field name="productFamily" form-view="product-family-form" grid-view="product-family-grid"/>
	    <field name="productTypeSelect" width="100"/>
	    <field name="saleSupplySelect"/>
	    <field name="unit" width="70" form-view="unit-form" grid-view="unit-grid"/>
	    <button name="sendByEmailBtn" title="Send Email" icon="fa-envelope" onClick="action-send-by-email-with-template"/>
    </grid>

   <form name="product-activity-form" title="Product Activity" model="com.axelor.apps.base.db.Product" 
   onNew="action-group-base-product-onnew, action-product-activity-record-default-activity" 
   onLoad="action-product-attrs-scale-and-precision" width="large">
    <toolbar>
    		<button name="sendByEmailBtn" title="Send Email" icon="fa-envelope" onClick="action-send-by-email-with-template"/>
			<button name="showProductSheetBtn" title="Product sheet" icon="fa-print" onClick="save,action-product-method-show-product-sheet"/>
    	</toolbar>
	    <panel name="mainPanel">
        <field name="productTypeSelect" hidden="true"/>
          <panel name="productDetailsPanel" colSpan="12">
            <panel name="imagePanel" colSpan="2">
              <field name="picture" showTitle="false" widget="Image" colSpan="12"/>
            </panel>
            <panel name="subProductDetailsPanel" colSpan="10">
              <field name="fullName" showTitle="false" css="label-bold bold large" colSpan="12">
                <editor x-show-titles="false">
                  <field name="code" x-bind="{{code|unaccent|uppercase}}" showTitle="false" colSpan="3" css="label-bold bold large" placeholder="Code" />
                  <field name="name" showTitle="false" colSpan="9" css="label-bold bold large" placeholder="Name"/>
                </editor>
              </field>
              <panel name="productTypologyPanel" title="Product typology" colSpan="6" colWidths="30%,70%">
                <field name="inAti"/>
                <field name="isAnalyticCapture" if-module="axelor-account"  if="__config__.app.isApp('account')" />
                <field name="deductLunchVoucher" hideIf="!expense" colSpan="12"/>
                <field name="expense" hidden="true"/>
              </panel>
              <panel name="categorizationPanel" title="Categorization" colSpan="6" colWidths="30%,70%">
                <field name="productFamily" colSpan="12" form-view="product-family-form" grid-view="product-family-grid"/>
                <field name="productCategory" colSpan="12" form-view="product-category-form" grid-view="product-category-grid"/>
              </panel>
            </panel>
          </panel>
        </panel>
	    <panel-tabs name="productSpecificAttrsPanelTab" title="Product specific attributes">
			<panel name="salePanel" title="Sale" showTitle="false">
				<panel name="subSalePanel" colSpan="6" title="Sales">
				    <field name="sellable" colSpan="12"/>
					<field name="salePrice" colSpan="12" hideIf="!sellable"/>
					<field name="saleCurrency" canEdit="false" colSpan="12" hideIf="!sellable" form-view="currency-form" grid-view="currency-grid"/>
					<field name="unit" colSpan="12" hideIf="!sellable" form-view="unit-form" grid-view="unit-grid"/>
				</panel>
				<panel colSpan="6" name="productDatesPanel" title="Product dates">
					<field name="startDate" colSpan="12"/>
					<field name="endDate" onChange="action-group-base-product-enddate-onchange" colSpan="12"/>
				</panel>
				<panel colSpan="6" name="descriptionPanel" title="Description">
					<field name="description" showTitle="false" colSpan="12" widget="html"/>
				</panel>
				<panel colSpan="6" name="internalDescriptionPanel" title="Internal description" >
					<field name="internalDescription" showTitle="false" colSpan="12" widget="html"/>
				</panel>
			</panel>
			<panel name="costsPanel" title="Costs" showTitle="false">
				<panel name="subCostsPanel" title="Costs" colSpan="6">
					<field name="costPrice" onChange="action-product-record-compute-sale-price" colSpan="12"/>
					<field name="managPriceCoef" onChange="action-product-record-compute-sale-price" colSpan="12"/>
				</panel>        
			</panel>
	        <panel-related name="accountManagementListPanel" title="Accounting" field="accountManagementList" colSpan="12" domain="self.typeSelect = 1" showTitle="false" form-view="account-management-form" grid-view="account-management-product-grid"/>
	  	</panel-tabs>
	</form>

	<cards name="product-activity-cards" model="com.axelor.apps.base.db.Product" title="Product Activities" orderBy="code,name" width="25%" css="rect-image">
		<toolbar>
			<button name="catalogBtn" title="Catalog" onClick="action-print-product-catalog" icon="fa-book"/>
		</toolbar>
		<field name="picture"/>
		<field name="fullName"/>
		<field name="unit"/>
		<field name="salePrice" x-scale="2"/>
		<field name="saleCurrency.symbol"/>
		<field name="productFamily"/>
		<field name="productCategory"/>
		<field name="internalDescription"/>
		<template><![CDATA[
			<div class="span12"><strong>{{fullName}}</strong></div>
			<div>
			  <div class="span4 card-image">
				<img ng-show="picture" ng-src="{{$image('picture', 'content')}}" />
				<img ng-show="!picture" src="img/product-default.png" />
			  </div>
			  <div class="span8">
				<span>{{$fmt('salePrice')}} {{saleCurrency.symbol}}<br/>
				{{unit.name}}<br/>
				{{productFamily.name}}<br/>
				{{productCategory.name}}</span>
			  </div>
			</div>
			<div class="span12" ng-bind-html="internalDescription"></div>
		]]>
		</template>
	</cards>
    
    <action-group name="action-group-base-product-expense-onnew">
    	<action name="action-product-record-default-new-expense"/>
    	<action name="action-product-record-sale-supply-select"/>
    	<action name="action-product-record-in-ati"/>
    	<action name="action-product-attrs-scale-and-precision"/>
    </action-group>
    
    <action-record name="action-product-activity-record-default-activity" model="com.axelor.apps.base.db.Product">
    	<field name="isActivity" expr="true"/>
    	<field name="productTypeSelect" expr="service"/>
    </action-record>
    
    <action-record name="action-product-record-default-new-expense" model="com.axelor.apps.base.db.Product">
    	<field name="productTypeSelect" expr="storable"/>
    	<field name="procurementMethodSelect" expr="buy"/>
    	<field name="startDate" expr="eval:__config__.app.getTodayDate()" if="startDate == null"/>
    	<field name="salePrice" expr="1"/>
    	<field name="purchasePrice" expr="1"/>
    	<field name="saleCurrency" expr="eval: _activeCompany?.currency"/>
    	<field name="purchaseCurrency" expr="eval: _activeCompany?.currency"/>
    	<field name="managPriceCoef" expr="1"/>
    	<field name="isModel" expr="eval: _isModel"/>
    	<field name="expense" expr="true"/>
    	<field name="productTypeSelect" expr="service"/>
    	<field name="saleSupplySelect" expr="0"/>
		<field name="sellable" expr="false"/>
    </action-record>
    
    <action-record name="hr-action-product-record-default-new" model="com.axelor.apps.base.db.Product">
    	<field name="expense" expr="false"/>
    </action-record>
	
</object-views>
