ores.refdata.business_unit

Table of Contents

Represents internal organizational units (e.g., desks, departments, branches). Supports hierarchical structure via self-referencing parent_business_unit_id. Each unit belongs to a top-level legal entity (party).

1. Flags

2. Columns

2.1. id

UUID uniquely identifying this business unit.

Surrogate key for the business unit record.

2.2. party_id

Top-level legal entity this unit belongs to.

References the parent party record.

uuid_gen()

2.3. unit_name

Human-readable name for the business unit.

e.g., 'FX Options Desk', 'London Branch'.

faker::company::companyName() + " Desk"

2.4. parent_business_unit_id

Self-referencing parent unit for hierarchy.

NULL indicates a top-level unit.

std::nullopt

2.5. unit_code

Optional internal code or alias.

Short identifier for the business unit.

std::string("DESK") + std::to_string(idx)

2.6. business_centre_code

Business centre for the unit.

References the business centres scheme. May be null for global units.

// WRLD is the only business centre guaranteed seeded by the base
// bootstrap (a real FpML city code like GBLO only exists once the
// large, optional FpML business-centre reference dataset is loaded --
// see the same reasoning in ores.refdata.party.org).
std::string("WRLD")

2.7. unit_type_id

Classification type for this business unit.

Optional FK to business_unit_type. When set, the level of this unit's type must be strictly greater than its parent's type level (if the parent also has a type set).

std::nullopt

2.8. status

Current lifecycle status (Active, Inactive, Closed).

std::string("Active")

3. Artefact columns

The import carries unit_type_code, a natural key; ores_refdata_publish_business_units_from_dq_fn resolves it to unit_type_id by joining business_unit_types on code. party_id and status are the publisher's to supply, not the dataset's.

3.1. id

3.2. version

3.3. unit_name

3.4. parent_business_unit_id

3.5. unit_code

3.6. business_centre_code

3.7. unit_type_code

4. SQL

4.1. Flags

5. Foreign keys

5.1. party_id

5.2. parent_business_unit_id

6. Insert trigger

6.1. Validations

column validation_function
business_centre_code ores_refdata_validate_business_centre_fn
unit_type_id ores_refdata_validate_business_unit_type_fn
-- Level constraint: when both parent and child have a type, child level > parent level
if NEW.unit_type_id is not null and NEW.parent_business_unit_id is not null then
    declare
        v_parent_type_id uuid;
        v_parent_level integer;
        v_child_level integer;
    begin
        select unit_type_id into v_parent_type_id
        from ores_refdata_business_units_tbl
        where tenant_id = NEW.tenant_id
          and id = NEW.parent_business_unit_id
          and valid_to = ores_utility_infinity_timestamp_fn();

        if v_parent_type_id is not null then
            select level into v_parent_level
            from ores_refdata_business_unit_types_tbl
            where tenant_id = NEW.tenant_id
              and id = v_parent_type_id
              and valid_to = ores_utility_infinity_timestamp_fn();

            select level into v_child_level
            from ores_refdata_business_unit_types_tbl
            where tenant_id = NEW.tenant_id
              and id = NEW.unit_type_id
              and valid_to = ores_utility_infinity_timestamp_fn();

            if v_child_level <= v_parent_level then
                raise exception
                    'Business unit type level % cannot be contained by a unit of the same or higher level %. Parent level must be strictly less than child level.',
                    v_child_level, v_parent_level
                    using errcode = '23514';
            end if;
        end if;
    end;
end if;

7. C++

7.1. Flags

Note: the plan this flag traces to (task_apply_safe_drift.org) named unit_code as the find-by-code column, but unit_code is nullable and not part of the natural key – (party_id, unit_name) is. Using unit_name (with party_id) instead keeps the lookup unambiguous.

7.2. Repository

7.3. Domain includes

#include <chrono>
#include <optional>
#include <string>
#include <boost/uuid/uuid.hpp>

7.4. Entity includes

#include <string>
#include "sqlgen/Timestamp.hpp"
#include "sqlgen/PrimaryKey.hpp"

7.5. Conventions

7.6. Table display

column header
party_id Party
unit_name Unit Name
unit_code Code
business_centre_code Business Centre
status Status
modified_by Modified By
version Version

7.7. Presentation

7.7.1. Detail fields

field label widget type is_key is_required placeholder combo_domain_type combo_display_field combo_fetch_include combo_fetch_fn combo_watcher_name combo_code_field combo_tooltip_field combo_sort_field combo_label combo_setter_pascal combo_values
unit_code Unit Code codeEdit line_edit true false Enter unit code                      
unit_name Unit Name nameEdit line_edit   true Enter unit name                      
business_centre_code Business Centre businessCentreEdit line_edit     Enter business centre code                      
status Status statusCombo static_combo                           Active,Inactive,Closed
unit_type_id Unit Type unitTypeCombo dynamic_combo       refdata::domain::business_unit_type name   fetch_business_unit_types unitTypeWatcher id description level business unit types UnitTypeCombo  

7.7.2. Columns

enum_name field header type width
UnitCode unit_code Code string 120
UnitName unit_name Name string 250
BusinessCentreCode business_centre_code Business Centre string 130
Status status Status string 100
Version version Version int 80
ModifiedBy modified_by Modified By string 120
RecordedAt recorded_at Recorded At timestamp 150

7.7.3. Icon columns

column accessor field1 field2
BusinessCentreCode business_centre_flag_icon business_centre_code  

7.8. Custom repository methods

8. See also

Emacs 29.3 (Org mode 9.6.15)