<?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">
    <!-- Operation -->
    <form name="operation-form" title="Operations" onNew="action-record-operation-default-record" model="com.axelor.apps.qvm.db.QvmOperation">
        <toolbar>
            <button name="printBtn" title="Print" readonlyIf="!id" icon="fa-print" onClick="action-production-request-method-print"/>
        </toolbar>
        <panel name="statusSelectPanel" colSpan="12">
            <field name="statusSelect" title="Status" selection="operation.status.select" showTitle="false" readonly="true" colSpan="12" widget="nav-select"/>
            <field name="serialNumber" title="Serial Number" colSpan="12" readonly="true"/>
            <field name="operationType" title="Operation Type" grid-view="operation-type-grid" form-view="operation-type-form" onChange="action-record-operation-default-type-record"/>
            <field name="purchaseRequest" title="Purchase Request" grid-view="purchase-request-grid" form-view="purchase-request-form" domain="self.familleProduit = 149 and self.statusSelect != 7 and self.statusSelect != 8"/>
        </panel>
        <panel name="detailPanel" sidebar="true">
            <button name="draftBtn" title="Draft" showIf="statusSelect == 5" css="btn-info" icon="fa-edit" onClick="save,action-operation-request-set-status-draft, save"/>
            <button name="requestBtn" title="Request" showIf="statusSelect == 1" icon="fa-bullhorn" onClick="action-operation-set-seq-group,action-operation-request-set-status-request,save"/>
            <button name="acceptBtn" title="Accept" showIf="statusSelect == 2" icon="fa-check" css="btn-success" onClick="save,action-operation-request-set-status-accept,save"/>
            <button name="refuseBtn" title="Refuse" showIf="statusSelect == 2 " css="btn-warning" icon="fa-times" onClick="save,action-operation-request-set-status-refuse,save"/>
            <button name="cancelBtn" title="Cancel" showIf="statusSelect == 1 || statusSelect == 2 || statusSelect == 3 || statusSelect == 4" css="btn-danger" icon="fa-times-circle" onClick="save,action-operation-request-set-status-cancel,save"/>
        </panel>
        <panel name="machine" >
            <field name="machineName" title="Name" grid-view="machine-grid-qvm" form-view="machine-form-qvm" onChange="action-record-machine-operation-default" domain="self.typeSelect != 0"  colSpan="6"/>
            <spacer colSpan="6" />
            <field name="machineId" title="Id" colSpan="4"/>
            <field name="machineBrand" title="Brand" colSpan="4"/>
            <field name="machineModel" title="Model" colSpan="4"/>
            <field name="machineSerialNumber" title="Serial Number" colSpan="4"/>
            <field name="machineLocation" title="Location" colSpan="4"/>
            <field name="machineLocationParent" title="Location Parent" colSpan="4"/>
        </panel>
        <panel>
            <field name="fullRange" title="Full Range"/>
            <field name="operationRange" title="Operation Range"/>
            <field name="leastCount" title="Least Count"/>
            <field name="operationFrequency" title="Operation Frequency"/>
            <field name="pastOperationDate" title="Past Operation Date"/>
            <field name="operationDate" title="Operation Date"/>
            <field name="operationDueDate" title="Operation Due Date"/>
            <field name="countdown" title="Countdown"/>
            <field name="reportCertifiacteNumber" title="Report / Certifiacte Number"/>
            <field name="externalInternal" title="Internal" onChange = "internal-external-validation-title-changer" widget="boolean-switch"/>
        </panel>
        <panel sidebar="true" title="Suivi" canCollapse="true" collapseIf="true">
            <field name="createdOn"/>
            <field name="createdBy"/>
            <field name="updatedOn"/>
            <field name="updatedBy"/>
        </panel>
        <panel-mail>
            <mail-messages limit="4" />
            <mail-followers />
        </panel-mail>
    </form>

    <grid name="operation-grid" title="Operations" model="com.axelor.apps.qvm.db.QvmOperation" edit-icon="true">
        <hilite background="success" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 0"/>
        <hilite background="primary" if="$moment(operationDueDate).diff(todayDate,'days') == 0"/>
        <hilite background="danger" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 10 &amp;&amp; $moment(operationDueDate).diff(todayDate,'days') &gt; 0"/>
        <hilite background="warning" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 30 &amp;&amp; $moment(operationDueDate).diff(todayDate,'days') &gt; 10"/>
        <hilite background="info" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 40 &amp;&amp; $moment(operationDueDate).diff(todayDate,'days') &gt; 30"/>

        <field name="serialNumber" title="Serial Number"/>
        <field name="statusSelect" title="Status">
            <hilite color="primary" if="statusSelect == 2"/>
            <hilite color="success" if="statusSelect == 3"/>
            <hilite color="warning" if="statusSelect == 4"/>
            <hilite color="danger" if="statusSelect == 5"/>
        </field>
        <field name="operationType" title="Operation Type"/>
        <field name="typeSelect" title="Type"/>
        <field name="purchaseRequest" title="Purchase Request"/>
        <field name="machineName" title="Name"/>
        <field name="machineId" title="Id"/>
        <field name="machineBrand" title="Brand"/>
        <field name="machineModel" title="Model"/>
        <field name="machineSerialNumber" title="Serial Number"/>
        <field name="machineLocation" title="Location"/>
        <field name="machineLocationParent" title="Location Parent"/>
        <field name="fullRange" title="Full Range"/>
        <field name="operationRange" title="Operation Range"/>
        <field name="leastCount" title="Least Count"/>
        <field name="operationFrequency" title="Operation Frequency"/>
        <field name="pastOperationDate" title="Past Operation Date"/>
        <field name="operationDate" title="Operation Date"/>
        <field name="operationDueDate" title="Operation Due Date"/>
        <field name="countdown" title="Countdown"/>
        <field name="reportCertifiacteNumber" title="Report / Certifiacte Number"/>
        <field name="externalInternal" title="Internal"/>
    </grid>

    <!-- Calibration -->
    <form name="calibration-form" title="Calibrations" onNew="action-record-operation-default-record" model="com.axelor.apps.qvm.db.QvmOperation">
        <toolbar>
            <button name="printBtn" title="Print" readonlyIf="!id" icon="fa-print" onClick="action-production-request-method-print"/>
        </toolbar>
        <panel name="statusSelectPanel" colSpan="12">
            <field name="statusSelect" title="Status" selection="operation.status.select" showTitle="false" readonly="true" colSpan="12" widget="nav-select"/>
            <field name="serialNumber" title="Serial Number" colSpan="12" readonly="true"/>
            <field name="operationType" domain="self.typeSelect = 2" title="Operation Type" grid-view="operation-type-grid" form-view="operation-type-form" onChange="action-record-operation-default-type-record"/>
            <field name="purchaseRequest" title="Purchase Request" grid-view="purchase-request-grid" form-view="purchase-request-form" domain="self.familleProduit = 149 and self.statusSelect != 7 and self.statusSelect != 8"/>
        </panel>
        <panel name="detailPanel" sidebar="true">
            <button name="draftBtn" title="Draft" showIf="statusSelect == 5" css="btn-info" icon="fa-edit" onClick="save,action-operation-request-set-status-draft, save"/>
            <button name="requestBtn" title="Request" showIf="statusSelect == 1" icon="fa-bullhorn" onClick="action-operation-set-seq-group,action-operation-request-set-status-request,save"/>
            <button name="acceptBtn" title="Accept" showIf="statusSelect == 2" icon="fa-check" css="btn-success" onClick="save,action-operation-request-set-status-accept,save"/>
            <button name="refuseBtn" title="Refuse" showIf="statusSelect == 2 " css="btn-warning" icon="fa-times" onClick="save,action-operation-request-set-status-refuse,save"/>
            <button name="cancelBtn" title="Cancel" showIf="statusSelect == 1 || statusSelect == 2 || statusSelect == 3 || statusSelect == 4" css="btn-danger" icon="fa-times-circle" onClick="save,action-operation-request-set-status-cancel,save"/>
        </panel>
        <panel name="machine" >
            <field name="machineName" title="Name" grid-view="machine-grid-qvm" form-view="machine-form-qvm" onChange="action-record-machine-operation-default" domain="self.typeSelect != 0"  colSpan="6"/>
            <spacer colSpan="6" />
            <field name="machineId" title="Id" colSpan="4"/>
            <field name="machineBrand" title="Brand" colSpan="4"/>
            <field name="machineModel" title="Model" colSpan="4"/>
            <field name="machineSerialNumber" title="Serial Number" colSpan="4"/>
            <field name="machineLocation" title="Location" colSpan="4"/>
            <field name="machineLocationParent" title="Location Parent" colSpan="4"/>
        </panel>
        <panel>
            <field name="fullRange" title="Full Range"/>
            <field name="operationRange" title="Calibration Range"/>
            <field name="leastCount" title="Least Count"/>
            <field name="operationFrequency" title="Calibration Frequency"/>
            <field name="pastOperationDate" title="Past Calibration Date"/>
            <field name="operationDate" title="Calibration Date"/>
            <field name="operationDueDate" title="Calibration Due Date"/>
            <field name="countdown" title="Countdown"/>
            <field name="reportCertifiacteNumber" title="Report / Certifiacte Number"/>
            <field name="externalInternal" title="Internal" onChange = "internal-external-validation-title-changer" widget="boolean-switch"/>
        </panel>
        <panel sidebar="true" title="Suivi" canCollapse="true" collapseIf="true">
            <field name="createdOn"/>
            <field name="createdBy"/>
            <field name="updatedOn"/>
            <field name="updatedBy"/>
        </panel>
        <panel-mail>
            <mail-messages limit="4" />
            <mail-followers />
        </panel-mail>
    </form>

    <grid name="calibration-grid" title="Calibrations" model="com.axelor.apps.qvm.db.QvmOperation" edit-icon="true">
        <hilite background="success" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 0"/>
        <hilite background="primary" if="$moment(operationDueDate).diff(todayDate,'days') == 0"/>
        <hilite background="danger" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 10 &amp;&amp; $moment(operationDueDate).diff(todayDate,'days') &gt; 0"/>
        <hilite background="warning" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 30 &amp;&amp; $moment(operationDueDate).diff(todayDate,'days') &gt; 10"/>
        <hilite background="info" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 40 &amp;&amp; $moment(operationDueDate).diff(todayDate,'days') &gt; 30"/>

        <field name="serialNumber" title="Serial Number"/>
        <field name="statusSelect" title="Status">
            <hilite color="primary" if="statusSelect == 2"/>
            <hilite color="success" if="statusSelect == 3"/>
            <hilite color="warning" if="statusSelect == 4"/>
            <hilite color="danger" if="statusSelect == 5"/>
        </field>
        <field name="operationType" title="Calibration Type"/>
        <field name="typeSelect" title="Type"/>
        <field name="purchaseRequest" title="Purchase Request"/>
        <field name="machineName" title="Name"/>
        <field name="machineId" title="Id"/>
        <field name="machineBrand" title="Brand"/>
        <field name="machineModel" title="Model"/>
        <field name="machineSerialNumber" title="Serial Number"/>
        <field name="machineLocation" title="Location"/>
        <field name="machineLocationParent" title="Location Parent"/>
        <field name="fullRange" title="Full Range"/>
        <field name="operationRange" title="Calibration Range"/>
        <field name="leastCount" title="Least Count"/>
        <field name="operationFrequency" title="Calibration Frequency"/>
        <field name="pastOperationDate" title="Past Calibration Date"/>
        <field name="operationDate" title="Calibration Date"/>
        <field name="operationDueDate" title="Calibration Due Date"/>
        <field name="countdown" title="Countdown"/>
        <field name="reportCertifiacteNumber" title="Report / Certifiacte Number"/>
        <field name="externalInternal" title="Internal"/>
    </grid>

    <!-- Qualification -->
    <form name="qualification-form" title="Qualifications" onNew="action-record-operation-default-record" model="com.axelor.apps.qvm.db.QvmOperation">
        <toolbar>
            <button name="printBtn" title="Print" readonlyIf="!id" icon="fa-print" onClick="action-production-request-method-print"/>
        </toolbar>
        <panel name="statusSelectPanel" colSpan="12">
            <field name="statusSelect" title="Status" selection="operation.status.select" showTitle="false" readonly="true" colSpan="12" widget="nav-select"/>
            <field name="serialNumber" title="Serial Number" colSpan="12" readonly="true"/>
            <field name="operationType" domain="self.typeSelect = 2" title="Operation Type" grid-view="operation-type-grid" form-view="operation-type-form" onChange="action-record-operation-default-type-record"/>
            <field name="purchaseRequest" title="Purchase Request" grid-view="purchase-request-grid" form-view="purchase-request-form" domain="self.familleProduit = 149 and self.statusSelect != 7 and self.statusSelect != 8"/>
        </panel>
        <panel name="detailPanel" sidebar="true">
            <button name="draftBtn" title="Draft" showIf="statusSelect == 5" css="btn-info" icon="fa-edit" onClick="save,action-operation-request-set-status-draft, save"/>
            <button name="requestBtn" title="Request" showIf="statusSelect == 1" icon="fa-bullhorn" onClick="action-operation-set-seq-group,action-operation-request-set-status-request,save"/>
            <button name="acceptBtn" title="Accept" showIf="statusSelect == 2" icon="fa-check" css="btn-success" onClick="save,action-operation-request-set-status-accept,save"/>
            <button name="refuseBtn" title="Refuse" showIf="statusSelect == 2 " css="btn-warning" icon="fa-times" onClick="save,action-operation-request-set-status-refuse,save"/>
            <button name="cancelBtn" title="Cancel" showIf="statusSelect == 1 || statusSelect == 2 || statusSelect == 3 || statusSelect == 4" css="btn-danger" icon="fa-times-circle" onClick="save,action-operation-request-set-status-cancel,save"/>
        </panel>
        <panel name="machine" >
            <field name="machineName" title="Name" grid-view="machine-grid-qvm" form-view="machine-form-qvm" onChange="action-record-machine-operation-default" domain="self.typeSelect != 0"  colSpan="6"/>
            <spacer colSpan="6" />
            <field name="machineId" title="Id" colSpan="4"/>
            <field name="machineBrand" title="Brand" colSpan="4"/>
            <field name="machineModel" title="Model" colSpan="4"/>
            <field name="machineSerialNumber" title="Serial Number" colSpan="4"/>
            <field name="machineLocation" title="Location" colSpan="4"/>
            <field name="machineLocationParent" title="Location Parent" colSpan="4"/>
        </panel>
        <panel>
            <field name="fullRange" title="Full Range"/>
            <field name="operationRange" title="Qualification Range"/>
            <field name="leastCount" title="Least Count"/>
            <field name="operationFrequency" title="Qualification Frequency"/>
            <field name="pastOperationDate" title="Past Qualification Date"/>
            <field name="operationDate" title="Qualification Date"/>
            <field name="operationDueDate" title="Qualification Due Date"/>
            <field name="countdown" title="Countdown"/>
            <field name="reportCertifiacteNumber" title="Report / Certifiacte Number"/>
            <field name="externalInternal" title="Internal" onChange = "internal-external-validation-title-changer" widget="boolean-switch"/>
        </panel>
        <panel sidebar="true" title="Suivi" canCollapse="true" collapseIf="true">
            <field name="createdOn"/>
            <field name="createdBy"/>
            <field name="updatedOn"/>
            <field name="updatedBy"/>
        </panel>
        <panel-mail>
            <mail-messages limit="4" />
            <mail-followers />
        </panel-mail>
    </form>

    <grid name="qualification-grid" title="Qualifications" model="com.axelor.apps.qvm.db.QvmOperation" edit-icon="true">
        <hilite background="success" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 0"/>
        <hilite background="primary" if="$moment(operationDueDate).diff(todayDate,'days') == 0"/>
        <hilite background="danger" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 10 &amp;&amp; $moment(operationDueDate).diff(todayDate,'days') &gt; 0"/>
        <hilite background="warning" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 30 &amp;&amp; $moment(operationDueDate).diff(todayDate,'days') &gt; 10"/>
        <hilite background="info" if="$moment(operationDueDate).diff(todayDate,'days') &lt; 40 &amp;&amp; $moment(operationDueDate).diff(todayDate,'days') &gt; 30"/>

        <field name="serialNumber" title="Serial Number"/>
        <field name="statusSelect" title="Status">
            <hilite color="primary" if="statusSelect == 2"/>
            <hilite color="success" if="statusSelect == 3"/>
            <hilite color="warning" if="statusSelect == 4"/>
            <hilite color="danger" if="statusSelect == 5"/>
        </field>
        <field name="operationType" title="Qualification Type"/>
        <field name="typeSelect" title="Type"/>
        <field name="purchaseRequest" title="Purchase Request"/>
        <field name="machineName" title="Name"/>
        <field name="machineId" title="Id"/>
        <field name="machineBrand" title="Brand"/>
        <field name="machineModel" title="Model"/>
        <field name="machineSerialNumber" title="Serial Number"/>
        <field name="machineLocation" title="Location"/>
        <field name="machineLocationParent" title="Location Parent"/>
        <field name="fullRange" title="Full Range"/>
        <field name="operationRange" title="Qualification Range"/>
        <field name="leastCount" title="Least Count"/>
        <field name="operationFrequency" title="Qualification Frequency"/>
        <field name="pastOperationDate" title="Past Qualification Date"/>
        <field name="operationDate" title="Qualification Date"/>
        <field name="operationDueDate" title="Qualification Due Date"/>
        <field name="countdown" title="Countdown"/>
        <field name="reportCertifiacteNumber" title="Report / Certifiacte Number"/>
        <field name="externalInternal" title="Internal"/>
    </grid>

    <!-- Actions -->
    <action-record name="action-record-machine-operation-default" model="com.axelor.apps.qvm.db.QvmOperation">
        <field name="machineId"  expr="eval:machineName.machineId" if="machineName != null"/>
        <field name="machineBrand"  expr="eval:machineName.brand" if="machineName != null"/>
        <field name="machineModel"  expr="eval:machineName.model" if="machineName != null"/>
        <field name="machineSerialNumber"  expr="eval:machineName.serialNumber" if="machineName != null"/>
        <field name="machineLocation"  expr="eval:machineName.machineLocation" if="machineName != null"/>
        <field name="machineLocationParent" expr="eval:machineName.machineLocation.parent"  if="machineName != null"/>
        <field name="stockUnity" expr="eval:machineName.machineLocation.parent.stockUnity"  if="machineName != null"/>
    </action-record>

    <action-record name="action-record-operation-default-record" model="com.axelor.apps.qvm.db.QvmOperation">
        <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-record name="action-operation-request-set-status-accept" model="com.axelor.apps.qvm.db.QvmOperation">
        <field name="statusSelect" expr="eval:3"/>
    </action-record>
    <action-record name="action-operation-request-set-status-cancel" model="com.axelor.apps.qvm.db.QvmOperation">
        <field name="statusSelect" expr="eval:5"/>
    </action-record>
    <action-record name="action-operation-request-set-status-draft" model="com.axelor.apps.qvm.db.QvmOperation">
        <field name="statusSelect" expr="eval:1"/>
    </action-record>
    <action-record name="action-operation-request-set-status-refuse" model="com.axelor.apps.qvm.db.QvmOperation">
        <field name="statusSelect" expr="eval:4"/>
    </action-record>
    <action-record name="action-operation-request-set-status-request" model="com.axelor.apps.qvm.db.QvmOperation">
        <field name="statusSelect" expr="eval:2"/>
    </action-record>

    <action-attrs name="internal-external-operation-title-changer">
        <attribute if="externalInternal == false" name="title" expr="External :" for="externalInternal"/>
        <attribute if="externalInternal == true" name="title" expr="Internal :" for="externalInternal"/>
    </action-attrs>

    <action-view name="operation.action.view" model="com.axelor.apps.qvm.db.QvmOperation" title="Operations">
        <view name="operation-grid" type="grid"/>
        <view name="operation-kanban-view" type="kanban"/>
        <view name="operation-form" type="form"/>
    </action-view>

    <action-view name="operation.operation.action.view" model="com.axelor.apps.qvm.db.QvmOperation" title="Calibrations">
        <view name="operation-grid" type="grid"/>
        <view name="operation-kanban-view" type="kanban"/>
        <view name="operation-form" type="form"/>
        <domain>self.typeSelect =  :_ts</domain>
        <context name="_ts" expr="eval: 1"/>
    </action-view>

    <action-view name="qualification.operation.action.view" model="com.axelor.apps.qvm.db.QvmOperation" title="Qualifications">
        <view name="operation-grid" type="grid"/>
        <view name="operation-kanban-view" type="kanban"/>
        <view name="operation-form" type="form"/>
        <domain>self.typeSelect =  :_ts</domain>
        <context name="_ts" expr="eval: 2"/>
    </action-view>

    <action-view name="operation.action.view.related" model="com.axelor.apps.qvm.db.QvmOperation" title="Operations">
        <view name="operation-grid" type="grid"/>
        <view name="operation-form" type="form"/>
        <domain>self.operationType =  :_id</domain>
        <context name="_id" expr="eval: id"/>
    </action-view>

    <action-group name="action-operation-set-seq-group">
        <action name="action-calibration-set-seq"/>
        <action name="action-qualification-set-seq"/>
        <action name="action-operation-set-seq"/>
    </action-group>

    <action-method name="action-calibration-set-seq">
        <!--<call method="setSequence" class="com.axelor.apps.qvm.web.CalibrationController"/>-->
        <call if="typeSelect == 1" method="setSequenceCalibration" class="com.axelor.qvm.web.OperationController"/>
    </action-method>

    <action-method name="action-qualification-set-seq">
        <call if="typeSelect == 2" method="setSequenceQualification" class="com.axelor.qvm.web.OperationController"/>
    </action-method>

    <action-method name="action-operation-set-seq">
        <call if="typeSelect == 3" method="setSequenceOperation" class="com.axelor.qvm.web.OperationController"/>
    </action-method>

</object-views>
