<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: niujiaqing1265 $
    $Date: 2010/12/09 05:48:38 $
    $Revision: 1.3 $
    $Purpose: 部门分配 bm
-->
<bm:model xmlns:e="leaf.service.exception" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="gr" baseTable="exp_unit_group_relations">
    <bm:fields>
        <bm:field name="unit_group_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="unit_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="org_unit_description" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false" prompt="EXP_ORG_UNIT.ORG_UNIT_DESCRIPTION"/>
        <bm:field name="company_code" databaseType="VARCHAR" datatype="java.lang.String" expression="(select cpy.company_code from fnd_companies cpy where cpy.company_id=unit.company_id)" forInsert="false" forUpdate="false" prompt="COMPANY_CODE"/>
        <bm:field name="company_short_name" databaseType="VARCHAR" datatype="java.lang.String" expression="(select cpy.company_short_name  from fnd_companies cpy where cpy.company_id=unit.company_id )" forInsert="false" forUpdate="false" prompt="COMPANY_SHORT_NAME"/>
    </bm:fields>
    <bm:primary-key>
        <bm:pk-field name="unit_group_id"/>
        <bm:pk-field name="unit_id"/>
    </bm:primary-key>
    <bm:relations>
        <bm:relation name="unit" joinType="INNER" refModel="exp.exp_org_unit">
            <bm:reference foreignField="unit_id" localField="unit_id"/>
        </bm:relation>
    </bm:relations>
    <bm:query-fields>
        <bm:query-field field="unit_group_id" queryOperator="="/>
        <bm:query-field name="company_code" queryExpression="exists(select 1 from fnd_companies cpy where cpy.company_code like ${@company_code})"/>
        <bm:query-field name="company_short_name" queryExpression="exists(select 1 from fnd_companies cpy where cpy.company_short_name like ${@company_short_name})"/>
        <!-- <bm:query-field field="company_short_name" queryExpression="exists (select 1 from fnd_descriptions fd,fnd_comanies cpy where cpy.company_short_name_id = fd.description_id and fd.description_text like ${@company_short_name} and fd.language = ${/session/@lang})"/> -->
    </bm:query-fields>
    <bm:features>
        <f:standard-who/>
        <f:multi-language-display/>
    </bm:features>
    <bm:ref-fields>
        <bm:ref-field name="unit_code" prompt="EXP_ORG_UNIT.UNIT_CODE" relationName="unit" sourceField="unit_code"/>
        <bm:ref-field name="description_id" multiLanguage="true" multiLanguageDescField="org_unit_description" relationName="unit" sourceField="description_id"/>
    </bm:ref-fields>
    <e:exception-descriptor-config>
        <e:exception-descriptor exception="java.sql.SQLException" handleClass="leaf.database.SQLExceptionDescriptor">
            <e:error-message code="1" message="EXP_UNIT_UNIT_RELATIONS.DISTINCT"/>
        </e:exception-descriptor>
    </e:exception-descriptor-config>
</bm:model>
