cardinal

Apps that work together

Work with another app when it is installed, extend ERP's postings, and let Eden read your records and propose your RPCs.

An app can add behaviour for another app without requiring it. CRM works alone, and adds ERP features on sites that have ERP.

Check what is installed

crm/lib/services/erpnext.service.ex
def installed?(ctx), do: Cardinal.App.installed?(ctx, :erp)

Cardinal.App.installed(ctx) returns every installed app module, in hook order.

Hooks and fields for an absent app

A rec_events entry with when_installed runs only on sites that have that app:

crm/app.exs
rec_events: [{"Sales Order", Crm.Controllers.ErpEvents, when_installed: :erp}]

A fixture record with when_installed: erp is written only on those sites, also when ERP is installed later:

crm/fixtures/custom_field.yaml
- {parent_rectype: Customer, fieldname: crm_deal, fieldtype: Data, label: Frappe CRM Deal, read_only: true, insert_after: prospect_name, when_installed: erp}

The named app is not a requirement. app install does not pull it in. Uninstalling it removes those fields, and installing it again writes them back.

Extension modules found by name

A host app can look for a module with a fixed name in every installed app. The guest app defines it without depending on the host, so it compiles alone.

ERP looks for <App>.ErpExtension and calls the callbacks each one exports, in app order. CRM names the customer on a Quotation made from a deal:

crm/lib/erp_extension.ex
defmodule Crm.ErpExtension do
  def quotation_party(ctx, "CRM Deal", deal),
    do: Crm.Controllers.CRMDeal.quotation_party(ctx, deal)

  def quotation_party(_ctx, _party_type, _party), do: nil
end

Other callbacks change GL lines before posting and let an app such as HRMS pay its own vouchers through Payment Entry. ERP's Erp.Extension module lists the callbacks.

Make records readable by Eden

Eden's assistant reads the AI catalog: the RecTypes and fields the user may read, and the Code Reports they may run.

YAMLEffect
description: on a RecType or fieldTells the model what the records are
ai: false on a RecTypeLeaves it out of the catalog
ai: false on a fieldLeaves the field out

Password fields and layout breaks are always left out. An installed app's RecTypes and reports show up on the next call, with no restart.

Let Eden propose your RPCs

Define <App>.EdenActions with actions/0. Eve may then offer a card that calls the RPC as the user when they click Confirm.

crm/lib/eden_actions.ex
defmodule Crm.EdenActions do
  def actions do
    [
      %{
        rpc: "crm.crm_lead.convert_to_deal",
        title: "Convert to deal",
        description: "Turn a lead into a deal. Returns the new deal's ID.",
        rectypes: ["CRM Lead"],
        record: "lead",
        result_rectype: "CRM Deal",
        input_schema: %{
          "type" => "object",
          "properties" => %{"lead" => %{"type" => "string"}}
        }
      }
    ]
  end
end
KeyMeaning
rpcOne of this app's @rpc paths. Another app's is ignored
title, descriptionWhat the model and the card show
input_schemaThe RPC's arguments as a JSON schema object
rectypesThe RecTypes it acts on
recordThe argument that names the record
rectype_argThe argument that names its RecType, when there are several
result_rectypeThe RecType the result names, for the card's link

The RPC's requires: and argument checks still apply. Eden is optional: without it nothing reads this module.

On this page