<?xml version="1.0" encoding="UTF-8"?>
<domain-models xmlns="http://axelor.com/xml/ns/domain-models"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://axelor.com/xml/ns/domain-models http://axelor.com/xml/ns/domain-models/domain-models_5.2.xsd">

  <module name="account" package="com.axelor.apps.account.db" />

  <entity name="AnalyticAccount" lang="java">

    <string name="code" title="Code" required="true" />
    <string name="name" title="Name"
      required="true" />
    <many-to-one name="analyticAxis"
      ref="com.axelor.apps.account.db.AnalyticAxis" title="Analytic axis" />
    <many-to-one
      name="parent" ref="com.axelor.apps.account.db.AnalyticAccount" title="Parent Analytic Acc." />

  	<string
      name="fullCode">
	  	<![CDATA[
	  		String fullName = "";
	  		if(code != null ){
	  			fullName += code;
	  		}
	  		if(parent != null)  {
	  			fullName =  parent.getCode()  + "/" + fullName;
          if(parent.getParent() != null)  {
            fullName = parent.getParent().getCode() + "/" + fullName;
            if(parent.getParent().getParent() != null)  {
              fullName = parent.getParent().getParent().getCode()  + "/" + fullName;
              if(parent.getParent().getParent().getParent() != null)  {
                fullName =  parent.getParent().getParent().getParent().getCode()  + "/" + fullName;
              }
            }
          }
        }
	  		return fullName;
	  	]]>
  	</string>

    <string
      name="fullName" namecolumn="true">
	  	<![CDATA[
	  		String fullName = "";
	  		if(name != null ){
	  			fullName += name;
	  		}
	  		if(parent != null)  {
	  			fullName =  parent.getName()  + "/" + fullName;
          if(parent.getParent() != null)  {
            fullName = parent.getParent().getName() + "/" + fullName;
            if(parent.getParent().getParent() != null)  {
              fullName = parent.getParent().getParent().getName()  + "/" + fullName;
              if(parent.getParent().getParent().getParent() != null)  {
                fullName =  parent.getParent().getParent().getParent().getName()  + "/" + fullName;
              }
            }
          }
        }
	  		return fullName;
	  	]]>
  	</string>

    <unique-constraint columns="code,name,analyticAxis,parent" />
  </entity>

</domain-models>