<?xml version="1.0" encoding="utf-8"?>
<json-models xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  
  <json-model name="ProductCategory" title="Catégorie de produit" appBuilder="PRD">
  	<fields>
		<field name="name" title="Nom" required="true" type="string" sequence="1" visibleInGrid="true"/>
		<field name="code" title="Code" type="string" sequence="2" visibleInGrid="true"/>
  	</fields>
  </json-model> 
  
  <json-model name="Product" title="Produit" appBuilder="PRD">
  	<fields>
		<field name="name" title="Nom" required="true" type="string" sequence="1" visibleInGrid="true"/>
		<field name="code" title="Code" type="string" sequence="2" visibleInGrid="true"/>
		<field name="price" title="Prix" type="decimal" sequence="3" visibleInGrid="true"/>
		<field name="launchDate" title="Date de lancement" type="date" sequence="4"/>
		<field name="supplier" title="Fournisseur" type="many-to-one" target-model="com.axelor.apps.base.db.Partner" sequence="5"/>
		<field name="category" title="Catégorie principale" type="json-many-to-one" target-json-model="ProductCategory" sequence="6" visibleInGrid="true"/>
  	</fields>
  </json-model>
  
  <json-model name="ProductOrderLine" title="Ligne de commande produit" appBuilder="PRD">
  	<fields>
  		<field name="product" title="Produit" type="json-many-to-one" target-json-model="Product"  sequence="1" onChange="action-product-order-line-get-product-details,action-product-order-line-update-total" visibleInGrid="true"/>
  		<field name="price" title="Prix" type="decimal" sequence="2" onChange="action-product-order-line-update-total" visibleInGrid="true"/>
  		<field name="qty" title="Qté" type="integer" sequence="3" onChange="action-product-order-line-update-total" visibleInGrid="true"/>
		<field name="total" title="Total" type="decimal" sequence="4" visibleInGrid="true"/>
  	</fields>
  </json-model> 
  
  <json-model name="ProductOrder" title="Commande produit" appBuilder="PRD">
  	<fields>
		<field name="reference" title="Réf" type="string" sequence="1" visibleInGrid="true"/>
		<field name="customer" title="Client" type="many-to-one" target-model="com.axelor.apps.base.db.Partner" domain="isCustomer = true" sequence="2" visibleInGrid="true"/>
		<field name="orderDate" title="Date de commande" type="date" sequence="3" visibleInGrid="true"/>
		<field name="total" title="Total" type="decimal" sequence="4" visibleInGrid="true"/>
		<field name="lines" title="Lignes" type="json-one-to-many" target-json-model="ProductOrderLine" sequence="5" onChange="action-product-order-update-total"/>
		<field name="status" title="Statut" type="integer" sequence="6" visibleInGrid="true"/>
  	</fields>
  </json-model>
  
  <json-field name="createInvoice" type="button"
    model="com.axelor.apps.hr.db.Timesheet" modelField="attrs"
    onClick="action-create-invoice-from-timesheet" sequence="1"
    appBuilder="PRD" showIf="$record.user.employee"
    title="Créer facture"/>

  <json-field name="createPlanning" type="button"
    model="com.axelor.apps.project.db.Project" modelField="attrs"
    onClick="action-create-project-planning" sequence="1" appBuilder="PRD"
    title="Créer planning"/>
  
  <json-field name="invertToInvoice" title="Cocher/Décocher 'A facturer'" type="button" model="com.axelor.apps.hr.db.Timesheet" modelField="attrs" onClick="action-timesheet-line-invert-to-invoice" sequence="2" appBuilder="PRD"/>
  
  <json-field name="products"  title="Produit" type="json-many-to-many" target-json-model="Product" model="com.axelor.meta.db.MetaJsonRecord" modelField="attrs" jsonModel="ProductCategory" sequence="3" appBuilder="PRD"/>
  
  <json-field name="createProduct" title="Créer commande produit" type="button" onClick="action-create-product-order-from-category" model="com.axelor.meta.db.MetaJsonRecord" modelField="attrs" jsonModel="ProductCategory" sequence="4" appBuilder="PRD"/>
  
</json-models>
