<?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="invoicing-project-grid" title="Invoicing business projects" model="com.axelor.apps.businessproject.db.InvoicingProject">
    <field name="invoice" width="120"/>
		<field name="project" form-view="project-form" grid-view="project-grid"/>
		<field name="deadlineDate"/>
		<field name="createdOn"/>
		<field name="comments"/>
	</grid>

	<form name="invoicing-project-form" title="Invoicing business project" model="com.axelor.apps.businessproject.db.InvoicingProject"
		onNew="action-invoicing-project-group-on-new" onLoad="action-invoicing-project-attrs-title-project" width="large">
		<toolbar>
  			<button name="deleteBtn" hidden="true" showIf="invoice == null" title="Delete"/>
  		</toolbar>

		<panel name="mainPanel">
		  <field name="statusSelect" widget="NavSelect" showTitle="false" colSpan="12" readonly="true"/>
			<field name="project" form-view="project-form" grid-view="project-grid" onChange="action-invoicing-project-method-fill-in"/>
			<field name="deadlineDate" readonlyIf="invoice" onChange="action-invoicing-project-method-fill-in"/>
			<field name="attachAnnexToInvoice" widget="boolean-switch"  readonlyIf="invoice"/>
			<button name="generateInvoiceBtn" title="Generate Invoice" onClick="save,action-invoicing-project-method-generate-invoice" hideIf="invoice != null"/>
			<field name="invoice" readonly="true" form-view="invoice-form" grid-view="invoice-grid" edit-window="blank"/>
			<button name="seeLinkedTimesheetLinesBtn" title="See Linked Timesheet Lines" onClick="action-invoicing-project-show-timesheet-lines" hidden="true" showIf="invoice != null"/>
		</panel>

        <panel name="commentsPanel">
            <field name="comments" colSpan="12" />
        </panel>

		<panel-tabs name="mainPanelTab">
			<panel name="listPanel" title="Elements To Invoice">
				<panel-related title="Sale" field="saleOrderLineSet"
							   colSpan="12" canNew="false" canEdit="false"
							   canSelect="false"
							   form-view="sale-order-line-form"
							   grid-view="sale-order-line-grid"
							   showIf="saleOrderLineSet &amp;&amp; saleOrderLineSet.length &gt; 0"
							   readonlyIf="invoice"
							   name="saleOrderLineSetPanel"/>
				<panel-related title="Purchase" field="purchaseOrderLineSet"
							   colSpan="12" canNew="false" canEdit="false"
							   canSelect="false"
							   grid-view="purchase-order-line-invoicing-project-grid"
							   form-view="purchase-order-line-form"
							   showIf="purchaseOrderLineSet &amp;&amp; purchaseOrderLineSet.length &gt; 0"
							   readonlyIf="invoice"
							   name="purchaseOrderLineSetPanel"/>
				<panel-related title="Time spent" field="logTimesSet"
							   colSpan="12" canNew="false" canEdit="false"
							   canSelect="false"
							   grid-view="timesheet-line-project-grid"
							   form-view="timesheet-line-project-form"
							   showIf="logTimesSet &amp;&amp; logTimesSet.length &gt; 0"
							   readonlyIf="invoice"
							   name="logTimesSetPanel"/>
				<panel-related title="Expenses" field="expenseLineSet"
							   colSpan="12" canNew="false" canEdit="false"
							   canSelect="false" form-view="expense-line-form"
							   grid-view="expense-line-grid"
							   showIf="expenseLineSet &amp;&amp; expenseLineSet.length &gt; 0"
							   readonlyIf="invoice"
							   name="expenseLineSetPanel"/>

				<panel-related field="projectSet" colSpan="12" canNew="false"
							   canEdit="false" canSelect="false"
							   form-view="project-form" grid-view="project-grid"
							   showIf="projectSet &amp;&amp; projectSet.length &gt; 0"
							   readonlyIf="invoice"
							   name="projectSetPanel"/>

				<panel-related title="Production" field="manufOrderSet"
							   colSpan="12" canNew="false" canEdit="false"
							   canSelect="false"
							   if-module="axelor-business-production"
							   grid-view="manuf-order-invoicing-project-grid"
							   form-view="manuf-order-form"
							   showIf="manufOrderSet &amp;&amp; manufOrderSet.length &gt; 0"
							   readonlyIf="invoice"
							   if="__config__.app.isApp('production') &amp;&amp; __config__.app.getApp('production').getManageBusinessProduction()"
							   name="manufOrderSetPanel"/>
				
				<panel-related field="teamTaskSet" colSpan="12" canNew="false"
							   canEdit="false" canSelect="false"
							   form-view="team-task-form" grid-view="business-project-team-task-grid"
							   showIf="teamTaskSet &amp;&amp; teamTaskSet.length &gt; 0"
							   readonlyIf="invoice" 
							   name="teamTaskSetPanel"/>
			</panel>

			<panel name="configurationsPanel" title="Configurations" readonlyIf="invoice">
                <field name="saleOrderLineSetPrioritySelect"/>
                <field name="purchaseOrderLineSetPrioritySelect"/>
                <field name="logTimesSetPrioritySelect"/>
                <field name="expenseLineSetPrioritySelect"/>
                <field name="projectSetPrioritySelect"/>
                <field name="teamTaskSetPrioritySelect"/>
            </panel>
        </panel-tabs>

	</form>
	
	<action-group name="action-invoicing-project-group-on-new">
		<action name="action-invoicing-project-attrs-title-project"/>
		<action name="action-invoicing-project-record-default"/>
		<action name="action-invoicing-project-method-fill-in" if="project != null"/>
	</action-group>
	
	<action-method name="action-invoicing-project-method-generate-invoice">
		<call class="com.axelor.apps.businessproject.web.InvoicingProjectController" method="generateInvoice"/>
	</action-method>
	
	<action-method name="action-invoicing-project-method-fill-in">
		<call class="com.axelor.apps.businessproject.web.InvoicingProjectController" method="fillIn"/>
	</action-method>

	<action-attrs name="action-invoicing-project-attrs-title-project">
		<attribute name="title" for="project" expr="eval: __config__.app.getApp('project').getProjectLabel()" if="!com.google.common.base.Strings.isNullOrEmpty(__config__.app.getApp('project').getProjectLabel())"/>
		<attribute name="title" for="projectSet" expr="eval: __config__.app.getApp('project').getProjectLabel()" if="!com.google.common.base.Strings.isNullOrEmpty(__config__.app.getApp('project').getProjectLabel())"/>
	</action-attrs>
	
	<action-record name="action-invoicing-project-record-default" model="com.axelor.apps.businessproject.db.InvoicingProject">
		<field name="project" expr="eval: _project"/>
	</action-record>
	
	<action-view name="action-invoicing-project-show-timesheet-lines" title="Timesheet lines" model="com.axelor.apps.hr.db.TimesheetLine">
		<view name="timesheet-line-project-grid" type="grid"/>
		<view name="timesheet-line-project-form" type="form"/>
		<domain>self.id IN (:list) </domain>
  		<context name="list" expr="eval: logTimesSet.collect{it.id}"/>
	</action-view>
	
</object-views>
